@imtbl/x-client 2.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/LICENSE.md +176 -0
  2. package/README.md +53 -0
  3. package/dist/browser/index.js +2 -0
  4. package/dist/node/index.cjs +2 -0
  5. package/dist/node/index.js +2 -0
  6. package/dist/types/IMXClient.d.ts +334 -0
  7. package/dist/types/config/config.test.d.ts +1 -0
  8. package/dist/types/config/index.d.ts +77 -0
  9. package/dist/types/contracts/@openzeppelin/contracts/index.d.ts +4 -0
  10. package/dist/types/contracts/@openzeppelin/contracts/token/ERC20/IERC20.d.ts +129 -0
  11. package/dist/types/contracts/@openzeppelin/contracts/token/ERC20/index.d.ts +1 -0
  12. package/dist/types/contracts/@openzeppelin/contracts/token/ERC721/IERC721.d.ts +199 -0
  13. package/dist/types/contracts/@openzeppelin/contracts/token/ERC721/index.d.ts +1 -0
  14. package/dist/types/contracts/@openzeppelin/contracts/token/index.d.ts +4 -0
  15. package/dist/types/contracts/@openzeppelin/contracts/utils/index.d.ts +2 -0
  16. package/dist/types/contracts/@openzeppelin/contracts/utils/introspection/IERC165.d.ts +29 -0
  17. package/dist/types/contracts/@openzeppelin/contracts/utils/introspection/index.d.ts +1 -0
  18. package/dist/types/contracts/@openzeppelin/index.d.ts +2 -0
  19. package/dist/types/contracts/common.d.ts +50 -0
  20. package/dist/types/contracts/contracts/index.d.ts +4 -0
  21. package/dist/types/contracts/contracts/v3/Core.d.ts +1088 -0
  22. package/dist/types/contracts/contracts/v3/Registration.d.ts +169 -0
  23. package/dist/types/contracts/contracts/v3/index.d.ts +2 -0
  24. package/dist/types/contracts/contracts/v4/CoreV4.d.ts +1650 -0
  25. package/dist/types/contracts/contracts/v4/RegistrationV4.d.ts +111 -0
  26. package/dist/types/contracts/contracts/v4/index.d.ts +2 -0
  27. package/dist/types/contracts/factories/@openzeppelin/contracts/index.d.ts +2 -0
  28. package/dist/types/contracts/factories/@openzeppelin/contracts/token/ERC20/IERC20__factory.d.ts +147 -0
  29. package/dist/types/contracts/factories/@openzeppelin/contracts/token/ERC20/index.d.ts +1 -0
  30. package/dist/types/contracts/factories/@openzeppelin/contracts/token/ERC721/IERC721__factory.d.ts +227 -0
  31. package/dist/types/contracts/factories/@openzeppelin/contracts/token/ERC721/index.d.ts +1 -0
  32. package/dist/types/contracts/factories/@openzeppelin/contracts/token/index.d.ts +2 -0
  33. package/dist/types/contracts/factories/@openzeppelin/contracts/utils/index.d.ts +1 -0
  34. package/dist/types/contracts/factories/@openzeppelin/contracts/utils/introspection/IERC165__factory.d.ts +21 -0
  35. package/dist/types/contracts/factories/@openzeppelin/contracts/utils/introspection/index.d.ts +1 -0
  36. package/dist/types/contracts/factories/@openzeppelin/index.d.ts +1 -0
  37. package/dist/types/contracts/factories/contracts/index.d.ts +2 -0
  38. package/dist/types/contracts/factories/contracts/v3/Core__factory.d.ts +1254 -0
  39. package/dist/types/contracts/factories/contracts/v3/Registration__factory.d.ts +214 -0
  40. package/dist/types/contracts/factories/contracts/v3/index.d.ts +2 -0
  41. package/dist/types/contracts/factories/contracts/v4/CoreV4__factory.d.ts +1890 -0
  42. package/dist/types/contracts/factories/contracts/v4/RegistrationV4__factory.d.ts +168 -0
  43. package/dist/types/contracts/factories/contracts/v4/index.d.ts +2 -0
  44. package/dist/types/contracts/factories/index.d.ts +2 -0
  45. package/dist/types/contracts/index.d.ts +19 -0
  46. package/dist/types/exportContracts.d.ts +2 -0
  47. package/dist/types/exportUtils.d.ts +1 -0
  48. package/dist/types/imx.test.d.ts +1 -0
  49. package/dist/types/index.d.ts +11 -0
  50. package/dist/types/types/api.d.ts +223 -0
  51. package/dist/types/types/errors.d.ts +9 -0
  52. package/dist/types/types/index.d.ts +6 -0
  53. package/dist/types/types/requests.d.ts +53 -0
  54. package/dist/types/types/signers.d.ts +37 -0
  55. package/dist/types/types/tokens.d.ts +51 -0
  56. package/dist/types/types/transfers.d.ts +17 -0
  57. package/dist/types/utils/convertToSignableToken.d.ts +8 -0
  58. package/dist/types/utils/crypto/crypto.d.ts +16 -0
  59. package/dist/types/utils/crypto/crypto.test.d.ts +1 -0
  60. package/dist/types/utils/crypto/index.d.ts +1 -0
  61. package/dist/types/utils/formatError.d.ts +7 -0
  62. package/dist/types/utils/formatError.test.d.ts +1 -0
  63. package/dist/types/utils/index.d.ts +5 -0
  64. package/dist/types/utils/stark/errors.d.ts +3 -0
  65. package/dist/types/utils/stark/getStarkPublicKeyFromImx.d.ts +12 -0
  66. package/dist/types/utils/stark/legacy/crypto/constants.d.ts +27 -0
  67. package/dist/types/utils/stark/legacy/crypto/crypto.d.ts +14 -0
  68. package/dist/types/utils/stark/legacy/crypto/index.d.ts +2 -0
  69. package/dist/types/utils/stark/legacy/crypto/points.d.ts +1 -0
  70. package/dist/types/utils/stark/legacy/crypto/types.d.ts +18 -0
  71. package/dist/types/utils/stark/starkCurve.d.ts +18 -0
  72. package/dist/types/utils/stark/starkCurve.test.d.ts +1 -0
  73. package/dist/types/utils/stark/starkSigner.d.ts +17 -0
  74. package/dist/types/utils/stark/starkSigner.test.d.ts +1 -0
  75. package/dist/types/workflows/errors.d.ts +3 -0
  76. package/dist/types/workflows/exchangeTransfers.d.ts +8 -0
  77. package/dist/types/workflows/index.d.ts +1 -0
  78. package/dist/types/workflows/minting.d.ts +4 -0
  79. package/dist/types/workflows/orders.d.ts +13 -0
  80. package/dist/types/workflows/trades.d.ts +8 -0
  81. package/dist/types/workflows/workflows.d.ts +29 -0
  82. package/package.json +70 -0
@@ -0,0 +1,7 @@
1
+ import { IMXError } from '../types/errors';
2
+ /**
3
+ * [Formats an error in the IMXError shape](https://axios-http.com/docs/handling_errors)
4
+ * @param error - The Error object thrown by the request
5
+ * @returns {@link IMXError} - The formatted error
6
+ */
7
+ export declare function formatError(error: unknown): IMXError;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ export * from './convertToSignableToken';
2
+ export * from './formatError';
3
+ export * from './crypto';
4
+ export * from './stark/starkCurve';
5
+ export * from './stark/starkSigner';
@@ -0,0 +1,3 @@
1
+ export declare enum Errors {
2
+ StarkCurveInvalidMessageLength = "invalid message length"
3
+ }
@@ -0,0 +1,12 @@
1
+ interface StarkUserResponse {
2
+ starkPublicKey: string;
3
+ accountNotFound: boolean;
4
+ }
5
+ /**
6
+ * @description Gets the account (stark public key) value of the requested user
7
+ * (ethAddress) for Production environment only.
8
+ * @param ethAddress {string}
9
+ * @returns {Promise<StarkUserResponse | undefined>}
10
+ */
11
+ export declare function getStarkPublicKeyFromImx(ethAddress: string): Promise<StarkUserResponse | undefined>;
12
+ export {};
@@ -0,0 +1,27 @@
1
+ import BN from 'bn.js';
2
+ import { Instruction, InstructionWithFee } from './types';
3
+ declare const DEFAULT_ACCOUNT_MAPPING_KEY = "STARKWARE_ACCOUNT_MAPPING";
4
+ declare const DEFAULT_SIGNATURE_MESSAGE = "Only sign this request if you\u2019ve initiated an action with Immutable X.";
5
+ declare const DEFAULT_ACCOUNT_LAYER = "starkex";
6
+ declare const DEFAULT_ACCOUNT_APPLICATION = "immutablex";
7
+ declare const DEFAULT_ACCOUNT_INDEX = "1";
8
+ declare const NFT_ASSET_ID_PREFIX = "NFT:";
9
+ declare const MINTABLE_ASSET_ID_PREFIX = "MINTABLE:";
10
+ declare const prime: BN;
11
+ declare const starkEc: any;
12
+ declare const constantPoints: any[];
13
+ declare const shiftPoint: any;
14
+ declare const instructionEncodingMap: {
15
+ [instruction in Instruction | InstructionWithFee]: BN;
16
+ };
17
+ declare const ZERO_BN: BN;
18
+ declare const ONE_BN: BN;
19
+ declare const TWO_POW_22_BN: BN;
20
+ declare const TWO_POW_31_BN: BN;
21
+ declare const TWO_POW_63_BN: BN;
22
+ declare const PRIME_BN: BN;
23
+ declare const MAX_ECDSA_BN: BN;
24
+ declare const MISSING_HEX_PREFIX = "Hex strings expected to be prefixed with 0x.";
25
+ declare const ORDER: BN;
26
+ declare const SECP_ORDER: BN;
27
+ export { constantPoints, DEFAULT_ACCOUNT_APPLICATION, DEFAULT_ACCOUNT_INDEX, DEFAULT_ACCOUNT_LAYER, DEFAULT_ACCOUNT_MAPPING_KEY, DEFAULT_SIGNATURE_MESSAGE, instructionEncodingMap, MAX_ECDSA_BN, MINTABLE_ASSET_ID_PREFIX, MISSING_HEX_PREFIX, NFT_ASSET_ID_PREFIX, ONE_BN, ORDER, prime, PRIME_BN, SECP_ORDER, shiftPoint, starkEc, TWO_POW_22_BN, TWO_POW_31_BN, TWO_POW_63_BN, ZERO_BN, };
@@ -0,0 +1,14 @@
1
+ import BN from 'bn.js';
2
+ import elliptic from 'elliptic';
3
+ export declare function isHexPrefixed(str: string): boolean;
4
+ export declare function getIntFromBits(hex: string, start: number, end?: number | undefined): number;
5
+ export declare function getAccountPath(layer: string, application: string, ethereumAddress: string, index: string): string;
6
+ export declare function hashKeyWithIndex(key: string, index: number): BN;
7
+ export declare function grindKey(privateKey: string): string;
8
+ export declare function getKeyPair(privateKey: string): elliptic.ec.KeyPair;
9
+ export declare function getPrivateKeyFromPath(seed: string, path: string): string;
10
+ export declare function getPublic(keyPair: elliptic.ec.KeyPair, compressed?: boolean): string;
11
+ export declare function getStarkPublicKey(keyPair: elliptic.ec.KeyPair): string;
12
+ export declare function getKeyPairFromPublicKey(publicKey: string): elliptic.ec.KeyPair;
13
+ export declare function getKeyPairFromPrivateKey(privateKey: string): elliptic.ec.KeyPair;
14
+ export declare function getXCoordinate(publicKey: string): string;
@@ -0,0 +1,2 @@
1
+ export * from './constants';
2
+ export * from './crypto';
@@ -0,0 +1 @@
1
+ export declare const constantPointsHex: string[][];
@@ -0,0 +1,18 @@
1
+ export type Instruction = 'order' | 'transfer' | 'registerUser' | 'deposit' | 'withdraw' | 'cancelOrder';
2
+ export type InstructionWithFee = 'orderWithFee' | 'transferWithFee';
3
+ export type FeeParams = {
4
+ feeToken: string;
5
+ feeVault: string;
6
+ feeLimit: string;
7
+ };
8
+ export type LimitOrderParams = {
9
+ vaultSell: string;
10
+ vaultBuy: string;
11
+ amountSell: string;
12
+ amountBuy: string;
13
+ nonce: string;
14
+ expirationTimestamp: string;
15
+ tokenSell: string;
16
+ tokenBuy: string;
17
+ };
18
+ export type LimitOrderWithFeeParams = LimitOrderParams & FeeParams;
@@ -0,0 +1,18 @@
1
+ import BN from 'bn.js';
2
+ import { Signer } from 'ethers';
3
+ export declare const starkEcOrder: BN;
4
+ export declare const starkEc: any;
5
+ export declare function grindKeyV201(keySeed: BN): string;
6
+ export declare function grindKey(keySeed: BN): string;
7
+ export declare function checkIfHashedKeyIsAboveLimit(keySeed: BN): boolean;
8
+ export declare function getPrivateKeyFromPath(seed: string, path: string): BN;
9
+ /**
10
+ * Generates a new Stark private key
11
+ * @returns the private key as a hex string
12
+ */
13
+ export declare function generateStarkPrivateKey(): string;
14
+ /**
15
+ * Generates a deterministic Stark private key from the provided signer.
16
+ * @returns the private key as a hex string
17
+ */
18
+ export declare function generateLegacyStarkPrivateKey(signer: Signer): Promise<string>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { StarkSigner } from '../../types';
2
+ export declare class StandardStarkSigner implements StarkSigner {
3
+ private privateKey;
4
+ private keyPair;
5
+ constructor(privateKey: string);
6
+ getAddress(): string;
7
+ signMessage(msg: string): Promise<string>;
8
+ private serialize;
9
+ getYCoordinate(): Promise<string>;
10
+ private fixMsgHashLen;
11
+ }
12
+ /**
13
+ * Creates a new Stark Signer
14
+ * @params starkPrivateKey - the private key as a hex string
15
+ * @returns a StarkSigner
16
+ */
17
+ export declare function createStarkSigner(starkPrivateKey: string): StarkSigner;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare enum Errors {
2
+ StarkCurveInvalidMessageLength = "invalid message length"
3
+ }
@@ -0,0 +1,8 @@
1
+ import { CreateTransferResponseV1, ExchangesApi } from '../types/api';
2
+ import { UnsignedExchangeTransferRequest, WalletConnection } from '../types';
3
+ type TransfersWorkflowParams = WalletConnection & {
4
+ request: UnsignedExchangeTransferRequest;
5
+ exchangesApi: ExchangesApi;
6
+ };
7
+ export declare function exchangeTransfersWorkflow({ ethSigner, starkSigner, request, exchangesApi, }: TransfersWorkflowParams): Promise<CreateTransferResponseV1>;
8
+ export {};
@@ -0,0 +1 @@
1
+ export * from './workflows';
@@ -0,0 +1,4 @@
1
+ import { Signer } from 'ethers';
2
+ import { MintsApi, MintTokensResponse } from '../types/api';
3
+ import { UnsignedMintRequest } from '../types';
4
+ export declare function mintingWorkflow(signer: Signer, request: UnsignedMintRequest, mintsApi: MintsApi): Promise<MintTokensResponse>;
@@ -0,0 +1,13 @@
1
+ import { CancelOrderResponse, CreateOrderResponse, GetSignableCancelOrderRequest, OrdersApi } from '../types/api';
2
+ import { UnsignedOrderRequest, WalletConnection } from '../types';
3
+ type CreateOrderWorkflowParams = WalletConnection & {
4
+ request: UnsignedOrderRequest;
5
+ ordersApi: OrdersApi;
6
+ };
7
+ type CancelOrderWorkflowParams = WalletConnection & {
8
+ request: GetSignableCancelOrderRequest;
9
+ ordersApi: OrdersApi;
10
+ };
11
+ export declare function createOrderWorkflow({ ethSigner, starkSigner, request, ordersApi, }: CreateOrderWorkflowParams): Promise<CreateOrderResponse>;
12
+ export declare function cancelOrderWorkflow({ ethSigner, starkSigner, request, ordersApi, }: CancelOrderWorkflowParams): Promise<CancelOrderResponse>;
13
+ export {};
@@ -0,0 +1,8 @@
1
+ import { CreateTradeResponse, GetSignableTradeRequest, TradesApi } from '../types/api';
2
+ import { WalletConnection } from '../types';
3
+ type createTradeWorkflowParams = WalletConnection & {
4
+ request: GetSignableTradeRequest;
5
+ tradesApi: TradesApi;
6
+ };
7
+ export declare function createTradeWorkflow({ ethSigner, starkSigner, request, tradesApi, }: createTradeWorkflowParams): Promise<CreateTradeResponse>;
8
+ export {};
@@ -0,0 +1,29 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { Signer } from 'ethers';
3
+ import { CollectionsApi, ExchangesApi, ProjectsApi, MetadataApi, MetadataRefreshesApi, MintsApi, CreateCollectionRequest, UpdateCollectionRequest, AddMetadataSchemaToCollectionRequest, CreateMetadataRefreshRequest, MetadataSchemaRequest, Project, Collection, SuccessResponse, GetMetadataRefreshes, GetMetadataRefreshErrorsResponse, GetMetadataRefreshResponse, CreateMetadataRefreshResponse } from '../types/api';
4
+ import { UnsignedMintRequest, WalletConnection, EthSigner, UnsignedExchangeTransferRequest } from '../types';
5
+ import { ImmutableXConfiguration } from '../config';
6
+ export declare class Workflows {
7
+ protected config: ImmutableXConfiguration;
8
+ private readonly mintsApi;
9
+ private readonly projectsApi;
10
+ private readonly collectionsApi;
11
+ private readonly metadataApi;
12
+ private readonly metadataRefreshesApi;
13
+ private readonly exchangesApi;
14
+ private isChainValid;
15
+ constructor(config: ImmutableXConfiguration, collectionsApi: CollectionsApi, exchangesApi: ExchangesApi, metadataApi: MetadataApi, metadataRefreshesApi: MetadataRefreshesApi, mintsApi: MintsApi, projectsApi: ProjectsApi);
16
+ private validateChain;
17
+ private getStarkExContractVersion;
18
+ mint(signer: Signer, request: UnsignedMintRequest): Promise<import("..").MintTokensResponse>;
19
+ exchangeTransfer(walletConnection: WalletConnection, request: UnsignedExchangeTransferRequest): Promise<import("..").CreateTransferResponseV1>;
20
+ getProject(ethSigner: EthSigner, id: string): Promise<AxiosResponse<Project, any>>;
21
+ createCollection(ethSigner: EthSigner, createCollectionRequest: CreateCollectionRequest): Promise<AxiosResponse<Collection, any>>;
22
+ updateCollection(ethSigner: EthSigner, address: string, updateCollectionRequest: UpdateCollectionRequest): Promise<AxiosResponse<Collection, any>>;
23
+ addMetadataSchemaToCollection(ethSigner: EthSigner, address: string, addMetadataSchemaToCollectionRequest: AddMetadataSchemaToCollectionRequest): Promise<AxiosResponse<SuccessResponse, any>>;
24
+ updateMetadataSchemaByName(ethSigner: EthSigner, address: string, name: string, metadataSchemaRequest: MetadataSchemaRequest): Promise<AxiosResponse<SuccessResponse, any>>;
25
+ listMetadataRefreshes(ethSigner: EthSigner, collectionAddress?: string, pageSize?: number, cursor?: string): Promise<AxiosResponse<GetMetadataRefreshes, any>>;
26
+ getMetadataRefreshErrors(ethSigner: EthSigner, refreshId: string, pageSize?: number, cursor?: string): Promise<AxiosResponse<GetMetadataRefreshErrorsResponse, any>>;
27
+ getMetadataRefreshResults(ethSigner: EthSigner, refreshId: string): Promise<AxiosResponse<GetMetadataRefreshResponse, any>>;
28
+ createMetadataRefresh(ethSigner: EthSigner, request: CreateMetadataRefreshRequest): Promise<AxiosResponse<CreateMetadataRefreshResponse, any>>;
29
+ }
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@imtbl/x-client",
3
+ "description": "Immutable X Client for Immutable SDK",
4
+ "version": "2.0.0-alpha.0",
5
+ "author": "Immutable",
6
+ "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
7
+ "dependencies": {
8
+ "@ethereumjs/wallet": "^2.0.4",
9
+ "@imtbl/config": "2.0.0-alpha.0",
10
+ "@imtbl/generated-clients": "2.0.0-alpha.0",
11
+ "axios": "^1.6.5",
12
+ "bn.js": "^5.2.1",
13
+ "elliptic": "^6.5.7",
14
+ "enc-utils": "^3.0.0",
15
+ "ethers": "^6.13.4",
16
+ "hash.js": "^1.1.7"
17
+ },
18
+ "devDependencies": {
19
+ "@swc/core": "^1.3.36",
20
+ "@swc/jest": "^0.2.24",
21
+ "@types/bn.js": "^5.1.6",
22
+ "@types/jest": "^29.4.3",
23
+ "crypto": "^1.0.1",
24
+ "eslint": "^8.40.0",
25
+ "jest": "^29.4.3",
26
+ "jest-environment-jsdom": "^29.4.3",
27
+ "tsup": "^8.3.5",
28
+ "typescript": "^5.6.2"
29
+ },
30
+ "engines": {
31
+ "node": ">=20.11.0"
32
+ },
33
+ "exports": {
34
+ "development": {
35
+ "types": "./src/index.ts",
36
+ "browser": "./dist/browser/index.js",
37
+ "require": "./dist/node/index.cjs",
38
+ "default": "./dist/node/index.js"
39
+ },
40
+ "default": {
41
+ "types": "./dist/types/index.d.ts",
42
+ "browser": "./dist/browser/index.js",
43
+ "require": "./dist/node/index.cjs",
44
+ "default": "./dist/node/index.js"
45
+ }
46
+ },
47
+ "files": [
48
+ "dist"
49
+ ],
50
+ "homepage": "https://github.com/immutable/ts-immutable-sdk#readme",
51
+ "license": "Apache-2.0",
52
+ "main": "dist/node/index.cjs",
53
+ "module": "dist/node/index.js",
54
+ "browser": "dist/browser/index.js",
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "repository": "immutable/ts-immutable-sdk.git",
59
+ "type": "module",
60
+ "types": "./dist/types/index.d.ts",
61
+ "scripts": {
62
+ "build": "pnpm transpile && pnpm typegen",
63
+ "transpile": "tsup src/index.ts --config ../../tsup.config.js",
64
+ "typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types",
65
+ "lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0",
66
+ "test": "jest",
67
+ "test:watch": "jest --watch",
68
+ "typecheck": "tsc --customConditions default --noEmit --jsx preserve"
69
+ }
70
+ }