ccxt 4.3.70 → 4.3.72

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 (153) hide show
  1. package/README.md +6 -5
  2. package/dist/ccxt.browser.min.js +13 -10
  3. package/dist/cjs/ccxt.js +6 -1
  4. package/dist/cjs/src/abstract/paradex.js +9 -0
  5. package/dist/cjs/src/base/Exchange.js +49 -0
  6. package/dist/cjs/src/paradex.js +2075 -0
  7. package/dist/cjs/src/pro/bequant.js +4 -0
  8. package/dist/cjs/src/pro/paradex.js +365 -0
  9. package/dist/cjs/src/static_dependencies/noble-curves/abstract/poseidon.js +100 -0
  10. package/dist/cjs/src/static_dependencies/noble-curves/abstract/weierstrass.js +1 -0
  11. package/dist/cjs/src/static_dependencies/scure-starknet/index.js +284 -0
  12. package/dist/cjs/src/static_dependencies/starknet/constants.js +60 -0
  13. package/dist/cjs/src/static_dependencies/starknet/types/calldata.js +26 -0
  14. package/dist/cjs/src/static_dependencies/starknet/types/lib/contract/abi.js +8 -0
  15. package/dist/cjs/src/static_dependencies/starknet/types/lib/contract/index.js +13 -0
  16. package/dist/cjs/src/static_dependencies/starknet/types/lib/index.js +56 -0
  17. package/dist/cjs/src/static_dependencies/starknet/types/typedData.js +19 -0
  18. package/dist/cjs/src/static_dependencies/starknet/utils/assert.js +15 -0
  19. package/dist/cjs/src/static_dependencies/starknet/utils/cairoDataTypes/felt.js +44 -0
  20. package/dist/cjs/src/static_dependencies/starknet/utils/cairoDataTypes/uint256.js +122 -0
  21. package/dist/cjs/src/static_dependencies/starknet/utils/cairoDataTypes/uint512.js +137 -0
  22. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/byteArray.js +61 -0
  23. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/cairo.js +218 -0
  24. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/enum/CairoCustomEnum.js +57 -0
  25. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/enum/CairoOption.js +64 -0
  26. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/enum/CairoResult.js +63 -0
  27. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/formatter.js +66 -0
  28. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/index.js +281 -0
  29. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/parser/index.js +33 -0
  30. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/parser/parser-0-1.1.0.js +37 -0
  31. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/parser/parser-2.0.0.js +40 -0
  32. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/propertyOrder.js +156 -0
  33. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/requestParser.js +250 -0
  34. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/responseParser.js +215 -0
  35. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/tuple.js +112 -0
  36. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/validate.js +206 -0
  37. package/dist/cjs/src/static_dependencies/starknet/utils/encode.js +58 -0
  38. package/dist/cjs/src/static_dependencies/starknet/utils/hash/classHash.js +57 -0
  39. package/dist/cjs/src/static_dependencies/starknet/utils/merkle.js +76 -0
  40. package/dist/cjs/src/static_dependencies/starknet/utils/num.js +92 -0
  41. package/dist/cjs/src/static_dependencies/starknet/utils/selector.js +48 -0
  42. package/dist/cjs/src/static_dependencies/starknet/utils/shortString.js +101 -0
  43. package/dist/cjs/src/static_dependencies/starknet/utils/typedData.js +334 -0
  44. package/dist/cjs/src/woo.js +4 -2
  45. package/examples/js/cli.js +8 -4
  46. package/js/ccxt.d.ts +8 -2
  47. package/js/ccxt.js +6 -2
  48. package/js/src/abstract/paradex.d.ts +43 -0
  49. package/js/src/abstract/paradex.js +11 -0
  50. package/js/src/base/Exchange.d.ts +7 -0
  51. package/js/src/base/Exchange.js +45 -0
  52. package/js/src/base/types.d.ts +10 -10
  53. package/js/src/paradex.d.ts +76 -0
  54. package/js/src/paradex.js +2075 -0
  55. package/js/src/pro/bequant.js +4 -0
  56. package/js/src/pro/paradex.d.ts +15 -0
  57. package/js/src/pro/paradex.js +366 -0
  58. package/js/src/static_dependencies/noble-curves/abstract/weierstrass.d.ts +24 -0
  59. package/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +1 -1
  60. package/js/src/static_dependencies/scure-starknet/index.d.ts +79 -0
  61. package/js/src/static_dependencies/scure-starknet/index.js +323 -0
  62. package/js/src/static_dependencies/starknet/constants.d.ts +61 -0
  63. package/js/src/static_dependencies/starknet/constants.js +67 -0
  64. package/js/src/static_dependencies/starknet/index.d.ts +7 -0
  65. package/js/src/static_dependencies/starknet/index.js +50 -0
  66. package/js/src/static_dependencies/starknet/types/cairoEnum.d.ts +2 -0
  67. package/js/src/static_dependencies/starknet/types/cairoEnum.js +7 -0
  68. package/js/src/static_dependencies/starknet/types/calldata.d.ts +19 -0
  69. package/js/src/static_dependencies/starknet/types/calldata.js +28 -0
  70. package/js/src/static_dependencies/starknet/types/index.d.ts +13 -0
  71. package/js/src/static_dependencies/starknet/types/index.js +16 -0
  72. package/js/src/static_dependencies/starknet/types/lib/contract/abi.d.ts +71 -0
  73. package/js/src/static_dependencies/starknet/types/lib/contract/abi.js +13 -0
  74. package/js/src/static_dependencies/starknet/types/lib/contract/index.d.ts +24 -0
  75. package/js/src/static_dependencies/starknet/types/lib/contract/index.js +16 -0
  76. package/js/src/static_dependencies/starknet/types/lib/contract/legacy.d.ts +33 -0
  77. package/js/src/static_dependencies/starknet/types/lib/contract/legacy.js +7 -0
  78. package/js/src/static_dependencies/starknet/types/lib/contract/sierra.d.ts +52 -0
  79. package/js/src/static_dependencies/starknet/types/lib/contract/sierra.js +7 -0
  80. package/js/src/static_dependencies/starknet/types/lib/index.d.ts +248 -0
  81. package/js/src/static_dependencies/starknet/types/lib/index.js +52 -0
  82. package/js/src/static_dependencies/starknet/types/typedData.d.ts +44 -0
  83. package/js/src/static_dependencies/starknet/types/typedData.js +19 -0
  84. package/js/src/static_dependencies/starknet/utils/address.d.ts +53 -0
  85. package/js/src/static_dependencies/starknet/utils/address.js +89 -0
  86. package/js/src/static_dependencies/starknet/utils/assert.d.ts +7 -0
  87. package/js/src/static_dependencies/starknet/utils/assert.js +17 -0
  88. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/felt.d.ts +6 -0
  89. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/felt.js +43 -0
  90. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint256.d.ts +72 -0
  91. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint256.js +117 -0
  92. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint512.d.ts +76 -0
  93. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint512.js +136 -0
  94. package/js/src/static_dependencies/starknet/utils/calldata/byteArray.d.ts +32 -0
  95. package/js/src/static_dependencies/starknet/utils/calldata/byteArray.js +59 -0
  96. package/js/src/static_dependencies/starknet/utils/calldata/cairo.d.ts +183 -0
  97. package/js/src/static_dependencies/starknet/utils/calldata/cairo.js +229 -0
  98. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoCustomEnum.d.ts +38 -0
  99. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoCustomEnum.js +57 -0
  100. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoOption.d.ts +35 -0
  101. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoOption.js +64 -0
  102. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoResult.d.ts +34 -0
  103. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoResult.js +63 -0
  104. package/js/src/static_dependencies/starknet/utils/calldata/enum/index.d.ts +3 -0
  105. package/js/src/static_dependencies/starknet/utils/calldata/enum/index.js +9 -0
  106. package/js/src/static_dependencies/starknet/utils/calldata/formatter.d.ts +9 -0
  107. package/js/src/static_dependencies/starknet/utils/calldata/formatter.js +67 -0
  108. package/js/src/static_dependencies/starknet/utils/calldata/index.d.ts +89 -0
  109. package/js/src/static_dependencies/starknet/utils/calldata/index.js +280 -0
  110. package/js/src/static_dependencies/starknet/utils/calldata/parser/index.d.ts +5 -0
  111. package/js/src/static_dependencies/starknet/utils/calldata/parser/index.js +30 -0
  112. package/js/src/static_dependencies/starknet/utils/calldata/parser/interface.d.ts +20 -0
  113. package/js/src/static_dependencies/starknet/utils/calldata/parser/interface.js +8 -0
  114. package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-0-1.1.0.d.ts +24 -0
  115. package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-0-1.1.0.js +36 -0
  116. package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-2.0.0.d.ts +23 -0
  117. package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-2.0.0.js +40 -0
  118. package/js/src/static_dependencies/starknet/utils/calldata/propertyOrder.d.ts +2 -0
  119. package/js/src/static_dependencies/starknet/utils/calldata/propertyOrder.js +155 -0
  120. package/js/src/static_dependencies/starknet/utils/calldata/requestParser.d.ts +11 -0
  121. package/js/src/static_dependencies/starknet/utils/calldata/requestParser.js +248 -0
  122. package/js/src/static_dependencies/starknet/utils/calldata/responseParser.d.ts +11 -0
  123. package/js/src/static_dependencies/starknet/utils/calldata/responseParser.js +214 -0
  124. package/js/src/static_dependencies/starknet/utils/calldata/tuple.d.ts +6 -0
  125. package/js/src/static_dependencies/starknet/utils/calldata/tuple.js +113 -0
  126. package/js/src/static_dependencies/starknet/utils/calldata/validate.d.ts +6 -0
  127. package/js/src/static_dependencies/starknet/utils/calldata/validate.js +208 -0
  128. package/js/src/static_dependencies/starknet/utils/encode.d.ts +207 -0
  129. package/js/src/static_dependencies/starknet/utils/encode.js +282 -0
  130. package/js/src/static_dependencies/starknet/utils/hash/classHash.d.ts +57 -0
  131. package/js/src/static_dependencies/starknet/utils/hash/classHash.js +224 -0
  132. package/js/src/static_dependencies/starknet/utils/hash/index.d.ts +6 -0
  133. package/js/src/static_dependencies/starknet/utils/hash/index.js +13 -0
  134. package/js/src/static_dependencies/starknet/utils/json.d.ts +24 -0
  135. package/js/src/static_dependencies/starknet/utils/json.js +43 -0
  136. package/js/src/static_dependencies/starknet/utils/merkle.d.ts +35 -0
  137. package/js/src/static_dependencies/starknet/utils/merkle.js +84 -0
  138. package/js/src/static_dependencies/starknet/utils/num.d.ts +182 -0
  139. package/js/src/static_dependencies/starknet/utils/num.js +244 -0
  140. package/js/src/static_dependencies/starknet/utils/selector.d.ts +48 -0
  141. package/js/src/static_dependencies/starknet/utils/selector.js +85 -0
  142. package/js/src/static_dependencies/starknet/utils/shortString.d.ts +57 -0
  143. package/js/src/static_dependencies/starknet/utils/shortString.js +96 -0
  144. package/js/src/static_dependencies/starknet/utils/starknetId.d.ts +113 -0
  145. package/js/src/static_dependencies/starknet/utils/starknetId.js +265 -0
  146. package/js/src/static_dependencies/starknet/utils/typedData.d.ts +54 -0
  147. package/js/src/static_dependencies/starknet/utils/typedData.js +321 -0
  148. package/js/src/static_dependencies/starknet/utils/uint256.d.ts +21 -0
  149. package/js/src/static_dependencies/starknet/utils/uint256.js +32 -0
  150. package/js/src/static_dependencies/starknet/utils/url.d.ts +29 -0
  151. package/js/src/static_dependencies/starknet/utils/url.js +70 -0
  152. package/js/src/woo.js +4 -2
  153. package/package.json +1 -1
@@ -0,0 +1,17 @@
1
+ // ----------------------------------------------------------------------------
2
+
3
+ // PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
+ // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
+ // EDIT THE CORRESPONDENT .ts FILE INSTEAD
6
+
7
+ /**
8
+ * Asserts that the given condition is true, otherwise throws an error with an optional message.
9
+ * @param {any} condition - The condition to check.
10
+ * @param {string} [message] - The optional message to include in the error.
11
+ * @throws {Error} Throws an error if the condition is false.
12
+ */
13
+ export default function assert(condition, message) {
14
+ if (!condition) {
15
+ throw new Error(message || 'Assertion failure');
16
+ }
17
+ }
@@ -0,0 +1,6 @@
1
+ import { BigNumberish } from '../num.js';
2
+ /**
3
+ * Create felt Cairo type (cairo type helper)
4
+ * @returns format: felt-string
5
+ */
6
+ export declare function CairoFelt(it: BigNumberish): string;
@@ -0,0 +1,43 @@
1
+ // ----------------------------------------------------------------------------
2
+
3
+ // PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
+ // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
+ // EDIT THE CORRESPONDENT .ts FILE INSTEAD
6
+
7
+ // TODO Convert to CairoFelt base on CairoUint256 and implement it in the codebase in the backward compatible manner
8
+ import { isBigInt, isBoolean, isHex, isStringWholeNumber } from '../num.js';
9
+ import { encodeShortString, isShortString, isString, isText } from '../shortString.js';
10
+ /**
11
+ * Create felt Cairo type (cairo type helper)
12
+ * @returns format: felt-string
13
+ */
14
+ export function CairoFelt(it) {
15
+ // BN or number
16
+ if (isBigInt(it) || Number.isInteger(it)) {
17
+ return it.toString();
18
+ }
19
+ // Handling strings
20
+ if (isString(it)) {
21
+ // Hex strings
22
+ if (isHex(it)) {
23
+ return BigInt(it).toString();
24
+ }
25
+ // Text strings that must be short
26
+ if (isText(it)) {
27
+ if (!isShortString(it)) {
28
+ throw new Error(`${it} is a long string > 31 chars. Please split it into an array of short strings.`);
29
+ }
30
+ // Assuming encodeShortString returns a hex representation of the string
31
+ return BigInt(encodeShortString(it)).toString();
32
+ }
33
+ // Whole numeric strings
34
+ if (isStringWholeNumber(it)) {
35
+ return it;
36
+ }
37
+ }
38
+ // bool to felt
39
+ if (isBoolean(it)) {
40
+ return `${+it}`;
41
+ }
42
+ throw new Error(`${it} can't be computed by felt()`);
43
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Singular class handling cairo u256 data type
3
+ */
4
+ import { BigNumberish, Uint256 } from '../../types/index.js';
5
+ export declare const UINT_128_MAX: bigint;
6
+ export declare const UINT_256_MAX: bigint;
7
+ export declare const UINT_256_MIN = 0n;
8
+ export declare const UINT_256_LOW_MAX = 340282366920938463463374607431768211455n;
9
+ export declare const UINT_256_HIGH_MAX = 340282366920938463463374607431768211455n;
10
+ export declare const UINT_256_LOW_MIN = 0n;
11
+ export declare const UINT_256_HIGH_MIN = 0n;
12
+ export declare class CairoUint256 {
13
+ low: bigint;
14
+ high: bigint;
15
+ static abiSelector: string;
16
+ /**
17
+ * Default constructor (Lib usage)
18
+ * @param bigNumberish BigNumberish value representing uin256
19
+ */
20
+ constructor(bigNumberish: BigNumberish);
21
+ /**
22
+ * Direct props initialization (Api response)
23
+ */
24
+ constructor(low: BigNumberish, high: BigNumberish);
25
+ /**
26
+ * Initialization from Uint256 object
27
+ */
28
+ constructor(uint256: Uint256);
29
+ /**
30
+ * Validate if BigNumberish can be represented as Unit256
31
+ */
32
+ static validate(bigNumberish: BigNumberish): bigint;
33
+ /**
34
+ * Validate if low and high can be represented as Unit256
35
+ */
36
+ static validateProps(low: BigNumberish, high: BigNumberish): {
37
+ low: bigint;
38
+ high: bigint;
39
+ };
40
+ /**
41
+ * Check if BigNumberish can be represented as Unit256
42
+ */
43
+ static is(bigNumberish: BigNumberish): boolean;
44
+ /**
45
+ * Check if provided abi type is this data type
46
+ */
47
+ static isAbiType(abiType: string): boolean;
48
+ /**
49
+ * Return bigint representation
50
+ */
51
+ toBigInt(): bigint;
52
+ /**
53
+ * Return Uint256 structure with HexString props
54
+ * {low: HexString, high: HexString}
55
+ */
56
+ toUint256HexString(): {
57
+ low: string;
58
+ high: string;
59
+ };
60
+ /**
61
+ * Return Uint256 structure with DecimalString props
62
+ * {low: DecString, high: DecString}
63
+ */
64
+ toUint256DecimalString(): {
65
+ low: string;
66
+ high: string;
67
+ };
68
+ /**
69
+ * Return api requests representation witch is felt array
70
+ */
71
+ toApiRequest(): string[];
72
+ }
@@ -0,0 +1,117 @@
1
+ // ----------------------------------------------------------------------------
2
+
3
+ // PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
+ // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
+ // EDIT THE CORRESPONDENT .ts FILE INSTEAD
6
+
7
+ /* eslint-disable no-bitwise */
8
+ /**
9
+ * Singular class handling cairo u256 data type
10
+ */
11
+ import { addHexPrefix } from '../encode.js';
12
+ import { CairoFelt } from './felt.js';
13
+ export const UINT_128_MAX = (1n << 128n) - 1n;
14
+ export const UINT_256_MAX = (1n << 256n) - 1n;
15
+ export const UINT_256_MIN = 0n;
16
+ export const UINT_256_LOW_MAX = 340282366920938463463374607431768211455n;
17
+ export const UINT_256_HIGH_MAX = 340282366920938463463374607431768211455n;
18
+ export const UINT_256_LOW_MIN = 0n;
19
+ export const UINT_256_HIGH_MIN = 0n;
20
+ export class CairoUint256 {
21
+ constructor(...arr) {
22
+ if (typeof arr[0] === 'object' && arr.length === 1 && 'low' in arr[0] && 'high' in arr[0]) {
23
+ const props = CairoUint256.validateProps(arr[0].low, arr[0].high);
24
+ this.low = props.low;
25
+ this.high = props.high;
26
+ }
27
+ else if (arr.length === 1) {
28
+ const bigInt = CairoUint256.validate(arr[0]);
29
+ this.low = bigInt & UINT_128_MAX;
30
+ this.high = bigInt >> 128n;
31
+ }
32
+ else if (arr.length === 2) {
33
+ const props = CairoUint256.validateProps(arr[0], arr[1]);
34
+ this.low = props.low;
35
+ this.high = props.high;
36
+ }
37
+ else {
38
+ throw Error('Incorrect constructor parameters');
39
+ }
40
+ }
41
+ /**
42
+ * Validate if BigNumberish can be represented as Unit256
43
+ */
44
+ static validate(bigNumberish) {
45
+ const bigInt = BigInt(bigNumberish);
46
+ if (bigInt < UINT_256_MIN)
47
+ throw Error('bigNumberish is smaller than UINT_256_MIN');
48
+ if (bigInt > UINT_256_MAX)
49
+ throw new Error('bigNumberish is bigger than UINT_256_MAX');
50
+ return bigInt;
51
+ }
52
+ /**
53
+ * Validate if low and high can be represented as Unit256
54
+ */
55
+ static validateProps(low, high) {
56
+ const bigIntLow = BigInt(low);
57
+ const bigIntHigh = BigInt(high);
58
+ if (bigIntLow < UINT_256_LOW_MIN || bigIntLow > UINT_256_LOW_MAX) {
59
+ throw new Error('low is out of range UINT_256_LOW_MIN - UINT_256_LOW_MAX');
60
+ }
61
+ if (bigIntHigh < UINT_256_HIGH_MIN || bigIntHigh > UINT_256_HIGH_MAX) {
62
+ throw new Error('high is out of range UINT_256_HIGH_MIN - UINT_256_HIGH_MAX');
63
+ }
64
+ return { low: bigIntLow, high: bigIntHigh };
65
+ }
66
+ /**
67
+ * Check if BigNumberish can be represented as Unit256
68
+ */
69
+ static is(bigNumberish) {
70
+ try {
71
+ CairoUint256.validate(bigNumberish);
72
+ }
73
+ catch (error) {
74
+ return false;
75
+ }
76
+ return true;
77
+ }
78
+ /**
79
+ * Check if provided abi type is this data type
80
+ */
81
+ static isAbiType(abiType) {
82
+ return abiType === CairoUint256.abiSelector;
83
+ }
84
+ /**
85
+ * Return bigint representation
86
+ */
87
+ toBigInt() {
88
+ return (this.high << 128n) + this.low;
89
+ }
90
+ /**
91
+ * Return Uint256 structure with HexString props
92
+ * {low: HexString, high: HexString}
93
+ */
94
+ toUint256HexString() {
95
+ return {
96
+ low: addHexPrefix(this.low.toString(16)),
97
+ high: addHexPrefix(this.high.toString(16)),
98
+ };
99
+ }
100
+ /**
101
+ * Return Uint256 structure with DecimalString props
102
+ * {low: DecString, high: DecString}
103
+ */
104
+ toUint256DecimalString() {
105
+ return {
106
+ low: this.low.toString(10),
107
+ high: this.high.toString(10),
108
+ };
109
+ }
110
+ /**
111
+ * Return api requests representation witch is felt array
112
+ */
113
+ toApiRequest() {
114
+ return [CairoFelt(this.low), CairoFelt(this.high)];
115
+ }
116
+ }
117
+ CairoUint256.abiSelector = 'core::integer::u256';
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Singular class handling cairo u512 data type
3
+ */
4
+ import { BigNumberish, type Uint512 } from '../../types/index.js';
5
+ export declare const UINT_512_MAX: bigint;
6
+ export declare const UINT_512_MIN = 0n;
7
+ export declare const UINT_128_MIN = 0n;
8
+ export declare class CairoUint512 {
9
+ limb0: bigint;
10
+ limb1: bigint;
11
+ limb2: bigint;
12
+ limb3: bigint;
13
+ static abiSelector: string;
14
+ /**
15
+ * Default constructor (Lib usage)
16
+ * @param bigNumberish BigNumberish value representing u512
17
+ */
18
+ constructor(bigNumberish: BigNumberish);
19
+ /**
20
+ * Direct props initialization (Api response)
21
+ */
22
+ constructor(limb0: BigNumberish, limb1: BigNumberish, limb2: BigNumberish, limb3: BigNumberish);
23
+ /**
24
+ * Initialization from Uint512 object
25
+ */
26
+ constructor(uint512: Uint512);
27
+ /**
28
+ * Validate if BigNumberish can be represented as Uint512
29
+ */
30
+ static validate(bigNumberish: BigNumberish): bigint;
31
+ /**
32
+ * Validate if limbs can be represented as Uint512
33
+ */
34
+ static validateProps(limb0: BigNumberish, limb1: BigNumberish, limb2: BigNumberish, limb3: BigNumberish): {
35
+ limb0: bigint;
36
+ limb1: bigint;
37
+ limb2: bigint;
38
+ limb3: bigint;
39
+ };
40
+ /**
41
+ * Check if BigNumberish can be represented as Uint512
42
+ */
43
+ static is(bigNumberish: BigNumberish): boolean;
44
+ /**
45
+ * Check if provided abi type is this data type
46
+ */
47
+ static isAbiType(abiType: string): boolean;
48
+ /**
49
+ * Return bigint representation
50
+ */
51
+ toBigInt(): bigint;
52
+ /**
53
+ * Return Uint512 structure with HexString props
54
+ * limbx: HexString
55
+ */
56
+ toUint512HexString(): {
57
+ limb0: string;
58
+ limb1: string;
59
+ limb2: string;
60
+ limb3: string;
61
+ };
62
+ /**
63
+ * Return Uint512 structure with DecimalString props
64
+ * limbx DecString
65
+ */
66
+ toUint512DecimalString(): {
67
+ limb0: string;
68
+ limb1: string;
69
+ limb2: string;
70
+ limb3: string;
71
+ };
72
+ /**
73
+ * Return api requests representation witch is felt array
74
+ */
75
+ toApiRequest(): string[];
76
+ }
@@ -0,0 +1,136 @@
1
+ // ----------------------------------------------------------------------------
2
+
3
+ // PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
+ // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
+ // EDIT THE CORRESPONDENT .ts FILE INSTEAD
6
+
7
+ /* eslint-disable no-bitwise */
8
+ /**
9
+ * Singular class handling cairo u512 data type
10
+ */
11
+ import { addHexPrefix } from '../encode.js';
12
+ import { CairoFelt } from './felt.js';
13
+ import { UINT_128_MAX } from './uint256.js';
14
+ export const UINT_512_MAX = (1n << 512n) - 1n;
15
+ export const UINT_512_MIN = 0n;
16
+ export const UINT_128_MIN = 0n;
17
+ export class CairoUint512 {
18
+ constructor(...arr) {
19
+ if (typeof arr[0] === 'object' &&
20
+ arr.length === 1 &&
21
+ 'limb0' in arr[0] &&
22
+ 'limb1' in arr[0] &&
23
+ 'limb2' in arr[0] &&
24
+ 'limb3' in arr[0]) {
25
+ const props = CairoUint512.validateProps(arr[0].limb0, arr[0].limb1, arr[0].limb2, arr[0].limb3);
26
+ this.limb0 = props.limb0;
27
+ this.limb1 = props.limb1;
28
+ this.limb2 = props.limb2;
29
+ this.limb3 = props.limb3;
30
+ }
31
+ else if (arr.length === 1) {
32
+ const bigInt = CairoUint512.validate(arr[0]);
33
+ this.limb0 = bigInt & UINT_128_MAX;
34
+ this.limb1 = (bigInt & (UINT_128_MAX << 128n)) >> 128n;
35
+ this.limb2 = (bigInt & (UINT_128_MAX << 256n)) >> 256n;
36
+ this.limb3 = bigInt >> 384n;
37
+ }
38
+ else if (arr.length === 4) {
39
+ const props = CairoUint512.validateProps(arr[0], arr[1], arr[2], arr[3]);
40
+ this.limb0 = props.limb0;
41
+ this.limb1 = props.limb1;
42
+ this.limb2 = props.limb2;
43
+ this.limb3 = props.limb3;
44
+ }
45
+ else {
46
+ throw Error('Incorrect Uint512 constructor parameters');
47
+ }
48
+ }
49
+ /**
50
+ * Validate if BigNumberish can be represented as Uint512
51
+ */
52
+ static validate(bigNumberish) {
53
+ const bigInt = BigInt(bigNumberish);
54
+ if (bigInt < UINT_512_MIN)
55
+ throw Error('bigNumberish is smaller than UINT_512_MIN.');
56
+ if (bigInt > UINT_512_MAX)
57
+ throw Error('bigNumberish is bigger than UINT_512_MAX.');
58
+ return bigInt;
59
+ }
60
+ /**
61
+ * Validate if limbs can be represented as Uint512
62
+ */
63
+ static validateProps(limb0, limb1, limb2, limb3) {
64
+ const l0 = BigInt(limb0);
65
+ const l1 = BigInt(limb1);
66
+ const l2 = BigInt(limb2);
67
+ const l3 = BigInt(limb3);
68
+ [l0, l1, l2, l3].forEach((value, index) => {
69
+ if (value < UINT_128_MIN || value > UINT_128_MAX) {
70
+ throw Error(`limb${index} is not in the range of a u128 number`);
71
+ }
72
+ });
73
+ return { limb0: l0, limb1: l1, limb2: l2, limb3: l3 };
74
+ }
75
+ /**
76
+ * Check if BigNumberish can be represented as Uint512
77
+ */
78
+ static is(bigNumberish) {
79
+ try {
80
+ CairoUint512.validate(bigNumberish);
81
+ }
82
+ catch (error) {
83
+ return false;
84
+ }
85
+ return true;
86
+ }
87
+ /**
88
+ * Check if provided abi type is this data type
89
+ */
90
+ static isAbiType(abiType) {
91
+ return abiType === CairoUint512.abiSelector;
92
+ }
93
+ /**
94
+ * Return bigint representation
95
+ */
96
+ toBigInt() {
97
+ return (this.limb3 << 384n) + (this.limb2 << 256n) + (this.limb1 << 128n) + this.limb0;
98
+ }
99
+ /**
100
+ * Return Uint512 structure with HexString props
101
+ * limbx: HexString
102
+ */
103
+ toUint512HexString() {
104
+ return {
105
+ limb0: addHexPrefix(this.limb0.toString(16)),
106
+ limb1: addHexPrefix(this.limb1.toString(16)),
107
+ limb2: addHexPrefix(this.limb2.toString(16)),
108
+ limb3: addHexPrefix(this.limb3.toString(16)),
109
+ };
110
+ }
111
+ /**
112
+ * Return Uint512 structure with DecimalString props
113
+ * limbx DecString
114
+ */
115
+ toUint512DecimalString() {
116
+ return {
117
+ limb0: this.limb0.toString(10),
118
+ limb1: this.limb1.toString(10),
119
+ limb2: this.limb2.toString(10),
120
+ limb3: this.limb3.toString(10),
121
+ };
122
+ }
123
+ /**
124
+ * Return api requests representation witch is felt array
125
+ */
126
+ toApiRequest() {
127
+ // lower limb first : https://github.com/starkware-libs/cairo/blob/07484c52791b76abcc18fd86265756904557d0d2/corelib/src/test/integer_test.cairo#L767
128
+ return [
129
+ CairoFelt(this.limb0),
130
+ CairoFelt(this.limb1),
131
+ CairoFelt(this.limb2),
132
+ CairoFelt(this.limb3),
133
+ ];
134
+ }
135
+ }
136
+ CairoUint512.abiSelector = 'core::integer::u512';
@@ -0,0 +1,32 @@
1
+ import { ByteArray } from '../../types/lib/index.js';
2
+ /**
3
+ * convert a Cairo ByteArray to a JS string
4
+ * @param myByteArray Cairo representation of a LongString
5
+ * @returns a JS string
6
+ * @example
7
+ * ```typescript
8
+ * const myByteArray = {
9
+ * data: [],
10
+ * pending_word: '0x414243444546474849',
11
+ * pending_word_len: 9
12
+ * }
13
+ * const result: String = stringFromByteArray(myByteArray); // ABCDEFGHI
14
+ * ```
15
+ */
16
+ export declare function stringFromByteArray(myByteArray: ByteArray): string;
17
+ /**
18
+ * convert a JS string to a Cairo ByteArray
19
+ * @param targetString a JS string
20
+ * @returns Cairo representation of a LongString
21
+ * @example
22
+ * ```typescript
23
+ * const myByteArray: ByteArray = byteArrayFromString("ABCDEFGHI");
24
+ * ```
25
+ * Result is :
26
+ * {
27
+ * data: [],
28
+ * pending_word: '0x414243444546474849',
29
+ * pending_word_len: 9
30
+ * }
31
+ */
32
+ export declare function byteArrayFromString(targetString: string): ByteArray;
@@ -0,0 +1,59 @@
1
+ // ----------------------------------------------------------------------------
2
+
3
+ // PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
+ // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
+ // EDIT THE CORRESPONDENT .ts FILE INSTEAD
6
+
7
+ import { toHex } from '../num.js';
8
+ import { decodeShortString, encodeShortString, splitLongString } from '../shortString.js';
9
+ /**
10
+ * convert a Cairo ByteArray to a JS string
11
+ * @param myByteArray Cairo representation of a LongString
12
+ * @returns a JS string
13
+ * @example
14
+ * ```typescript
15
+ * const myByteArray = {
16
+ * data: [],
17
+ * pending_word: '0x414243444546474849',
18
+ * pending_word_len: 9
19
+ * }
20
+ * const result: String = stringFromByteArray(myByteArray); // ABCDEFGHI
21
+ * ```
22
+ */
23
+ export function stringFromByteArray(myByteArray) {
24
+ const pending_word = BigInt(myByteArray.pending_word) === 0n
25
+ ? ''
26
+ : decodeShortString(toHex(myByteArray.pending_word));
27
+ return (myByteArray.data.reduce((cumuledString, encodedString) => {
28
+ const add = BigInt(encodedString) === 0n ? '' : decodeShortString(toHex(encodedString));
29
+ return cumuledString + add;
30
+ }, '') + pending_word);
31
+ }
32
+ /**
33
+ * convert a JS string to a Cairo ByteArray
34
+ * @param targetString a JS string
35
+ * @returns Cairo representation of a LongString
36
+ * @example
37
+ * ```typescript
38
+ * const myByteArray: ByteArray = byteArrayFromString("ABCDEFGHI");
39
+ * ```
40
+ * Result is :
41
+ * {
42
+ * data: [],
43
+ * pending_word: '0x414243444546474849',
44
+ * pending_word_len: 9
45
+ * }
46
+ */
47
+ export function byteArrayFromString(targetString) {
48
+ const shortStrings = splitLongString(targetString);
49
+ const remainder = shortStrings[shortStrings.length - 1];
50
+ const shortStringsEncoded = shortStrings.map(encodeShortString);
51
+ const [pendingWord, pendingWordLength] = remainder === undefined || remainder.length === 31
52
+ ? ['0x00', 0]
53
+ : [shortStringsEncoded.pop(), remainder.length];
54
+ return {
55
+ data: shortStringsEncoded.length === 0 ? [] : shortStringsEncoded,
56
+ pending_word: pendingWord,
57
+ pending_word_len: pendingWordLength,
58
+ };
59
+ }