ccxt 4.3.69 → 4.3.71

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 (187) hide show
  1. package/README.md +7 -6
  2. package/dist/ccxt.browser.min.js +13 -10
  3. package/dist/cjs/ccxt.js +8 -1
  4. package/dist/cjs/src/abstract/paradex.js +9 -0
  5. package/dist/cjs/src/ascendex.js +1 -1
  6. package/dist/cjs/src/base/Exchange.js +55 -0
  7. package/dist/cjs/src/binance.js +1 -1
  8. package/dist/cjs/src/blofin.js +63 -6
  9. package/dist/cjs/src/bybit.js +1 -1
  10. package/dist/cjs/src/coinbaseinternational.js +168 -2
  11. package/dist/cjs/src/cryptocom.js +9 -1
  12. package/dist/cjs/src/hitbtc.js +1 -1
  13. package/dist/cjs/src/paradex.js +2075 -0
  14. package/dist/cjs/src/poloniex.js +1 -0
  15. package/dist/cjs/src/pro/bequant.js +4 -0
  16. package/dist/cjs/src/pro/blofin.js +665 -0
  17. package/dist/cjs/src/pro/coinbaseinternational.js +154 -9
  18. package/dist/cjs/src/pro/cryptocom.js +3 -1
  19. package/dist/cjs/src/pro/hitbtc.js +26 -8
  20. package/dist/cjs/src/pro/okx.js +7 -0
  21. package/dist/cjs/src/pro/paradex.js +365 -0
  22. package/dist/cjs/src/pro/poloniex.js +37 -12
  23. package/dist/cjs/src/pro/woo.js +5 -4
  24. package/dist/cjs/src/static_dependencies/noble-curves/abstract/poseidon.js +100 -0
  25. package/dist/cjs/src/static_dependencies/noble-curves/abstract/weierstrass.js +1 -0
  26. package/dist/cjs/src/static_dependencies/scure-starknet/index.js +284 -0
  27. package/dist/cjs/src/static_dependencies/starknet/constants.js +60 -0
  28. package/dist/cjs/src/static_dependencies/starknet/types/calldata.js +26 -0
  29. package/dist/cjs/src/static_dependencies/starknet/types/lib/contract/abi.js +8 -0
  30. package/dist/cjs/src/static_dependencies/starknet/types/lib/contract/index.js +13 -0
  31. package/dist/cjs/src/static_dependencies/starknet/types/lib/index.js +56 -0
  32. package/dist/cjs/src/static_dependencies/starknet/types/typedData.js +19 -0
  33. package/dist/cjs/src/static_dependencies/starknet/utils/assert.js +15 -0
  34. package/dist/cjs/src/static_dependencies/starknet/utils/cairoDataTypes/felt.js +44 -0
  35. package/dist/cjs/src/static_dependencies/starknet/utils/cairoDataTypes/uint256.js +122 -0
  36. package/dist/cjs/src/static_dependencies/starknet/utils/cairoDataTypes/uint512.js +137 -0
  37. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/byteArray.js +61 -0
  38. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/cairo.js +218 -0
  39. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/enum/CairoCustomEnum.js +57 -0
  40. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/enum/CairoOption.js +64 -0
  41. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/enum/CairoResult.js +63 -0
  42. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/formatter.js +66 -0
  43. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/index.js +281 -0
  44. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/parser/index.js +33 -0
  45. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/parser/parser-0-1.1.0.js +37 -0
  46. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/parser/parser-2.0.0.js +40 -0
  47. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/propertyOrder.js +156 -0
  48. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/requestParser.js +250 -0
  49. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/responseParser.js +215 -0
  50. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/tuple.js +112 -0
  51. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/validate.js +206 -0
  52. package/dist/cjs/src/static_dependencies/starknet/utils/encode.js +58 -0
  53. package/dist/cjs/src/static_dependencies/starknet/utils/hash/classHash.js +57 -0
  54. package/dist/cjs/src/static_dependencies/starknet/utils/merkle.js +76 -0
  55. package/dist/cjs/src/static_dependencies/starknet/utils/num.js +92 -0
  56. package/dist/cjs/src/static_dependencies/starknet/utils/selector.js +48 -0
  57. package/dist/cjs/src/static_dependencies/starknet/utils/shortString.js +101 -0
  58. package/dist/cjs/src/static_dependencies/starknet/utils/typedData.js +334 -0
  59. package/dist/cjs/src/woo.js +4 -2
  60. package/js/ccxt.d.ts +11 -2
  61. package/js/ccxt.js +8 -2
  62. package/js/src/abstract/coinbaseinternational.d.ts +1 -1
  63. package/js/src/abstract/paradex.d.ts +43 -0
  64. package/js/src/abstract/paradex.js +11 -0
  65. package/js/src/ascendex.js +1 -1
  66. package/js/src/base/Exchange.d.ts +8 -0
  67. package/js/src/base/Exchange.js +51 -0
  68. package/js/src/binance.js +1 -1
  69. package/js/src/blofin.d.ts +1 -1
  70. package/js/src/blofin.js +63 -6
  71. package/js/src/bybit.js +1 -1
  72. package/js/src/coinbaseinternational.d.ts +6 -1
  73. package/js/src/coinbaseinternational.js +168 -2
  74. package/js/src/cryptocom.js +10 -2
  75. package/js/src/hitbtc.js +1 -1
  76. package/js/src/paradex.d.ts +76 -0
  77. package/js/src/paradex.js +2075 -0
  78. package/js/src/poloniex.js +1 -0
  79. package/js/src/pro/bequant.js +4 -0
  80. package/js/src/pro/blofin.d.ts +39 -0
  81. package/js/src/pro/blofin.js +668 -0
  82. package/js/src/pro/coinbaseinternational.d.ts +5 -1
  83. package/js/src/pro/coinbaseinternational.js +155 -10
  84. package/js/src/pro/cryptocom.js +4 -2
  85. package/js/src/pro/hitbtc.d.ts +1 -1
  86. package/js/src/pro/hitbtc.js +26 -8
  87. package/js/src/pro/okx.js +7 -0
  88. package/js/src/pro/paradex.d.ts +15 -0
  89. package/js/src/pro/paradex.js +366 -0
  90. package/js/src/pro/poloniex.js +37 -12
  91. package/js/src/pro/woo.js +5 -4
  92. package/js/src/static_dependencies/noble-curves/abstract/weierstrass.d.ts +24 -0
  93. package/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +1 -1
  94. package/js/src/static_dependencies/scure-starknet/index.d.ts +79 -0
  95. package/js/src/static_dependencies/scure-starknet/index.js +323 -0
  96. package/js/src/static_dependencies/starknet/constants.d.ts +61 -0
  97. package/js/src/static_dependencies/starknet/constants.js +67 -0
  98. package/js/src/static_dependencies/starknet/index.d.ts +7 -0
  99. package/js/src/static_dependencies/starknet/index.js +50 -0
  100. package/js/src/static_dependencies/starknet/types/cairoEnum.d.ts +2 -0
  101. package/js/src/static_dependencies/starknet/types/cairoEnum.js +7 -0
  102. package/js/src/static_dependencies/starknet/types/calldata.d.ts +19 -0
  103. package/js/src/static_dependencies/starknet/types/calldata.js +28 -0
  104. package/js/src/static_dependencies/starknet/types/index.d.ts +13 -0
  105. package/js/src/static_dependencies/starknet/types/index.js +16 -0
  106. package/js/src/static_dependencies/starknet/types/lib/contract/abi.d.ts +71 -0
  107. package/js/src/static_dependencies/starknet/types/lib/contract/abi.js +13 -0
  108. package/js/src/static_dependencies/starknet/types/lib/contract/index.d.ts +24 -0
  109. package/js/src/static_dependencies/starknet/types/lib/contract/index.js +16 -0
  110. package/js/src/static_dependencies/starknet/types/lib/contract/legacy.d.ts +33 -0
  111. package/js/src/static_dependencies/starknet/types/lib/contract/legacy.js +7 -0
  112. package/js/src/static_dependencies/starknet/types/lib/contract/sierra.d.ts +52 -0
  113. package/js/src/static_dependencies/starknet/types/lib/contract/sierra.js +7 -0
  114. package/js/src/static_dependencies/starknet/types/lib/index.d.ts +248 -0
  115. package/js/src/static_dependencies/starknet/types/lib/index.js +52 -0
  116. package/js/src/static_dependencies/starknet/types/typedData.d.ts +44 -0
  117. package/js/src/static_dependencies/starknet/types/typedData.js +19 -0
  118. package/js/src/static_dependencies/starknet/utils/address.d.ts +53 -0
  119. package/js/src/static_dependencies/starknet/utils/address.js +89 -0
  120. package/js/src/static_dependencies/starknet/utils/assert.d.ts +7 -0
  121. package/js/src/static_dependencies/starknet/utils/assert.js +17 -0
  122. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/felt.d.ts +6 -0
  123. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/felt.js +43 -0
  124. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint256.d.ts +72 -0
  125. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint256.js +117 -0
  126. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint512.d.ts +76 -0
  127. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint512.js +136 -0
  128. package/js/src/static_dependencies/starknet/utils/calldata/byteArray.d.ts +32 -0
  129. package/js/src/static_dependencies/starknet/utils/calldata/byteArray.js +59 -0
  130. package/js/src/static_dependencies/starknet/utils/calldata/cairo.d.ts +183 -0
  131. package/js/src/static_dependencies/starknet/utils/calldata/cairo.js +229 -0
  132. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoCustomEnum.d.ts +38 -0
  133. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoCustomEnum.js +57 -0
  134. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoOption.d.ts +35 -0
  135. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoOption.js +64 -0
  136. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoResult.d.ts +34 -0
  137. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoResult.js +63 -0
  138. package/js/src/static_dependencies/starknet/utils/calldata/enum/index.d.ts +3 -0
  139. package/js/src/static_dependencies/starknet/utils/calldata/enum/index.js +9 -0
  140. package/js/src/static_dependencies/starknet/utils/calldata/formatter.d.ts +9 -0
  141. package/js/src/static_dependencies/starknet/utils/calldata/formatter.js +67 -0
  142. package/js/src/static_dependencies/starknet/utils/calldata/index.d.ts +89 -0
  143. package/js/src/static_dependencies/starknet/utils/calldata/index.js +280 -0
  144. package/js/src/static_dependencies/starknet/utils/calldata/parser/index.d.ts +5 -0
  145. package/js/src/static_dependencies/starknet/utils/calldata/parser/index.js +30 -0
  146. package/js/src/static_dependencies/starknet/utils/calldata/parser/interface.d.ts +20 -0
  147. package/js/src/static_dependencies/starknet/utils/calldata/parser/interface.js +8 -0
  148. package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-0-1.1.0.d.ts +24 -0
  149. package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-0-1.1.0.js +36 -0
  150. package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-2.0.0.d.ts +23 -0
  151. package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-2.0.0.js +40 -0
  152. package/js/src/static_dependencies/starknet/utils/calldata/propertyOrder.d.ts +2 -0
  153. package/js/src/static_dependencies/starknet/utils/calldata/propertyOrder.js +155 -0
  154. package/js/src/static_dependencies/starknet/utils/calldata/requestParser.d.ts +11 -0
  155. package/js/src/static_dependencies/starknet/utils/calldata/requestParser.js +248 -0
  156. package/js/src/static_dependencies/starknet/utils/calldata/responseParser.d.ts +11 -0
  157. package/js/src/static_dependencies/starknet/utils/calldata/responseParser.js +214 -0
  158. package/js/src/static_dependencies/starknet/utils/calldata/tuple.d.ts +6 -0
  159. package/js/src/static_dependencies/starknet/utils/calldata/tuple.js +113 -0
  160. package/js/src/static_dependencies/starknet/utils/calldata/validate.d.ts +6 -0
  161. package/js/src/static_dependencies/starknet/utils/calldata/validate.js +208 -0
  162. package/js/src/static_dependencies/starknet/utils/encode.d.ts +207 -0
  163. package/js/src/static_dependencies/starknet/utils/encode.js +282 -0
  164. package/js/src/static_dependencies/starknet/utils/hash/classHash.d.ts +57 -0
  165. package/js/src/static_dependencies/starknet/utils/hash/classHash.js +224 -0
  166. package/js/src/static_dependencies/starknet/utils/hash/index.d.ts +6 -0
  167. package/js/src/static_dependencies/starknet/utils/hash/index.js +13 -0
  168. package/js/src/static_dependencies/starknet/utils/json.d.ts +24 -0
  169. package/js/src/static_dependencies/starknet/utils/json.js +43 -0
  170. package/js/src/static_dependencies/starknet/utils/merkle.d.ts +35 -0
  171. package/js/src/static_dependencies/starknet/utils/merkle.js +84 -0
  172. package/js/src/static_dependencies/starknet/utils/num.d.ts +182 -0
  173. package/js/src/static_dependencies/starknet/utils/num.js +244 -0
  174. package/js/src/static_dependencies/starknet/utils/selector.d.ts +48 -0
  175. package/js/src/static_dependencies/starknet/utils/selector.js +85 -0
  176. package/js/src/static_dependencies/starknet/utils/shortString.d.ts +57 -0
  177. package/js/src/static_dependencies/starknet/utils/shortString.js +96 -0
  178. package/js/src/static_dependencies/starknet/utils/starknetId.d.ts +113 -0
  179. package/js/src/static_dependencies/starknet/utils/starknetId.js +265 -0
  180. package/js/src/static_dependencies/starknet/utils/typedData.d.ts +54 -0
  181. package/js/src/static_dependencies/starknet/utils/typedData.js +321 -0
  182. package/js/src/static_dependencies/starknet/utils/uint256.d.ts +21 -0
  183. package/js/src/static_dependencies/starknet/utils/uint256.js +32 -0
  184. package/js/src/static_dependencies/starknet/utils/url.d.ts +29 -0
  185. package/js/src/static_dependencies/starknet/utils/url.js +70 -0
  186. package/js/src/woo.js +4 -2
  187. package/package.json +1 -1
@@ -0,0 +1,265 @@
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 { StarknetChainId, ZERO } from '../constants.js';
8
+ import { tuple } from './calldata/cairo.js';
9
+ import { CairoCustomEnum } from './calldata/enum/CairoCustomEnum.js';
10
+ /* eslint-disable no-param-reassign */
11
+ const basicAlphabet = 'abcdefghijklmnopqrstuvwxyz0123456789-';
12
+ const basicSizePlusOne = BigInt(basicAlphabet.length + 1);
13
+ const bigAlphabet = '这来';
14
+ const basicAlphabetSize = BigInt(basicAlphabet.length);
15
+ const bigAlphabetSize = BigInt(bigAlphabet.length);
16
+ const bigAlphabetSizePlusOne = BigInt(bigAlphabet.length + 1);
17
+ function extractStars(str) {
18
+ let k = 0;
19
+ while (str.endsWith(bigAlphabet[bigAlphabet.length - 1])) {
20
+ str = str.substring(0, str.length - 1);
21
+ k += 1;
22
+ }
23
+ return [str, k];
24
+ }
25
+ /**
26
+ * Decodes an array of BigInts into a string using the given algorithm.
27
+ * @param {bigint[]} encoded - The encoded array of BigInts.
28
+ * @return {string} The decoded string.
29
+ */
30
+ export function useDecoded(encoded) {
31
+ let decoded = '';
32
+ encoded.forEach((subdomain) => {
33
+ while (subdomain !== ZERO) {
34
+ const code = subdomain % basicSizePlusOne;
35
+ subdomain /= basicSizePlusOne;
36
+ if (code === BigInt(basicAlphabet.length)) {
37
+ const nextSubdomain = subdomain / bigAlphabetSizePlusOne;
38
+ if (nextSubdomain === ZERO) {
39
+ const code2 = subdomain % bigAlphabetSizePlusOne;
40
+ subdomain = nextSubdomain;
41
+ if (code2 === ZERO)
42
+ decoded += basicAlphabet[0];
43
+ else
44
+ decoded += bigAlphabet[Number(code2) - 1];
45
+ }
46
+ else {
47
+ const code2 = subdomain % bigAlphabetSize;
48
+ decoded += bigAlphabet[Number(code2)];
49
+ subdomain /= bigAlphabetSize;
50
+ }
51
+ }
52
+ else
53
+ decoded += basicAlphabet[Number(code)];
54
+ }
55
+ const [str, k] = extractStars(decoded);
56
+ if (k)
57
+ decoded =
58
+ str +
59
+ (k % 2 === 0
60
+ ? bigAlphabet[bigAlphabet.length - 1].repeat(k / 2 - 1) +
61
+ bigAlphabet[0] +
62
+ basicAlphabet[1]
63
+ : bigAlphabet[bigAlphabet.length - 1].repeat((k - 1) / 2 + 1));
64
+ decoded += '.';
65
+ });
66
+ if (!decoded) {
67
+ return decoded;
68
+ }
69
+ return decoded.concat('stark');
70
+ }
71
+ /**
72
+ * Encodes a string into a bigint value.
73
+ *
74
+ * @param {string} decoded - The string to be encoded.
75
+ * @returns {bigint} - The encoded bigint value.
76
+ */
77
+ export function useEncoded(decoded) {
78
+ let encoded = BigInt(0);
79
+ let multiplier = BigInt(1);
80
+ if (decoded.endsWith(bigAlphabet[0] + basicAlphabet[1])) {
81
+ const [str, k] = extractStars(decoded.substring(0, decoded.length - 2));
82
+ decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(2 * (k + 1));
83
+ }
84
+ else {
85
+ const [str, k] = extractStars(decoded);
86
+ if (k)
87
+ decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(1 + 2 * (k - 1));
88
+ }
89
+ for (let i = 0; i < decoded.length; i += 1) {
90
+ const char = decoded[i];
91
+ const index = basicAlphabet.indexOf(char);
92
+ const bnIndex = BigInt(basicAlphabet.indexOf(char));
93
+ if (index !== -1) {
94
+ // add encoded + multiplier * index
95
+ if (i === decoded.length - 1 && decoded[i] === basicAlphabet[0]) {
96
+ encoded += multiplier * basicAlphabetSize;
97
+ multiplier *= basicSizePlusOne;
98
+ // add 0
99
+ multiplier *= basicSizePlusOne;
100
+ }
101
+ else {
102
+ encoded += multiplier * bnIndex;
103
+ multiplier *= basicSizePlusOne;
104
+ }
105
+ }
106
+ else if (bigAlphabet.indexOf(char) !== -1) {
107
+ // add encoded + multiplier * (basicAlphabetSize)
108
+ encoded += multiplier * basicAlphabetSize;
109
+ multiplier *= basicSizePlusOne;
110
+ // add encoded + multiplier * index
111
+ const newid = (i === decoded.length - 1 ? 1 : 0) + bigAlphabet.indexOf(char);
112
+ encoded += multiplier * BigInt(newid);
113
+ multiplier *= bigAlphabetSize;
114
+ }
115
+ }
116
+ return encoded;
117
+ }
118
+ /**
119
+ * Returns the Starknet ID contract address based on the provided chain ID.
120
+ *
121
+ * @param {StarknetChainId} chainId - The chain ID of the Starknet network.
122
+ * @return {string} The Starknet ID contract address.
123
+ * @throws {Error} Throws an error if the Starknet ID contract is not deployed on the network.
124
+ */
125
+ export function getStarknetIdContract(chainId) {
126
+ switch (chainId) {
127
+ case StarknetChainId.SN_MAIN:
128
+ return "0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678" /* StarknetIdContract.MAINNET */;
129
+ case StarknetChainId.SN_SEPOLIA:
130
+ return "0x0707f09bc576bd7cfee59694846291047e965f4184fe13dac62c56759b3b6fa7" /* StarknetIdContract.TESTNET_SEPOLIA */;
131
+ default:
132
+ throw new Error('Starknet.id is not yet deployed on this network');
133
+ }
134
+ }
135
+ /**
136
+ * Returns the Starknet ID identity contract address for the given chain ID.
137
+ *
138
+ * @param {StarknetChainId} chainId - The chain ID for the specified network.
139
+ *
140
+ * @return {string} - The Starknet ID identity contract address for the specified network.
141
+ *
142
+ * @throws {Error} - If the Starknet ID verifier contract is not deployed on the network.
143
+ */
144
+ export function getStarknetIdIdentityContract(chainId) {
145
+ switch (chainId) {
146
+ case StarknetChainId.SN_MAIN:
147
+ return "0x05dbdedc203e92749e2e746e2d40a768d966bd243df04a6b712e222bc040a9af" /* StarknetIdIdentityContract.MAINNET */;
148
+ case StarknetChainId.SN_SEPOLIA:
149
+ return "0x070DF8B4F5cb2879f8592849fA8f3134da39d25326B8558cc9C8FE8D47EA3A90" /* StarknetIdIdentityContract.TESTNET_SEPOLIA */;
150
+ default:
151
+ throw new Error('Starknet.id verifier contract is not yet deployed on this network');
152
+ }
153
+ }
154
+ export const StarknetIdMulticallContract = '0x034ffb8f4452df7a613a0210824d6414dbadcddce6c6e19bf4ddc9e22ce5f970';
155
+ /**
156
+ * Returns the Starknet.id multicall contract address based on the provided chainId.
157
+ *
158
+ * @param {StarknetChainId} chainId - The chainId of the network.
159
+ * @return {string} - The address of the Starknet.id multicall contract.
160
+ * @throws {Error} - If the Starknet.id multicall contract is not deployed on the network.
161
+ */
162
+ export function getStarknetIdMulticallContract(chainId) {
163
+ switch (chainId) {
164
+ case StarknetChainId.SN_MAIN:
165
+ return StarknetIdMulticallContract;
166
+ case StarknetChainId.SN_SEPOLIA:
167
+ return StarknetIdMulticallContract;
168
+ default:
169
+ throw new Error('Starknet.id multicall contract is not yet deployed on this network');
170
+ }
171
+ }
172
+ /**
173
+ * Returns the address of the Starknet ID Verifier contract based on the specified chain ID.
174
+ *
175
+ * @param {StarknetChainId} chainId - The ID of the Starknet chain.
176
+ * @return {string} - The address of the Starknet ID Verifier contract.
177
+ * @throws {Error} - If the Starknet ID Verifier contract is not deployed on the specified network.
178
+ */
179
+ export function getStarknetIdVerifierContract(chainId) {
180
+ switch (chainId) {
181
+ case StarknetChainId.SN_MAIN:
182
+ return "0x07d14dfd8ee95b41fce179170d88ba1f0d5a512e13aeb232f19cfeec0a88f8bf" /* StarknetIdVerifierContract.MAINNET */;
183
+ case StarknetChainId.SN_SEPOLIA:
184
+ return "0x0182EcE8173C216A395f4828e1523541b7e3600bf190CB252E1a1A0cE219d184" /* StarknetIdVerifierContract.TESTNET_SEPOLIA */;
185
+ default:
186
+ throw new Error('Starknet.id verifier contract is not yet deployed on this network');
187
+ }
188
+ }
189
+ /**
190
+ * Retrieves the contract address of the Starknet.id profile picture verifier contract based on the given chain ID.
191
+ *
192
+ * @param {StarknetChainId} chainId - The chain ID of the network.
193
+ * @returns {string} - The contract address of the Starknet.id profile picture verifier contract.
194
+ * @throws {Error} - Throws an error if the Starknet.id profile picture verifier contract is not yet deployed on the network.
195
+ */
196
+ export function getStarknetIdPfpContract(chainId) {
197
+ switch (chainId) {
198
+ case StarknetChainId.SN_MAIN:
199
+ return "0x070aaa20ec4a46da57c932d9fd89ca5e6bb9ca3188d3df361a32306aff7d59c7" /* StarknetIdPfpContract.MAINNET */;
200
+ case StarknetChainId.SN_SEPOLIA:
201
+ return "0x058061bb6bdc501eE215172c9f87d557C1E0f466dC498cA81b18f998Bf1362b2" /* StarknetIdPfpContract.TESTNET_SEPOLIA */;
202
+ default:
203
+ throw new Error('Starknet.id profile picture verifier contract is not yet deployed on this network');
204
+ }
205
+ }
206
+ /**
207
+ * Retrieves the Starknet ID Proof of Personhood (IdPop) verifier contract address for the given chain ID.
208
+ *
209
+ * @param {StarknetChainId} chainId - The chain ID of the Starknet network.
210
+ * @return {string} - The Starknet ID Pop contract address.
211
+ * @throws {Error} - If the Starknet ID Pop contract is not deployed on the specified network.
212
+ */
213
+ export function getStarknetIdPopContract(chainId) {
214
+ switch (chainId) {
215
+ case StarknetChainId.SN_MAIN:
216
+ return "0x0293eb2ba9862f762bd3036586d5755a782bd22e6f5028320f1d0405fd47bff4" /* StarknetIdPopContract.MAINNET */;
217
+ case StarknetChainId.SN_SEPOLIA:
218
+ return "0x0023FE3b845ed5665a9eb3792bbB17347B490EE4090f855C1298d03BB5F49B49" /* StarknetIdPopContract.TESTNET_SEPOLIA */;
219
+ default:
220
+ throw new Error('Starknet.id proof of personhood verifier contract is not yet deployed on this network');
221
+ }
222
+ }
223
+ /**
224
+ * Executes a method and returns a CairoCustomEnum object.
225
+ *
226
+ * Functions to build CairoCustomEnum for multicall contracts
227
+ * @param {Object} staticEx - An optional object defining the "Static" value of the CairoCustomEnum.
228
+ * @param {number[]} ifEqual - An optional array defining the "IfEqual" value of the CairoCustomEnum.
229
+ * @param {number[]} ifNotEqual - An optional array defining the "IfNotEqual" value of the CairoCustomEnum.
230
+ * @return {CairoCustomEnum} - The created CairoCustomEnum object.
231
+ */
232
+ export function execution(staticEx, ifEqual = undefined, ifNotEqual = undefined) {
233
+ return new CairoCustomEnum({
234
+ Static: staticEx,
235
+ IfEqual: ifEqual ? tuple(ifEqual[0], ifEqual[1], ifEqual[2]) : undefined,
236
+ IfNotEqual: ifNotEqual ? tuple(ifNotEqual[0], ifNotEqual[1], ifNotEqual[2]) : undefined,
237
+ });
238
+ }
239
+ /**
240
+ * Creates a new instance of CairoCustomEnum.
241
+ *
242
+ * @param {BigNumberish | undefined} hardcoded - The hardcoded value for the CairoCustomEnum.
243
+ * @param {number[] | undefined} reference - The reference array for the CairoCustomEnum.
244
+ * @returns {CairoCustomEnum} The new instance of CairoCustomEnum.
245
+ */
246
+ export function dynamicFelt(hardcoded, reference = undefined) {
247
+ return new CairoCustomEnum({
248
+ Hardcoded: hardcoded,
249
+ Reference: reference ? tuple(reference[0], reference[1]) : undefined,
250
+ });
251
+ }
252
+ /**
253
+ * Creates a new instance of CairoCustomEnum with the given parameters.
254
+ * @param {BigNumberish | undefined} hardcoded - The hardcoded value.
255
+ * @param {BigNumberish[] | undefined} [reference] - The reference value (optional).
256
+ * @param {BigNumberish[] | undefined} [arrayReference] - The array reference value (optional).
257
+ * @return {CairoCustomEnum} - The new instance of CairoCustomEnum.
258
+ */
259
+ export function dynamicCallData(hardcoded, reference = undefined, arrayReference = undefined) {
260
+ return new CairoCustomEnum({
261
+ Hardcoded: hardcoded,
262
+ Reference: reference ? tuple(reference[0], reference[1]) : undefined,
263
+ ArrayReference: arrayReference ? tuple(arrayReference[0], arrayReference[1]) : undefined,
264
+ });
265
+ }
@@ -0,0 +1,54 @@
1
+ import { BigNumberish, TypedDataRevision as Revision, StarknetMerkleType, StarknetType, TypedData } from '../types/index.js';
2
+ /** @deprecated prefer importing from 'types' over 'typedData' */
3
+ interface Context {
4
+ parent?: string;
5
+ key?: string;
6
+ }
7
+ /**
8
+ * Prepares the selector for use.
9
+ *
10
+ * @param {string} selector - The selector to be prepared.
11
+ * @returns {string} The prepared selector.
12
+ */
13
+ export declare function prepareSelector(selector: string): string;
14
+ /**
15
+ * Checks if the given Starknet type is a Merkle tree type.
16
+ *
17
+ * @param {StarknetType} type - The StarkNet type to check.
18
+ *
19
+ * @returns {boolean} - True if the type is a Merkle tree type, false otherwise.
20
+ */
21
+ export declare function isMerkleTreeType(type: StarknetType): type is StarknetMerkleType;
22
+ /**
23
+ * Get the dependencies of a struct type. If a struct has the same dependency multiple times, it's only included once
24
+ * in the resulting array.
25
+ */
26
+ export declare function getDependencies(types: TypedData['types'], type: string, dependencies?: string[], contains?: string, revision?: Revision): string[];
27
+ /**
28
+ * Encode a type to a string. All dependent types are alphabetically sorted.
29
+ */
30
+ export declare function encodeType(types: TypedData['types'], type: string, revision?: Revision): string;
31
+ /**
32
+ * Get a type string as hash.
33
+ */
34
+ export declare function getTypeHash(types: TypedData['types'], type: string, revision?: Revision): string;
35
+ /**
36
+ * Encodes a single value to an ABI serialisable string, number or Buffer. Returns the data as tuple, which consists of
37
+ * an array of ABI compatible types, and an array of corresponding values.
38
+ */
39
+ export declare function encodeValue(types: TypedData['types'], type: string, data: unknown, ctx?: Context, revision?: Revision): [string, string];
40
+ /**
41
+ * Encode the data to an ABI encoded Buffer. The data should be a key -> value object with all the required values.
42
+ * All dependent types are automatically encoded.
43
+ */
44
+ export declare function encodeData<T extends TypedData>(types: T['types'], type: string, data: T['message'], revision?: Revision): string[][];
45
+ /**
46
+ * Get encoded data as a hash. The data should be a key -> value object with all the required values.
47
+ * All dependent types are automatically encoded.
48
+ */
49
+ export declare function getStructHash<T extends TypedData>(types: T['types'], type: string, data: T['message'], revision?: Revision): string;
50
+ /**
51
+ * Get the SNIP-12 encoded message to sign, from the typedData object.
52
+ */
53
+ export declare function getMessageHash(typedData: TypedData, account: BigNumberish): string;
54
+ export {};
@@ -0,0 +1,321 @@
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-param-reassign */
8
+ import { PRIME, RANGE_FELT, RANGE_I128, RANGE_U128 } from '../constants.js';
9
+ import { TypedDataRevision as Revision, } from '../types/index.js';
10
+ import assert from './assert.js';
11
+ import { byteArrayFromString } from './calldata/byteArray.js';
12
+ import { computePedersenHash, computePedersenHashOnElements, computePoseidonHash, computePoseidonHashOnElements, getSelectorFromName, } from './hash/index.js';
13
+ import { MerkleTree } from './merkle.js';
14
+ import { isHex, toHex } from './num.js';
15
+ import { encodeShortString, isString } from './shortString.js';
16
+ const presetTypes = {
17
+ u256: JSON.parse('[{ "name": "low", "type": "u128" }, { "name": "high", "type": "u128" }]'),
18
+ TokenAmount: JSON.parse('[{ "name": "token_address", "type": "ContractAddress" }, { "name": "amount", "type": "u256" }]'),
19
+ NftId: JSON.parse('[{ "name": "collection_address", "type": "ContractAddress" }, { "name": "token_id", "type": "u256" }]'),
20
+ };
21
+ const revisionConfiguration = {
22
+ [Revision.Active]: {
23
+ domain: 'StarknetDomain',
24
+ hashMethod: computePoseidonHashOnElements,
25
+ hashMerkleMethod: computePoseidonHash,
26
+ escapeTypeString: (s) => `"${s}"`,
27
+ presetTypes,
28
+ },
29
+ [Revision.Legacy]: {
30
+ domain: 'StarkNetDomain',
31
+ hashMethod: computePedersenHashOnElements,
32
+ hashMerkleMethod: computePedersenHash,
33
+ escapeTypeString: (s) => s,
34
+ presetTypes: {},
35
+ },
36
+ };
37
+ function assertRange(data, type, { min, max }) {
38
+ const value = BigInt(data);
39
+ assert(value >= min && value <= max, `${value} (${type}) is out of bounds [${min}, ${max}]`);
40
+ }
41
+ function identifyRevision({ types, domain }) {
42
+ if (revisionConfiguration[Revision.Active].domain in types && domain.revision === Revision.Active)
43
+ return Revision.Active;
44
+ if (revisionConfiguration[Revision.Legacy].domain in types &&
45
+ (domain.revision ?? Revision.Legacy) === Revision.Legacy)
46
+ return Revision.Legacy;
47
+ return undefined;
48
+ }
49
+ function getHex(value) {
50
+ try {
51
+ return toHex(value);
52
+ }
53
+ catch (e) {
54
+ if (isString(value)) {
55
+ return toHex(encodeShortString(value));
56
+ }
57
+ throw new Error(`Invalid BigNumberish: ${value}`);
58
+ }
59
+ }
60
+ /**
61
+ * Validates that `data` matches the EIP-712 JSON schema.
62
+ */
63
+ function validateTypedData(data) {
64
+ const typedData = data;
65
+ return Boolean(typedData.message && typedData.primaryType && typedData.types && identifyRevision(typedData));
66
+ }
67
+ /**
68
+ * Prepares the selector for use.
69
+ *
70
+ * @param {string} selector - The selector to be prepared.
71
+ * @returns {string} The prepared selector.
72
+ */
73
+ export function prepareSelector(selector) {
74
+ return isHex(selector) ? selector : getSelectorFromName(selector);
75
+ }
76
+ /**
77
+ * Checks if the given Starknet type is a Merkle tree type.
78
+ *
79
+ * @param {StarknetType} type - The StarkNet type to check.
80
+ *
81
+ * @returns {boolean} - True if the type is a Merkle tree type, false otherwise.
82
+ */
83
+ export function isMerkleTreeType(type) {
84
+ return type.type === 'merkletree';
85
+ }
86
+ /**
87
+ * Get the dependencies of a struct type. If a struct has the same dependency multiple times, it's only included once
88
+ * in the resulting array.
89
+ */
90
+ export function getDependencies(types, type, dependencies = [], contains = '', revision = Revision.Legacy) {
91
+ // Include pointers (struct arrays)
92
+ if (type[type.length - 1] === '*') {
93
+ type = type.slice(0, -1);
94
+ }
95
+ else if (revision === Revision.Active) {
96
+ // enum base
97
+ if (type === 'enum') {
98
+ type = contains;
99
+ }
100
+ // enum element types
101
+ else if (type.match(/^\(.*\)$/)) {
102
+ type = type.slice(1, -1);
103
+ }
104
+ }
105
+ if (dependencies.includes(type) || !types[type]) {
106
+ return dependencies;
107
+ }
108
+ return [
109
+ type,
110
+ ...types[type].reduce((previous, t) => [
111
+ ...previous,
112
+ ...getDependencies(types, t.type, previous, t.contains, revision).filter((dependency) => !previous.includes(dependency)),
113
+ ], []),
114
+ ];
115
+ }
116
+ function getMerkleTreeType(types, ctx) {
117
+ if (ctx.parent && ctx.key) {
118
+ const parentType = types[ctx.parent];
119
+ const merkleType = parentType.find((t) => t.name === ctx.key);
120
+ const isMerkleTree = isMerkleTreeType(merkleType);
121
+ if (!isMerkleTree) {
122
+ throw new Error(`${ctx.key} is not a merkle tree`);
123
+ }
124
+ if (merkleType.contains.endsWith('*')) {
125
+ throw new Error(`Merkle tree contain property must not be an array but was given ${ctx.key}`);
126
+ }
127
+ return merkleType.contains;
128
+ }
129
+ return 'raw';
130
+ }
131
+ /**
132
+ * Encode a type to a string. All dependent types are alphabetically sorted.
133
+ */
134
+ export function encodeType(types, type, revision = Revision.Legacy) {
135
+ const allTypes = revision === Revision.Active
136
+ ? { ...types, ...revisionConfiguration[revision].presetTypes }
137
+ : types;
138
+ const [primary, ...dependencies] = getDependencies(allTypes, type, undefined, undefined, revision);
139
+ const newTypes = !primary ? [] : [primary, ...dependencies.sort()];
140
+ const esc = revisionConfiguration[revision].escapeTypeString;
141
+ return newTypes
142
+ .map((dependency) => {
143
+ const dependencyElements = allTypes[dependency].map((t) => {
144
+ const targetType = t.type === 'enum' && revision === Revision.Active
145
+ ? t.contains
146
+ : t.type;
147
+ // parentheses handling for enum variant types
148
+ const typeString = targetType.match(/^\(.*\)$/)
149
+ ? `(${targetType
150
+ .slice(1, -1)
151
+ .split(',')
152
+ .map((e) => (e ? esc(e) : e))
153
+ .join(',')})`
154
+ : esc(targetType);
155
+ return `${esc(t.name)}:${typeString}`;
156
+ });
157
+ return `${esc(dependency)}(${dependencyElements})`;
158
+ })
159
+ .join('');
160
+ }
161
+ /**
162
+ * Get a type string as hash.
163
+ */
164
+ export function getTypeHash(types, type, revision = Revision.Legacy) {
165
+ return getSelectorFromName(encodeType(types, type, revision));
166
+ }
167
+ /**
168
+ * Encodes a single value to an ABI serialisable string, number or Buffer. Returns the data as tuple, which consists of
169
+ * an array of ABI compatible types, and an array of corresponding values.
170
+ */
171
+ export function encodeValue(types, type, data, ctx = {}, revision = Revision.Legacy) {
172
+ if (types[type]) {
173
+ return [type, getStructHash(types, type, data, revision)];
174
+ }
175
+ if (revisionConfiguration[revision].presetTypes[type]) {
176
+ return [
177
+ type,
178
+ getStructHash(revisionConfiguration[revision].presetTypes, type, data, revision),
179
+ ];
180
+ }
181
+ if (type.endsWith('*')) {
182
+ const hashes = data.map((entry) => encodeValue(types, type.slice(0, -1), entry, undefined, revision)[1]);
183
+ return [type, revisionConfiguration[revision].hashMethod(hashes)];
184
+ }
185
+ switch (type) {
186
+ case 'enum': {
187
+ if (revision === Revision.Active) {
188
+ const [variantKey, variantData] = Object.entries(data)[0];
189
+ const parentType = types[ctx.parent][0];
190
+ const enumType = types[parentType.contains];
191
+ const variantType = enumType.find((t) => t.name === variantKey);
192
+ const variantIndex = enumType.indexOf(variantType);
193
+ const encodedSubtypes = variantType.type
194
+ .slice(1, -1)
195
+ .split(',')
196
+ .map((subtype, index) => {
197
+ if (!subtype)
198
+ return subtype;
199
+ const subtypeData = variantData[index];
200
+ return encodeValue(types, subtype, subtypeData, undefined, revision)[1];
201
+ });
202
+ return [
203
+ type,
204
+ revisionConfiguration[revision].hashMethod([variantIndex, ...encodedSubtypes]),
205
+ ];
206
+ } // else fall through to default
207
+ return [type, getHex(data)];
208
+ }
209
+ case 'merkletree': {
210
+ const merkleTreeType = getMerkleTreeType(types, ctx);
211
+ const structHashes = data.map((struct) => {
212
+ return encodeValue(types, merkleTreeType, struct, undefined, revision)[1];
213
+ });
214
+ const { root } = new MerkleTree(structHashes, revisionConfiguration[revision].hashMerkleMethod);
215
+ return ['felt', root];
216
+ }
217
+ case 'selector': {
218
+ return ['felt', prepareSelector(data)];
219
+ }
220
+ case 'string': {
221
+ if (revision === Revision.Active) {
222
+ const byteArray = byteArrayFromString(data);
223
+ const elements = [
224
+ byteArray.data.length,
225
+ ...byteArray.data,
226
+ byteArray.pending_word,
227
+ byteArray.pending_word_len,
228
+ ];
229
+ return [type, revisionConfiguration[revision].hashMethod(elements)];
230
+ } // else fall through to default
231
+ return [type, getHex(data)];
232
+ }
233
+ case 'i128': {
234
+ if (revision === Revision.Active) {
235
+ const value = BigInt(data);
236
+ assertRange(value, type, RANGE_I128);
237
+ return [type, getHex(value < 0n ? PRIME + value : value)];
238
+ } // else fall through to default
239
+ return [type, getHex(data)];
240
+ }
241
+ case 'timestamp':
242
+ case 'u128': {
243
+ if (revision === Revision.Active) {
244
+ assertRange(data, type, RANGE_U128);
245
+ } // else fall through to default
246
+ return [type, getHex(data)];
247
+ }
248
+ case 'felt':
249
+ case 'shortstring': {
250
+ // TODO: should 'shortstring' diverge into directly using encodeShortString()?
251
+ if (revision === Revision.Active) {
252
+ assertRange(getHex(data), type, RANGE_FELT);
253
+ } // else fall through to default
254
+ return [type, getHex(data)];
255
+ }
256
+ case 'ClassHash':
257
+ case 'ContractAddress': {
258
+ if (revision === Revision.Active) {
259
+ assertRange(data, type, RANGE_FELT);
260
+ } // else fall through to default
261
+ return [type, getHex(data)];
262
+ }
263
+ case 'bool': {
264
+ if (revision === Revision.Active) {
265
+ assert(typeof data === 'boolean', `Type mismatch for ${type} ${data}`);
266
+ } // else fall through to default
267
+ return [type, getHex(data)];
268
+ }
269
+ default: {
270
+ if (revision === Revision.Active) {
271
+ throw new Error(`Unsupported type: ${type}`);
272
+ }
273
+ return [type, getHex(data)];
274
+ }
275
+ }
276
+ }
277
+ /**
278
+ * Encode the data to an ABI encoded Buffer. The data should be a key -> value object with all the required values.
279
+ * All dependent types are automatically encoded.
280
+ */
281
+ export function encodeData(types, type, data, revision = Revision.Legacy) {
282
+ const targetType = types[type] ?? revisionConfiguration[revision].presetTypes[type];
283
+ const [returnTypes, values] = targetType.reduce(([ts, vs], field) => {
284
+ if (data[field.name] === undefined ||
285
+ (data[field.name] === null && field.type !== 'enum')) {
286
+ throw new Error(`Cannot encode data: missing data for '${field.name}'`);
287
+ }
288
+ const value = data[field.name];
289
+ const ctx = { parent: type, key: field.name };
290
+ const [t, encodedValue] = encodeValue(types, field.type, value, ctx, revision);
291
+ return [
292
+ [...ts, t],
293
+ [...vs, encodedValue],
294
+ ];
295
+ }, [['felt'], [getTypeHash(types, type, revision)]]);
296
+ return [returnTypes, values];
297
+ }
298
+ /**
299
+ * Get encoded data as a hash. The data should be a key -> value object with all the required values.
300
+ * All dependent types are automatically encoded.
301
+ */
302
+ export function getStructHash(types, type, data, revision = Revision.Legacy) {
303
+ return revisionConfiguration[revision].hashMethod(encodeData(types, type, data, revision)[1]);
304
+ }
305
+ /**
306
+ * Get the SNIP-12 encoded message to sign, from the typedData object.
307
+ */
308
+ export function getMessageHash(typedData, account) {
309
+ if (!validateTypedData(typedData)) {
310
+ throw new Error('Typed data does not match JSON schema');
311
+ }
312
+ const revision = identifyRevision(typedData);
313
+ const { domain, hashMethod } = revisionConfiguration[revision];
314
+ const message = [
315
+ encodeShortString('StarkNet Message'),
316
+ getStructHash(typedData.types, domain, typedData.domain, revision),
317
+ account,
318
+ getStructHash(typedData.types, typedData.primaryType, typedData.message, revision),
319
+ ];
320
+ return hashMethod(message);
321
+ }
@@ -0,0 +1,21 @@
1
+ import { BigNumberish, Uint256 } from '../types/index.js';
2
+ import { UINT_128_MAX, UINT_256_MAX } from './cairoDataTypes/uint256.js';
3
+ /**
4
+ * @deprecated Legacy support Export
5
+ */
6
+ export { UINT_128_MAX, UINT_256_MAX };
7
+ /**
8
+ * Convert Uint256 to bigint
9
+ * Legacy support Export
10
+ */
11
+ export declare function uint256ToBN(uint256: Uint256): bigint;
12
+ /**
13
+ * Test BigNumberish is smaller or equal 2**256-1
14
+ * Legacy support Export
15
+ */
16
+ export declare function isUint256(bn: BigNumberish): boolean;
17
+ /**
18
+ * Convert BigNumberish (string | number | bigint) to Uint256 (hex)
19
+ * Legacy support Export
20
+ */
21
+ export declare function bnToUint256(bn: BigNumberish): Uint256;