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,244 @@
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 { hexToBytes as hexToBytesNoble } from '../../noble-curves/abstract/utils.js';
8
+ import assert from './assert.js';
9
+ import { addHexPrefix, removeHexPrefix } from './encode.js';
10
+ /**
11
+ * Test if string is hex-string
12
+ * @param hex hex-string
13
+ * @returns {boolean} True if the input string is a hexadecimal string, false otherwise
14
+ * @example
15
+ * ```typescript
16
+ * const hexString1 = "0x2fd23d9182193775423497fc0c472e156c57c69e4089a1967fb288a2d84e914";
17
+ * const result1 = isHex(hexString1);
18
+ * // result1 = true
19
+ *
20
+ * const hexString2 = "2fd23d9182193775423497fc0c472e156c57c69e4089a1967fb288a2d84e914";
21
+ * const result2 = isHex(hexString2);
22
+ * // result2 = false
23
+ * ```
24
+ */
25
+ export function isHex(hex) {
26
+ return /^0x[0-9a-f]*$/i.test(hex);
27
+ }
28
+ /**
29
+ * Convert BigNumberish to bigint
30
+ */
31
+ export function toBigInt(value) {
32
+ return BigInt(value);
33
+ }
34
+ /**
35
+ * Test if value is bigint
36
+ */
37
+ export function isBigInt(value) {
38
+ return typeof value === 'bigint';
39
+ }
40
+ /**
41
+ * Convert BigNumberish to hex-string
42
+ * @returns format: hex-string
43
+ */
44
+ export function toHex(number) {
45
+ return addHexPrefix(toBigInt(number).toString(16));
46
+ }
47
+ /**
48
+ * Alias of ToHex
49
+ */
50
+ export const toHexString = toHex;
51
+ /**
52
+ * Convert BigNumberish to storage-key-string
53
+ *
54
+ * Same as toHex but conforming to the STORAGE_KEY pattern `^0x0[0-7]{1}[a-fA-F0-9]{0,62}$`.
55
+ *
56
+ * A storage key is represented as up to 62 hex digits, 3 bits, and 5 leading zeroes:
57
+ * `0x0 + [0-7] + 62 hex = 0x + 64 hex`
58
+ * @returns format: storage-key-string
59
+ */
60
+ export function toStorageKey(number) {
61
+ const res = addHexPrefix(toBigInt(number).toString(16).padStart(64, '0'));
62
+ return res;
63
+ }
64
+ /**
65
+ * Convert hexadecimal string to decimal string
66
+ * @param hex hex-string
67
+ * @returns format: decimal string
68
+ */
69
+ export function hexToDecimalString(hex) {
70
+ return BigInt(addHexPrefix(hex)).toString(10);
71
+ }
72
+ /**
73
+ * Remove hex string leading zero and lowercase it
74
+ * @example '0x01A...' -> '0x1a..'
75
+ * @param hex hex-string
76
+ * @returns format: hex-string
77
+ */
78
+ export const cleanHex = (hex) => hex.toLowerCase().replace(/^(0x)0+/, '$1');
79
+ /**
80
+ * Asserts input is equal to or greater then lowerBound and lower then upperBound.
81
+ *
82
+ * The `inputName` parameter is used in the assertion message.
83
+ * @param input Value to check
84
+ * @param lowerBound Lower bound value
85
+ * @param upperBound Upper bound value
86
+ * @param inputName Name of the input for error message
87
+ * @Throws Error if input is out of range
88
+ * @example
89
+ * ```typescript
90
+ * const input1:BigNumberish = 10;
91
+ * assertInRange(input1, 5, 20, 'value')
92
+ *
93
+ * const input2: BigNumberish = 25;
94
+ * assertInRange(input2, 5, 20, 'value');
95
+ * // Throws Error: Message not signable, invalid value length.
96
+ * ```
97
+ */
98
+ export function assertInRange(input, lowerBound, upperBound, inputName = '') {
99
+ const messageSuffix = inputName === '' ? 'invalid length' : `invalid ${inputName} length`;
100
+ const inputBigInt = BigInt(input);
101
+ const lowerBoundBigInt = BigInt(lowerBound);
102
+ const upperBoundBigInt = BigInt(upperBound);
103
+ assert(inputBigInt >= lowerBoundBigInt && inputBigInt <= upperBoundBigInt, `Message not signable, ${messageSuffix}.`);
104
+ }
105
+ /**
106
+ * Convert BigNumberish array to decimal string array
107
+ * @returns format: decimal string array
108
+ */
109
+ export function bigNumberishArrayToDecimalStringArray(rawCalldata) {
110
+ return rawCalldata.map((x) => toBigInt(x).toString(10));
111
+ }
112
+ /**
113
+ * Convert BigNumberish array to hexadecimal string array
114
+ * @returns format: hex-string array
115
+ */
116
+ export function bigNumberishArrayToHexadecimalStringArray(rawCalldata) {
117
+ return rawCalldata.map((x) => toHex(x));
118
+ }
119
+ /**
120
+ * Test if string is whole number (0, 1, 2, 3...)
121
+ */
122
+ export const isStringWholeNumber = (value) => /^\d+$/.test(value);
123
+ /**
124
+ * Convert string to decimal string
125
+ * @returns format: decimal string
126
+ * @example
127
+ * ```typescript
128
+ * const result = getDecimalString("0x1a");
129
+ * // result = "26"
130
+ *
131
+ * const result2 = getDecimalString("Hello");
132
+ * // Throws Error: "Hello need to be hex-string or whole-number-string"
133
+ * ```
134
+ */
135
+ export function getDecimalString(value) {
136
+ if (isHex(value)) {
137
+ return hexToDecimalString(value);
138
+ }
139
+ if (isStringWholeNumber(value)) {
140
+ return value;
141
+ }
142
+ throw new Error(`${value} need to be hex-string or whole-number-string`);
143
+ }
144
+ /**
145
+ * Convert string to hexadecimal string
146
+ * @returns format: hex-string
147
+ * @example
148
+ * ```typescript
149
+ * const result = getHexString("123");
150
+ * // result = "0x7b"
151
+ *
152
+ * const result2 = getHexString("Hello");
153
+ * // Throws Error: Hello need to be hex-string or whole-number-string
154
+ * ```
155
+ */
156
+ export function getHexString(value) {
157
+ if (isHex(value)) {
158
+ return value;
159
+ }
160
+ if (isStringWholeNumber(value)) {
161
+ return toHexString(value);
162
+ }
163
+ throw new Error(`${value} need to be hex-string or whole-number-string`);
164
+ }
165
+ /**
166
+ * Convert string array to hex-string array
167
+ * @returns format: hex-string array
168
+ */
169
+ export function getHexStringArray(value) {
170
+ return value.map((el) => getHexString(el));
171
+ }
172
+ /**
173
+ * Convert boolean to "0" or "1"
174
+ * @param value The boolean value to be converted.
175
+ * @returns {boolean} Returns true if the value is a number, otherwise returns false.
176
+ * @example
177
+ * ```typescript
178
+ * const result = toCairoBool(true);
179
+ * // result ="1"
180
+ *
181
+ * const result2 = toCairoBool(false);
182
+ * // result2 = "0"
183
+ * ```
184
+ */
185
+ export const toCairoBool = (value) => (+value).toString();
186
+ /**
187
+ * Convert hex-string to an array of Bytes (Uint8Array)
188
+ * @param value hex-string
189
+ */
190
+ export function hexToBytes(value) {
191
+ if (!isHex(value))
192
+ throw new Error(`${value} need to be a hex-string`);
193
+ let adaptedValue = removeHexPrefix(value);
194
+ if (adaptedValue.length % 2 !== 0) {
195
+ adaptedValue = `0${adaptedValue}`;
196
+ }
197
+ return hexToBytesNoble(adaptedValue);
198
+ }
199
+ /**
200
+ *
201
+ * @param number value to be increased
202
+ * @param percent integer as percent ex. 50 for 50%
203
+ * @returns increased value
204
+ */
205
+ export function addPercent(number, percent) {
206
+ const bigIntNum = BigInt(number);
207
+ return bigIntNum + (bigIntNum * BigInt(percent)) / 100n;
208
+ }
209
+ /**
210
+ * Check if a value is a number.
211
+ *
212
+ * @param {unknown} value - The value to check.
213
+ * @returns {boolean} Returns true if the value is a number, otherwise returns false.
214
+ * @example
215
+ * ```typescript
216
+ * const result = isNumber(123);
217
+ * // result = true
218
+ *
219
+ * const result2 = isNumber("123");
220
+ * // result2 = false
221
+ * ```
222
+ * @return {boolean} Returns true if the value is a number, otherwise returns false.
223
+ */
224
+ export function isNumber(value) {
225
+ return typeof value === 'number';
226
+ }
227
+ /**
228
+ * Checks if a given value is of boolean type.
229
+ *
230
+ * @param {unknown} value - The value to check.
231
+ * @returns {boolean} - True if the value is of boolean type, false otherwise.
232
+ * @example
233
+ * ```typescript
234
+ * const result = isBoolean(true);
235
+ * // result = true
236
+ *
237
+ * const result2 = isBoolean(false);
238
+ * // result2 = false
239
+ * ```
240
+ * @return {boolean} - True if the value is of boolean type, false otherwise.
241
+ */
242
+ export function isBoolean(value) {
243
+ return typeof value === 'boolean';
244
+ }
@@ -0,0 +1,48 @@
1
+ import { BigNumberish } from '../types/index.js';
2
+ /**
3
+ * Calculate hex-string keccak hash for a given BigNumberish
4
+ *
5
+ * BigNumberish -> hex-string keccak hash
6
+ * @returns format: hex-string
7
+ */
8
+ export declare function keccakBn(value: BigNumberish): string;
9
+ /**
10
+ * Calculate bigint keccak hash for a given string
11
+ *
12
+ * String -> bigint keccak hash
13
+ *
14
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/public/abi.py#L17-L22)
15
+ * @param str the value you want to get the keccak hash from
16
+ * @returns starknet keccak hash as BigInt
17
+ */
18
+ export declare function starknetKeccak(str: string): bigint;
19
+ /**
20
+ * Calculate hex-string selector for a given abi-function-name
21
+ *
22
+ * Abi-function-name -> hex-string selector
23
+ *
24
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/public/abi.py#L25-L26)
25
+ * @param funcName ascii-string of 'abi function name'
26
+ * @returns format: hex-string; selector for 'abi function name'
27
+ */
28
+ export declare function getSelectorFromName(funcName: string): string;
29
+ /**
30
+ * Calculate hex-string selector from abi-function-name, decimal string or hex string
31
+ *
32
+ * ('abi-function-name' or dec-string or hex-string) -> hex-string selector
33
+ *
34
+ * @param value hex-string | dec-string | ascii-string
35
+ * @returns format: hex-string
36
+ * @example
37
+ * ```typescript
38
+ * const selector: string = getSelector("myFunction");
39
+ * // selector = "0x7e44bafo"
40
+ *
41
+ * const selector1: string = getSelector("0x123abc");
42
+ * // selector1 = "0x123abc"
43
+ *
44
+ * const selector2: string = getSelector("123456");
45
+ * // selector2 = "0x1e240"
46
+ * ```
47
+ */
48
+ export declare function getSelector(value: string): string;
@@ -0,0 +1,85 @@
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 { keccak } from '../../scure-starknet/index.js';
8
+ import { MASK_250 } from '../constants.js';
9
+ import { addHexPrefix, removeHexPrefix, utf8ToArray } from './encode.js';
10
+ import { hexToBytes, isHex, isStringWholeNumber, toHex, toHexString } from './num.js';
11
+ /**
12
+ * Calculate hex-string keccak hash for a given BigNumberish
13
+ *
14
+ * BigNumberish -> hex-string keccak hash
15
+ * @returns format: hex-string
16
+ */
17
+ export function keccakBn(value) {
18
+ const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
19
+ const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
20
+ return addHexPrefix(keccak(hexToBytes(addHexPrefix(evenHex))).toString(16));
21
+ }
22
+ /**
23
+ * Calculate hex-string keccak hash for a given string
24
+ *
25
+ * String -> hex-string keccak hash
26
+ * @returns format: hex-string
27
+ */
28
+ function keccakHex(str) {
29
+ return addHexPrefix(keccak(utf8ToArray(str)).toString(16));
30
+ }
31
+ /**
32
+ * Calculate bigint keccak hash for a given string
33
+ *
34
+ * String -> bigint keccak hash
35
+ *
36
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/public/abi.py#L17-L22)
37
+ * @param str the value you want to get the keccak hash from
38
+ * @returns starknet keccak hash as BigInt
39
+ */
40
+ export function starknetKeccak(str) {
41
+ const hash = BigInt(keccakHex(str));
42
+ // eslint-disable-next-line no-bitwise
43
+ return hash & MASK_250;
44
+ }
45
+ /**
46
+ * Calculate hex-string selector for a given abi-function-name
47
+ *
48
+ * Abi-function-name -> hex-string selector
49
+ *
50
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/public/abi.py#L25-L26)
51
+ * @param funcName ascii-string of 'abi function name'
52
+ * @returns format: hex-string; selector for 'abi function name'
53
+ */
54
+ export function getSelectorFromName(funcName) {
55
+ // sometimes BigInteger pads the hex string with zeros, which is not allowed in the starknet api
56
+ return toHex(starknetKeccak(funcName));
57
+ }
58
+ /**
59
+ * Calculate hex-string selector from abi-function-name, decimal string or hex string
60
+ *
61
+ * ('abi-function-name' or dec-string or hex-string) -> hex-string selector
62
+ *
63
+ * @param value hex-string | dec-string | ascii-string
64
+ * @returns format: hex-string
65
+ * @example
66
+ * ```typescript
67
+ * const selector: string = getSelector("myFunction");
68
+ * // selector = "0x7e44bafo"
69
+ *
70
+ * const selector1: string = getSelector("0x123abc");
71
+ * // selector1 = "0x123abc"
72
+ *
73
+ * const selector2: string = getSelector("123456");
74
+ * // selector2 = "0x1e240"
75
+ * ```
76
+ */
77
+ export function getSelector(value) {
78
+ if (isHex(value)) {
79
+ return value;
80
+ }
81
+ if (isStringWholeNumber(value)) {
82
+ return toHexString(value);
83
+ }
84
+ return getSelectorFromName(value);
85
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Test if string contains only ASCII characters (string can be ascii text)
3
+ */
4
+ export declare function isASCII(str: string): boolean;
5
+ /**
6
+ * Test if string is a Cairo short string (string has less or equal 31 characters)
7
+ */
8
+ export declare function isShortString(str: string): boolean;
9
+ /**
10
+ * Test if string contains only numbers (string can be converted to decimal number)
11
+ */
12
+ export declare function isDecimalString(str: string): boolean;
13
+ /**
14
+ * Checks if a given value is a string.
15
+ *
16
+ * @param {unknown} value - The value to be checked.
17
+ * @return {boolean} - Returns true if the value is a string, false otherwise.
18
+ */
19
+ export declare function isString(value: unknown): value is string;
20
+ /**
21
+ * Test if value is a free-from string text, and not a hex string or number string
22
+ */
23
+ export declare function isText(val: any): boolean;
24
+ /**
25
+ * Test if value is short text
26
+ */
27
+ export declare const isShortText: (val: any) => boolean;
28
+ /**
29
+ * Test if value is long text
30
+ */
31
+ export declare const isLongText: (val: any) => boolean;
32
+ /**
33
+ * Split long text into short strings
34
+ */
35
+ export declare function splitLongString(longStr: string): string[];
36
+ /**
37
+ * Convert an ASCII string to a hexadecimal string.
38
+ * @param str short string (ASCII string, 31 characters max)
39
+ * @returns format: hex-string; 248 bits max
40
+ * @example
41
+ * ```typescript
42
+ * const myEncodedString: string = encodeShortString("uri/pict/t38.jpg");
43
+ * // return hex string (ex."0x7572692f706963742f7433382e6a7067")
44
+ * ```
45
+ */
46
+ export declare function encodeShortString(str: string): string;
47
+ /**
48
+ * Convert a hexadecimal or decimal string to an ASCII string.
49
+ * @param str representing a 248 bit max number (ex. "0x1A4F64EA56" or "236942575435676423")
50
+ * @returns format: short string; 31 characters max
51
+ * @example
52
+ * ```typescript
53
+ * const myDecodedString: string = decodeShortString("0x7572692f706963742f7433382e6a7067");
54
+ * // return string (ex."uri/pict/t38.jpg")
55
+ * ```
56
+ */
57
+ export declare function decodeShortString(str: string): string;
@@ -0,0 +1,96 @@
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 { TEXT_TO_FELT_MAX_LEN } from '../constants.js';
8
+ import { addHexPrefix, removeHexPrefix } from './encode.js';
9
+ import { isHex, isStringWholeNumber } from './num.js';
10
+ /**
11
+ * Test if string contains only ASCII characters (string can be ascii text)
12
+ */
13
+ export function isASCII(str) {
14
+ // eslint-disable-next-line no-control-regex
15
+ return /^[\x00-\x7F]*$/.test(str);
16
+ }
17
+ /**
18
+ * Test if string is a Cairo short string (string has less or equal 31 characters)
19
+ */
20
+ export function isShortString(str) {
21
+ return str.length <= TEXT_TO_FELT_MAX_LEN;
22
+ }
23
+ /**
24
+ * Test if string contains only numbers (string can be converted to decimal number)
25
+ */
26
+ export function isDecimalString(str) {
27
+ return /^[0-9]*$/i.test(str);
28
+ }
29
+ /**
30
+ * Checks if a given value is a string.
31
+ *
32
+ * @param {unknown} value - The value to be checked.
33
+ * @return {boolean} - Returns true if the value is a string, false otherwise.
34
+ */
35
+ export function isString(value) {
36
+ return typeof value === 'string';
37
+ }
38
+ /**
39
+ * Test if value is a free-from string text, and not a hex string or number string
40
+ */
41
+ export function isText(val) {
42
+ return isString(val) && !isHex(val) && !isStringWholeNumber(val);
43
+ }
44
+ /**
45
+ * Test if value is short text
46
+ */
47
+ export const isShortText = (val) => isText(val) && isShortString(val);
48
+ /**
49
+ * Test if value is long text
50
+ */
51
+ export const isLongText = (val) => isText(val) && !isShortString(val);
52
+ /**
53
+ * Split long text into short strings
54
+ */
55
+ export function splitLongString(longStr) {
56
+ const regex = RegExp(`[^]{1,${TEXT_TO_FELT_MAX_LEN}}`, 'g');
57
+ return longStr.match(regex) || [];
58
+ }
59
+ /**
60
+ * Convert an ASCII string to a hexadecimal string.
61
+ * @param str short string (ASCII string, 31 characters max)
62
+ * @returns format: hex-string; 248 bits max
63
+ * @example
64
+ * ```typescript
65
+ * const myEncodedString: string = encodeShortString("uri/pict/t38.jpg");
66
+ * // return hex string (ex."0x7572692f706963742f7433382e6a7067")
67
+ * ```
68
+ */
69
+ export function encodeShortString(str) {
70
+ if (!isASCII(str))
71
+ throw new Error(`${str} is not an ASCII string`);
72
+ if (!isShortString(str))
73
+ throw new Error(`${str} is too long`);
74
+ return addHexPrefix(str.replace(/./g, (char) => char.charCodeAt(0).toString(16)));
75
+ }
76
+ /**
77
+ * Convert a hexadecimal or decimal string to an ASCII string.
78
+ * @param str representing a 248 bit max number (ex. "0x1A4F64EA56" or "236942575435676423")
79
+ * @returns format: short string; 31 characters max
80
+ * @example
81
+ * ```typescript
82
+ * const myDecodedString: string = decodeShortString("0x7572692f706963742f7433382e6a7067");
83
+ * // return string (ex."uri/pict/t38.jpg")
84
+ * ```
85
+ */
86
+ export function decodeShortString(str) {
87
+ if (!isASCII(str))
88
+ throw new Error(`${str} is not an ASCII string`);
89
+ if (isHex(str)) {
90
+ return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
91
+ }
92
+ if (isDecimalString(str)) {
93
+ return decodeShortString('0X'.concat(BigInt(str).toString(16)));
94
+ }
95
+ throw new Error(`${str} is not Hex or decimal`);
96
+ }
@@ -0,0 +1,113 @@
1
+ import { StarknetChainId } from '../constants.js';
2
+ import { BigNumberish } from '../types/index.js';
3
+ import { CairoCustomEnum } from './calldata/enum/CairoCustomEnum.js';
4
+ /**
5
+ * Decodes an array of BigInts into a string using the given algorithm.
6
+ * @param {bigint[]} encoded - The encoded array of BigInts.
7
+ * @return {string} The decoded string.
8
+ */
9
+ export declare function useDecoded(encoded: bigint[]): string;
10
+ /**
11
+ * Encodes a string into a bigint value.
12
+ *
13
+ * @param {string} decoded - The string to be encoded.
14
+ * @returns {bigint} - The encoded bigint value.
15
+ */
16
+ export declare function useEncoded(decoded: string): bigint;
17
+ export declare const enum StarknetIdContract {
18
+ MAINNET = "0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678",
19
+ TESTNET_SEPOLIA = "0x0707f09bc576bd7cfee59694846291047e965f4184fe13dac62c56759b3b6fa7"
20
+ }
21
+ /**
22
+ * Returns the Starknet ID contract address based on the provided chain ID.
23
+ *
24
+ * @param {StarknetChainId} chainId - The chain ID of the Starknet network.
25
+ * @return {string} The Starknet ID contract address.
26
+ * @throws {Error} Throws an error if the Starknet ID contract is not deployed on the network.
27
+ */
28
+ export declare function getStarknetIdContract(chainId: StarknetChainId): string;
29
+ export declare const enum StarknetIdIdentityContract {
30
+ MAINNET = "0x05dbdedc203e92749e2e746e2d40a768d966bd243df04a6b712e222bc040a9af",
31
+ TESTNET_SEPOLIA = "0x070DF8B4F5cb2879f8592849fA8f3134da39d25326B8558cc9C8FE8D47EA3A90"
32
+ }
33
+ /**
34
+ * Returns the Starknet ID identity contract address for the given chain ID.
35
+ *
36
+ * @param {StarknetChainId} chainId - The chain ID for the specified network.
37
+ *
38
+ * @return {string} - The Starknet ID identity contract address for the specified network.
39
+ *
40
+ * @throws {Error} - If the Starknet ID verifier contract is not deployed on the network.
41
+ */
42
+ export declare function getStarknetIdIdentityContract(chainId: StarknetChainId): string;
43
+ export declare const StarknetIdMulticallContract = "0x034ffb8f4452df7a613a0210824d6414dbadcddce6c6e19bf4ddc9e22ce5f970";
44
+ /**
45
+ * Returns the Starknet.id multicall contract address based on the provided chainId.
46
+ *
47
+ * @param {StarknetChainId} chainId - The chainId of the network.
48
+ * @return {string} - The address of the Starknet.id multicall contract.
49
+ * @throws {Error} - If the Starknet.id multicall contract is not deployed on the network.
50
+ */
51
+ export declare function getStarknetIdMulticallContract(chainId: StarknetChainId): string;
52
+ export declare const enum StarknetIdVerifierContract {
53
+ MAINNET = "0x07d14dfd8ee95b41fce179170d88ba1f0d5a512e13aeb232f19cfeec0a88f8bf",
54
+ TESTNET_SEPOLIA = "0x0182EcE8173C216A395f4828e1523541b7e3600bf190CB252E1a1A0cE219d184"
55
+ }
56
+ /**
57
+ * Returns the address of the Starknet ID Verifier contract based on the specified chain ID.
58
+ *
59
+ * @param {StarknetChainId} chainId - The ID of the Starknet chain.
60
+ * @return {string} - The address of the Starknet ID Verifier contract.
61
+ * @throws {Error} - If the Starknet ID Verifier contract is not deployed on the specified network.
62
+ */
63
+ export declare function getStarknetIdVerifierContract(chainId: StarknetChainId): string;
64
+ export declare const enum StarknetIdPfpContract {
65
+ MAINNET = "0x070aaa20ec4a46da57c932d9fd89ca5e6bb9ca3188d3df361a32306aff7d59c7",
66
+ TESTNET_SEPOLIA = "0x058061bb6bdc501eE215172c9f87d557C1E0f466dC498cA81b18f998Bf1362b2"
67
+ }
68
+ /**
69
+ * Retrieves the contract address of the Starknet.id profile picture verifier contract based on the given chain ID.
70
+ *
71
+ * @param {StarknetChainId} chainId - The chain ID of the network.
72
+ * @returns {string} - The contract address of the Starknet.id profile picture verifier contract.
73
+ * @throws {Error} - Throws an error if the Starknet.id profile picture verifier contract is not yet deployed on the network.
74
+ */
75
+ export declare function getStarknetIdPfpContract(chainId: StarknetChainId): string;
76
+ export declare const enum StarknetIdPopContract {
77
+ MAINNET = "0x0293eb2ba9862f762bd3036586d5755a782bd22e6f5028320f1d0405fd47bff4",
78
+ TESTNET_SEPOLIA = "0x0023FE3b845ed5665a9eb3792bbB17347B490EE4090f855C1298d03BB5F49B49"
79
+ }
80
+ /**
81
+ * Retrieves the Starknet ID Proof of Personhood (IdPop) verifier contract address for the given chain ID.
82
+ *
83
+ * @param {StarknetChainId} chainId - The chain ID of the Starknet network.
84
+ * @return {string} - The Starknet ID Pop contract address.
85
+ * @throws {Error} - If the Starknet ID Pop contract is not deployed on the specified network.
86
+ */
87
+ export declare function getStarknetIdPopContract(chainId: StarknetChainId): string;
88
+ /**
89
+ * Executes a method and returns a CairoCustomEnum object.
90
+ *
91
+ * Functions to build CairoCustomEnum for multicall contracts
92
+ * @param {Object} staticEx - An optional object defining the "Static" value of the CairoCustomEnum.
93
+ * @param {number[]} ifEqual - An optional array defining the "IfEqual" value of the CairoCustomEnum.
94
+ * @param {number[]} ifNotEqual - An optional array defining the "IfNotEqual" value of the CairoCustomEnum.
95
+ * @return {CairoCustomEnum} - The created CairoCustomEnum object.
96
+ */
97
+ export declare function execution(staticEx: {} | undefined, ifEqual?: number[] | undefined, ifNotEqual?: number[] | undefined): CairoCustomEnum;
98
+ /**
99
+ * Creates a new instance of CairoCustomEnum.
100
+ *
101
+ * @param {BigNumberish | undefined} hardcoded - The hardcoded value for the CairoCustomEnum.
102
+ * @param {number[] | undefined} reference - The reference array for the CairoCustomEnum.
103
+ * @returns {CairoCustomEnum} The new instance of CairoCustomEnum.
104
+ */
105
+ export declare function dynamicFelt(hardcoded: BigNumberish | undefined, reference?: number[] | undefined): CairoCustomEnum;
106
+ /**
107
+ * Creates a new instance of CairoCustomEnum with the given parameters.
108
+ * @param {BigNumberish | undefined} hardcoded - The hardcoded value.
109
+ * @param {BigNumberish[] | undefined} [reference] - The reference value (optional).
110
+ * @param {BigNumberish[] | undefined} [arrayReference] - The array reference value (optional).
111
+ * @return {CairoCustomEnum} - The new instance of CairoCustomEnum.
112
+ */
113
+ export declare function dynamicCallData(hardcoded: BigNumberish | undefined, reference?: BigNumberish[] | undefined, arrayReference?: BigNumberish[] | undefined): CairoCustomEnum;