starknet 6.9.0 → 6.10.1

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 (315) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +1 -1
  3. package/README.md +5 -9
  4. package/dist/account/default.cjs +655 -0
  5. package/dist/account/default.d.ts +67 -0
  6. package/dist/account/default.mjs +652 -0
  7. package/dist/account/index.cjs +27 -0
  8. package/dist/account/index.d.ts +2 -0
  9. package/dist/account/index.mjs +2 -0
  10. package/dist/account/interface.cjs +9 -0
  11. package/dist/account/interface.d.ts +301 -0
  12. package/dist/account/interface.mjs +3 -0
  13. package/dist/channel/index.cjs +27 -0
  14. package/dist/channel/index.d.ts +3 -0
  15. package/dist/channel/index.mjs +3 -0
  16. package/dist/channel/rpc_0_6.cjs +607 -0
  17. package/dist/channel/rpc_0_6.d.ts +78 -0
  18. package/dist/channel/rpc_0_6.mjs +543 -0
  19. package/dist/channel/rpc_0_7.cjs +619 -0
  20. package/dist/channel/rpc_0_7.d.ts +81 -0
  21. package/dist/channel/rpc_0_7.mjs +561 -0
  22. package/dist/constants.cjs +76 -0
  23. package/dist/constants.d.ts +70 -0
  24. package/dist/constants.mjs +60 -0
  25. package/dist/contract/contractFactory.cjs +93 -0
  26. package/dist/contract/contractFactory.d.ts +46 -0
  27. package/dist/contract/contractFactory.mjs +83 -0
  28. package/dist/contract/default.cjs +269 -0
  29. package/dist/contract/default.d.ts +58 -0
  30. package/dist/contract/default.mjs +254 -0
  31. package/dist/contract/index.cjs +38 -0
  32. package/dist/contract/index.d.ts +3 -0
  33. package/dist/contract/index.mjs +3 -0
  34. package/dist/contract/interface.cjs +13 -0
  35. package/dist/contract/interface.d.ts +128 -0
  36. package/dist/contract/interface.mjs +6 -0
  37. package/dist/index.cjs +267 -0
  38. package/dist/index.d.ts +45 -5991
  39. package/dist/index.global.js +728 -609
  40. package/dist/index.global.js.map +1 -1
  41. package/dist/index.mjs +39 -7320
  42. package/dist/provider/errors.cjs +50 -0
  43. package/dist/provider/errors.d.ts +16 -0
  44. package/dist/provider/errors.mjs +35 -0
  45. package/dist/provider/extensions/default.cjs +11 -0
  46. package/dist/provider/extensions/default.d.ts +6 -0
  47. package/dist/provider/extensions/default.mjs +5 -0
  48. package/dist/provider/extensions/starknetId.cjs +174 -0
  49. package/dist/provider/extensions/starknetId.d.ts +10 -0
  50. package/dist/provider/extensions/starknetId.mjs +230 -0
  51. package/dist/provider/index.cjs +56 -0
  52. package/dist/provider/index.d.ts +6 -0
  53. package/dist/provider/index.mjs +6 -0
  54. package/dist/provider/interface.cjs +8 -0
  55. package/dist/provider/interface.d.ts +261 -0
  56. package/dist/provider/interface.mjs +2 -0
  57. package/dist/provider/rpc.cjs +301 -0
  58. package/dist/provider/rpc.d.ts +115 -0
  59. package/dist/provider/rpc.mjs +302 -0
  60. package/dist/service/types.cjs +1 -0
  61. package/dist/service/types.d.ts +5 -0
  62. package/dist/service/types.mjs +0 -0
  63. package/dist/signer/default.cjs +105 -0
  64. package/dist/signer/default.d.ts +12 -0
  65. package/dist/signer/default.mjs +102 -0
  66. package/dist/signer/ethSigner.cjs +123 -0
  67. package/dist/signer/ethSigner.d.ts +25 -0
  68. package/dist/signer/ethSigner.mjs +140 -0
  69. package/dist/signer/index.cjs +38 -0
  70. package/dist/signer/index.d.ts +3 -0
  71. package/dist/signer/index.mjs +3 -0
  72. package/dist/signer/interface.cjs +8 -0
  73. package/dist/signer/interface.d.ts +115 -0
  74. package/dist/signer/interface.mjs +2 -0
  75. package/dist/types/account.cjs +1 -0
  76. package/dist/types/account.d.ts +79 -0
  77. package/dist/types/account.mjs +0 -0
  78. package/dist/types/api/index.cjs +30 -0
  79. package/dist/types/api/index.d.ts +4 -0
  80. package/dist/types/api/index.mjs +4 -0
  81. package/dist/types/api/jsonrpc/index.cjs +1 -0
  82. package/dist/types/api/jsonrpc/index.d.ts +21 -0
  83. package/dist/types/api/jsonrpc/index.mjs +0 -0
  84. package/dist/types/api/rpcspec_0_6/components.cjs +1 -0
  85. package/dist/types/api/rpcspec_0_6/components.d.ts +541 -0
  86. package/dist/types/api/rpcspec_0_6/components.mjs +0 -0
  87. package/dist/types/api/rpcspec_0_6/contract.cjs +1 -0
  88. package/dist/types/api/rpcspec_0_6/contract.d.ts +85 -0
  89. package/dist/types/api/rpcspec_0_6/contract.mjs +0 -0
  90. package/dist/types/api/rpcspec_0_6/errors.cjs +1 -0
  91. package/dist/types/api/rpcspec_0_6/errors.d.ts +128 -0
  92. package/dist/types/api/rpcspec_0_6/errors.mjs +0 -0
  93. package/dist/types/api/rpcspec_0_6/index.cjs +45 -0
  94. package/dist/types/api/rpcspec_0_6/index.d.ts +8 -0
  95. package/dist/types/api/rpcspec_0_6/index.mjs +5 -0
  96. package/dist/types/api/rpcspec_0_6/methods.cjs +1 -0
  97. package/dist/types/api/rpcspec_0_6/methods.d.ts +207 -0
  98. package/dist/types/api/rpcspec_0_6/methods.mjs +0 -0
  99. package/dist/types/api/rpcspec_0_6/nonspec.cjs +65 -0
  100. package/dist/types/api/rpcspec_0_6/nonspec.d.ts +147 -0
  101. package/dist/types/api/rpcspec_0_6/nonspec.mjs +59 -0
  102. package/dist/types/cairoEnum.cjs +1 -0
  103. package/dist/types/cairoEnum.d.ts +2 -0
  104. package/dist/types/cairoEnum.mjs +0 -0
  105. package/dist/types/calldata.cjs +27 -0
  106. package/dist/types/calldata.d.ts +23 -0
  107. package/dist/types/calldata.mjs +21 -0
  108. package/dist/types/contract.cjs +1 -0
  109. package/dist/types/contract.d.ts +27 -0
  110. package/dist/types/contract.mjs +0 -0
  111. package/dist/types/helpers/valuesType.cjs +1 -0
  112. package/dist/types/helpers/valuesType.d.ts +1 -0
  113. package/dist/types/helpers/valuesType.mjs +0 -0
  114. package/dist/types/index.cjs +121 -0
  115. package/dist/types/index.d.ts +10 -0
  116. package/dist/types/index.mjs +10 -0
  117. package/dist/types/lib/contract/abi.cjs +1 -0
  118. package/dist/types/lib/contract/abi.d.ts +71 -0
  119. package/dist/types/lib/contract/abi.mjs +0 -0
  120. package/dist/types/lib/contract/index.cjs +50 -0
  121. package/dist/types/lib/contract/index.d.ts +26 -0
  122. package/dist/types/lib/contract/index.mjs +8 -0
  123. package/dist/types/lib/contract/legacy.cjs +1 -0
  124. package/dist/types/lib/contract/legacy.d.ts +33 -0
  125. package/dist/types/lib/contract/legacy.mjs +0 -0
  126. package/dist/types/lib/contract/sierra.cjs +1 -0
  127. package/dist/types/lib/contract/sierra.d.ts +52 -0
  128. package/dist/types/lib/contract/sierra.mjs +0 -0
  129. package/dist/types/lib/index.cjs +61 -0
  130. package/dist/types/lib/index.d.ts +259 -0
  131. package/dist/types/lib/index.mjs +36 -0
  132. package/dist/types/provider/configuration.cjs +1 -0
  133. package/dist/types/provider/configuration.d.ts +20 -0
  134. package/dist/types/provider/configuration.mjs +0 -0
  135. package/dist/types/provider/index.cjs +27 -0
  136. package/dist/types/provider/index.d.ts +2 -0
  137. package/dist/types/provider/index.mjs +2 -0
  138. package/dist/types/provider/response.cjs +30 -0
  139. package/dist/types/provider/response.d.ts +98 -0
  140. package/dist/types/provider/response.mjs +1 -0
  141. package/dist/types/provider/spec.cjs +1 -0
  142. package/dist/types/provider/spec.d.ts +49 -0
  143. package/dist/types/provider/spec.mjs +0 -0
  144. package/dist/types/signer.cjs +1 -0
  145. package/dist/types/signer.d.ts +49 -0
  146. package/dist/types/signer.mjs +0 -0
  147. package/dist/types/transactionReceipt.cjs +1 -0
  148. package/dist/types/transactionReceipt.d.ts +23 -0
  149. package/dist/types/transactionReceipt.mjs +0 -0
  150. package/dist/types/typedData.cjs +12 -0
  151. package/dist/types/typedData.d.ts +1 -0
  152. package/dist/types/typedData.mjs +3 -0
  153. package/dist/utils/address.cjs +44 -0
  154. package/dist/utils/address.d.ts +55 -0
  155. package/dist/utils/address.mjs +35 -0
  156. package/dist/utils/assert.cjs +11 -0
  157. package/dist/utils/assert.d.ts +12 -0
  158. package/dist/utils/assert.mjs +5 -0
  159. package/dist/utils/cairoDataTypes/felt.cjs +31 -0
  160. package/dist/utils/cairoDataTypes/felt.d.ts +6 -0
  161. package/dist/utils/cairoDataTypes/felt.mjs +27 -0
  162. package/dist/utils/cairoDataTypes/uint256.cjs +113 -0
  163. package/dist/utils/cairoDataTypes/uint256.d.ts +72 -0
  164. package/dist/utils/cairoDataTypes/uint256.mjs +103 -0
  165. package/dist/utils/cairoDataTypes/uint512.cjs +125 -0
  166. package/dist/utils/cairoDataTypes/uint512.d.ts +76 -0
  167. package/dist/utils/cairoDataTypes/uint512.mjs +123 -0
  168. package/dist/utils/calldata/byteArray.cjs +27 -0
  169. package/dist/utils/calldata/byteArray.d.ts +32 -0
  170. package/dist/utils/calldata/byteArray.mjs +20 -0
  171. package/dist/utils/calldata/cairo.cjs +114 -0
  172. package/dist/utils/calldata/cairo.d.ts +196 -0
  173. package/dist/utils/calldata/cairo.mjs +68 -0
  174. package/dist/utils/calldata/enum/CairoCustomEnum.cjs +55 -0
  175. package/dist/utils/calldata/enum/CairoCustomEnum.d.ts +38 -0
  176. package/dist/utils/calldata/enum/CairoCustomEnum.mjs +50 -0
  177. package/dist/utils/calldata/enum/CairoOption.cjs +55 -0
  178. package/dist/utils/calldata/enum/CairoOption.d.ts +37 -0
  179. package/dist/utils/calldata/enum/CairoOption.mjs +50 -0
  180. package/dist/utils/calldata/enum/CairoResult.cjs +54 -0
  181. package/dist/utils/calldata/enum/CairoResult.d.ts +36 -0
  182. package/dist/utils/calldata/enum/CairoResult.mjs +47 -0
  183. package/dist/utils/calldata/enum/index.cjs +38 -0
  184. package/dist/utils/calldata/enum/index.d.ts +3 -0
  185. package/dist/utils/calldata/enum/index.mjs +3 -0
  186. package/dist/utils/calldata/formatter.cjs +55 -0
  187. package/dist/utils/calldata/formatter.d.ts +9 -0
  188. package/dist/utils/calldata/formatter.mjs +58 -0
  189. package/dist/utils/calldata/index.cjs +272 -0
  190. package/dist/utils/calldata/index.d.ts +90 -0
  191. package/dist/utils/calldata/index.mjs +276 -0
  192. package/dist/utils/calldata/parser/index.cjs +29 -0
  193. package/dist/utils/calldata/parser/index.d.ts +5 -0
  194. package/dist/utils/calldata/parser/index.mjs +21 -0
  195. package/dist/utils/calldata/parser/interface.cjs +8 -0
  196. package/dist/utils/calldata/parser/interface.d.ts +20 -0
  197. package/dist/utils/calldata/parser/interface.mjs +2 -0
  198. package/dist/utils/calldata/parser/parser-0-1.1.0.cjs +38 -0
  199. package/dist/utils/calldata/parser/parser-0-1.1.0.d.ts +24 -0
  200. package/dist/utils/calldata/parser/parser-0-1.1.0.mjs +31 -0
  201. package/dist/utils/calldata/parser/parser-2.0.0.cjs +42 -0
  202. package/dist/utils/calldata/parser/parser-2.0.0.d.ts +23 -0
  203. package/dist/utils/calldata/parser/parser-2.0.0.mjs +37 -0
  204. package/dist/utils/calldata/propertyOrder.cjs +159 -0
  205. package/dist/utils/calldata/propertyOrder.d.ts +2 -0
  206. package/dist/utils/calldata/propertyOrder.mjs +189 -0
  207. package/dist/utils/calldata/requestParser.cjs +204 -0
  208. package/dist/utils/calldata/requestParser.d.ts +11 -0
  209. package/dist/utils/calldata/requestParser.mjs +231 -0
  210. package/dist/utils/calldata/responseParser.cjs +200 -0
  211. package/dist/utils/calldata/responseParser.d.ts +11 -0
  212. package/dist/utils/calldata/responseParser.mjs +201 -0
  213. package/dist/utils/calldata/tuple.cjs +106 -0
  214. package/dist/utils/calldata/tuple.d.ts +6 -0
  215. package/dist/utils/calldata/tuple.mjs +88 -0
  216. package/dist/utils/calldata/validate.cjs +241 -0
  217. package/dist/utils/calldata/validate.d.ts +6 -0
  218. package/dist/utils/calldata/validate.mjs +315 -0
  219. package/dist/utils/contract.cjs +40 -0
  220. package/dist/utils/contract.d.ts +37 -0
  221. package/dist/utils/contract.mjs +31 -0
  222. package/dist/utils/ec.cjs +12 -0
  223. package/dist/utils/ec.d.ts +2 -0
  224. package/dist/utils/ec.mjs +2 -0
  225. package/dist/utils/encode.cjs +78 -0
  226. package/dist/utils/encode.d.ts +207 -0
  227. package/dist/utils/encode.mjs +56 -0
  228. package/dist/utils/eth.cjs +22 -0
  229. package/dist/utils/eth.d.ts +22 -0
  230. package/dist/utils/eth.mjs +14 -0
  231. package/dist/utils/events/index.cjs +144 -0
  232. package/dist/utils/events/index.d.ts +84 -0
  233. package/dist/utils/events/index.mjs +136 -0
  234. package/dist/utils/fetchPonyfill.cjs +14 -0
  235. package/dist/utils/fetchPonyfill.d.ts +2 -0
  236. package/dist/utils/fetchPonyfill.mjs +5 -0
  237. package/dist/utils/hash/classHash.cjs +151 -0
  238. package/dist/utils/hash/classHash.d.ts +120 -0
  239. package/dist/utils/hash/classHash.mjs +168 -0
  240. package/dist/utils/hash/index.cjs +49 -0
  241. package/dist/utils/hash/index.d.ts +7 -0
  242. package/dist/utils/hash/index.mjs +4 -0
  243. package/dist/utils/hash/selector.cjs +37 -0
  244. package/dist/utils/hash/selector.d.ts +57 -0
  245. package/dist/utils/hash/selector.mjs +28 -0
  246. package/dist/utils/hash/transactionHash/index.cjs +38 -0
  247. package/dist/utils/hash/transactionHash/index.d.ts +81 -0
  248. package/dist/utils/hash/transactionHash/index.mjs +102 -0
  249. package/dist/utils/hash/transactionHash/v2.cjs +31 -0
  250. package/dist/utils/hash/transactionHash/v2.d.ts +34 -0
  251. package/dist/utils/hash/transactionHash/v2.mjs +57 -0
  252. package/dist/utils/hash/transactionHash/v3.cjs +45 -0
  253. package/dist/utils/hash/transactionHash/v3.d.ts +24 -0
  254. package/dist/utils/hash/transactionHash/v3.mjs +80 -0
  255. package/dist/utils/json.cjs +21 -0
  256. package/dist/utils/json.d.ts +50 -0
  257. package/dist/utils/json.mjs +10 -0
  258. package/dist/utils/merkle.cjs +118 -0
  259. package/dist/utils/merkle.d.ts +87 -0
  260. package/dist/utils/merkle.mjs +114 -0
  261. package/dist/utils/num.cjs +109 -0
  262. package/dist/utils/num.d.ts +283 -0
  263. package/dist/utils/num.mjs +86 -0
  264. package/dist/utils/provider.cjs +182 -0
  265. package/dist/utils/provider.d.ts +217 -0
  266. package/dist/utils/provider.mjs +158 -0
  267. package/dist/utils/responseParser/index.cjs +27 -0
  268. package/dist/utils/responseParser/index.d.ts +2 -0
  269. package/dist/utils/responseParser/index.mjs +2 -0
  270. package/dist/utils/responseParser/interface.cjs +8 -0
  271. package/dist/utils/responseParser/interface.d.ts +13 -0
  272. package/dist/utils/responseParser/interface.mjs +2 -0
  273. package/dist/utils/responseParser/rpc.cjs +83 -0
  274. package/dist/utils/responseParser/rpc.d.ts +19 -0
  275. package/dist/utils/responseParser/rpc.mjs +77 -0
  276. package/dist/utils/shortString.cjs +56 -0
  277. package/dist/utils/shortString.d.ts +116 -0
  278. package/dist/utils/shortString.mjs +39 -0
  279. package/dist/utils/stark.cjs +137 -0
  280. package/dist/utils/stark.d.ts +224 -0
  281. package/dist/utils/stark.mjs +109 -0
  282. package/dist/utils/starknetId.cjs +196 -0
  283. package/dist/utils/starknetId.d.ts +182 -0
  284. package/dist/utils/starknetId.mjs +185 -0
  285. package/dist/utils/transaction.cjs +115 -0
  286. package/dist/utils/transaction.d.ts +185 -0
  287. package/dist/utils/transaction.mjs +98 -0
  288. package/dist/utils/transactionReceipt.cjs +54 -0
  289. package/dist/utils/transactionReceipt.d.ts +33 -0
  290. package/dist/utils/transactionReceipt.mjs +49 -0
  291. package/dist/utils/typedData.cjs +285 -0
  292. package/dist/utils/typedData.d.ts +54 -0
  293. package/dist/utils/typedData.mjs +286 -0
  294. package/dist/utils/uint256.cjs +30 -0
  295. package/dist/utils/uint256.d.ts +45 -0
  296. package/dist/utils/uint256.mjs +11 -0
  297. package/dist/utils/url.cjs +35 -0
  298. package/dist/utils/url.d.ts +29 -0
  299. package/dist/utils/url.mjs +27 -0
  300. package/dist/wallet/account.cjs +115 -0
  301. package/dist/wallet/account.d.ts +31 -0
  302. package/dist/wallet/account.mjs +112 -0
  303. package/dist/wallet/connect.cjs +90 -0
  304. package/dist/wallet/connect.d.ts +82 -0
  305. package/dist/wallet/connect.mjs +64 -0
  306. package/dist/wallet/index.cjs +16 -0
  307. package/dist/wallet/index.d.ts +1 -0
  308. package/dist/wallet/index.mjs +1 -0
  309. package/dist/wallet/types.cjs +1 -0
  310. package/dist/wallet/types.d.ts +4 -0
  311. package/dist/wallet/types.mjs +0 -0
  312. package/package.json +13 -13
  313. package/dist/index.js +0 -7426
  314. package/dist/index.js.map +0 -1
  315. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,283 @@
1
+ import { BigNumberish } from '../types';
2
+ /** @deprecated prefer importing from 'types' over 'num' */
3
+ export type { BigNumberish };
4
+ /**
5
+ * Test if string is hex-string
6
+ *
7
+ * @param hex hex-string
8
+ * @returns {boolean} true if the input string is a hexadecimal string, false otherwise
9
+ * @example
10
+ * ```typescript
11
+ * const hexString1 = "0x2fd23d9182193775423497fc0c472e156c57c69e4089a1967fb288a2d84e914";
12
+ * const result1 = isHex(hexString1);
13
+ * // result1 = true
14
+ *
15
+ * const hexString2 = "2fd23d9182193775423497fc0c472e156c57c69e4089a1967fb288a2d84e914";
16
+ * const result2 = isHex(hexString2);
17
+ * // result2 = false
18
+ * ```
19
+ */
20
+ export declare function isHex(hex: string): boolean;
21
+ /**
22
+ * Convert BigNumberish to bigint
23
+ *
24
+ * @param {BigNumberish} value value to convert
25
+ * @returns {BigInt} converted value
26
+ * @example
27
+ * ```typescript
28
+ * const str = '123';
29
+ * const result = toBigInt(str);
30
+ * // result = 123n
31
+ * ```
32
+ */
33
+ export declare function toBigInt(value: BigNumberish): bigint;
34
+ /**
35
+ * Test if value is bigint
36
+ *
37
+ * @param value value to test
38
+ * @returns {boolean} true if value is bigint, false otherwise
39
+ * @example
40
+ * ```typescript
41
+ * isBigInt(10n); // true
42
+ * isBigInt(BigInt('10')); // true
43
+ * isBigInt(10); // false
44
+ * isBigInt('10'); // false
45
+ * isBigInt(null); // false
46
+ * ```
47
+ */
48
+ export declare function isBigInt(value: any): value is bigint;
49
+ /**
50
+ * Convert BigNumberish to hex-string
51
+ *
52
+ * @param {BigNumberish} value value to convert
53
+ * @returns {string} converted number in hex-string format
54
+ * @example
55
+ * ```typescript
56
+ * toHex(100); // '0x64'
57
+ * toHex('200'); // '0xc8'
58
+ * ```
59
+ */
60
+ export declare function toHex(value: BigNumberish): string;
61
+ /**
62
+ * Alias of ToHex
63
+ */
64
+ export declare const toHexString: typeof toHex;
65
+ /**
66
+ * Convert BigNumberish to storage-key-string
67
+ *
68
+ * Same as toHex but conforming to the STORAGE_KEY pattern `^0x0[0-7]{1}[a-fA-F0-9]{0,62}$`.
69
+ *
70
+ * A storage key is represented as up to 62 hex digits, 3 bits, and 5 leading zeroes:
71
+ * `0x0 + [0-7] + 62 hex = 0x + 64 hex`
72
+ * @returns format: storage-key-string
73
+ */
74
+ export declare function toStorageKey(number: BigNumberish): string;
75
+ /**
76
+ * Convert hexadecimal string to decimal string
77
+ *
78
+ * @param {string} hex hex-string to convert
79
+ * @returns {string} converted number in decimal string format
80
+ * @example
81
+ * ```typescript
82
+ * hexToDecimalString('64'); // '100'
83
+ * hexToDecimalString('c8'); // '200'
84
+ * ```
85
+ */
86
+ export declare function hexToDecimalString(hex: string): string;
87
+ /**
88
+ * Remove hex-string leading zeroes and lowercase it
89
+ *
90
+ * @param {string} hex hex-string
91
+ * @returns {string} updated string in hex-string format
92
+ * @example
93
+ * ```typescript
94
+ * cleanHex('0x00023AB'); // '0x23ab'
95
+ * ```
96
+ */
97
+ export declare function cleanHex(hex: string): string;
98
+ /**
99
+ * Asserts input is equal to or greater then lowerBound and lower then upperBound.
100
+ *
101
+ * The `inputName` parameter is used in the assertion message.
102
+ * @param input Value to check
103
+ * @param lowerBound Lower bound value
104
+ * @param upperBound Upper bound value
105
+ * @param inputName Name of the input for error message
106
+ * @throws Error if input is out of range
107
+ * @example
108
+ * ```typescript
109
+ * const input1:BigNumberish = 10;
110
+ * assertInRange(input1, 5, 20, 'value')
111
+ *
112
+ * const input2: BigNumberish = 25;
113
+ * assertInRange(input2, 5, 20, 'value');
114
+ * // throws Error: Message not signable, invalid value length.
115
+ * ```
116
+ */
117
+ export declare function assertInRange(input: BigNumberish, lowerBound: BigNumberish, upperBound: BigNumberish, inputName?: string): void;
118
+ /**
119
+ * Convert BigNumberish array to decimal string array
120
+ *
121
+ * @param {BigNumberish[]} data array of big-numberish elements
122
+ * @returns {string[]} array of decimal strings
123
+ * @example
124
+ * ```typescript
125
+ * const data = [100, 200n];
126
+ * const result = bigNumberishArrayToDecimalStringArray(data);
127
+ * // result = ['100', '200']
128
+ * ```
129
+ */
130
+ export declare function bigNumberishArrayToDecimalStringArray(data: BigNumberish[]): string[];
131
+ /**
132
+ * Convert BigNumberish array to hexadecimal string array
133
+ *
134
+ * @param {BigNumberish[]} data array of big-numberish elements
135
+ * @returns array of hex-strings
136
+ * @example
137
+ * ```typescript
138
+ * const data = [100, 200n];
139
+ * const result = bigNumberishArrayToHexadecimalStringArray(data);
140
+ * // result = ['0x64', '0xc8']
141
+ * ```
142
+ */
143
+ export declare function bigNumberishArrayToHexadecimalStringArray(data: BigNumberish[]): string[];
144
+ /**
145
+ * Test if string is a whole number (0, 1, 2, 3...)
146
+ *
147
+ * @param {string} str string to test
148
+ * @returns {boolean}: true if string is a whole number, false otherwise
149
+ * @example
150
+ * ```typescript
151
+ * isStringWholeNumber('100'); // true
152
+ * isStringWholeNumber('10.0'); // false
153
+ * isStringWholeNumber('test'); // false
154
+ * ```
155
+ */
156
+ export declare function isStringWholeNumber(str: string): boolean;
157
+ /**
158
+ * Convert string to decimal string
159
+ *
160
+ * @param {string} str string to convert
161
+ * @returns converted string in decimal format
162
+ * @throws str needs to be a number string in hex or whole number format
163
+ * @example
164
+ * ```typescript
165
+ * const result = getDecimalString("0x1a");
166
+ * // result = "26"
167
+ *
168
+ * const result2 = getDecimalString("Hello");
169
+ * // throws Error: "Hello needs to be a hex-string or whole-number-string"
170
+ * ```
171
+ */
172
+ export declare function getDecimalString(str: string): string;
173
+ /**
174
+ * Convert string to hexadecimal string
175
+ *
176
+ * @param {string} str string to convert
177
+ * @returns converted hex-string
178
+ * @throws str needs to be a number string in hex or whole number format
179
+ * @example
180
+ * ```typescript
181
+ * const result = getHexString("123");
182
+ * // result = "0x7b"
183
+ *
184
+ * const result2 = getHexString("Hello");
185
+ * // throws Error: Hello needs to be a hex-string or whole-number-string
186
+ * ```
187
+ */
188
+ export declare function getHexString(str: string): string;
189
+ /**
190
+ * Convert string array to hex-string array
191
+ *
192
+ * @param {Array<string>} array array of string elements
193
+ * @returns array of converted elements in hex-string format
194
+ * @example
195
+ * ```typescript
196
+ * const data = ['100', '200', '0xaa'];
197
+ * const result = getHexStringArray(data);
198
+ * // result = ['0x64', '0xc8', '0xaa']
199
+ * ```
200
+ */
201
+ export declare function getHexStringArray(array: Array<string>): string[];
202
+ /**
203
+ * Convert boolean to "0" or "1"
204
+ *
205
+ * @param value The boolean value to be converted.
206
+ * @returns {boolean} Returns true if the value is a number, otherwise returns false.
207
+ * @example
208
+ * ```typescript
209
+ * const result = toCairoBool(true);
210
+ * // result ="1"
211
+ *
212
+ * const result2 = toCairoBool(false);
213
+ * // result2 = "0"
214
+ * ```
215
+ */
216
+ export declare function toCairoBool(value: boolean): string;
217
+ /**
218
+ * Convert hex-string to an array of Bytes (Uint8Array)
219
+ *
220
+ * @param {string} str hex-string
221
+ * @returns {Uint8Array} array containing the converted elements
222
+ * @throws str must be a hex-string
223
+ * @example
224
+ * ```typescript
225
+ * let result;
226
+ *
227
+ * result = hexToBytes('0x64');
228
+ * // result = [100]
229
+ *
230
+ * result = hexToBytes('test');
231
+ * // throws Error: test needs to be a hex-string
232
+ * ```
233
+ */
234
+ export declare function hexToBytes(str: string): Uint8Array;
235
+ /**
236
+ * Adds a percentage amount to the value
237
+ *
238
+ * @param number value to be modified
239
+ * @param percent integer as percent ex. 50 for 50%
240
+ * @returns {BigInt} modified value
241
+ * @example
242
+ * ```typescript
243
+ * addPercent(100, 50); // 150n
244
+ * addPercent(100, 100); // 200n
245
+ * addPercent(200, 50); // 300n
246
+ * addPercent(200, -50); // 100n
247
+ * addPercent(200, -100); // 0n
248
+ * addPercent(200, -150); // -100n
249
+ * ```
250
+ */
251
+ export declare function addPercent(number: BigNumberish, percent: number): bigint;
252
+ /**
253
+ * Check if a value is a number.
254
+ *
255
+ * @param {unknown} value - The value to check.
256
+ * @returns {boolean} Returns true if the value is a number, otherwise returns false.
257
+ * @example
258
+ * ```typescript
259
+ * const result = isNumber(123);
260
+ * // result = true
261
+ *
262
+ * const result2 = isNumber("123");
263
+ * // result2 = false
264
+ * ```
265
+ * @return {boolean} Returns true if the value is a number, otherwise returns false.
266
+ */
267
+ export declare function isNumber(value: unknown): value is number;
268
+ /**
269
+ * Checks if a given value is of boolean type.
270
+ *
271
+ * @param {unknown} value - The value to check.
272
+ * @returns {boolean} - True if the value is of boolean type, false otherwise.
273
+ * @example
274
+ * ```typescript
275
+ * const result = isBoolean(true);
276
+ * // result = true
277
+ *
278
+ * const result2 = isBoolean(false);
279
+ * // result2 = false
280
+ * ```
281
+ * @return {boolean} - True if the value is of boolean type, false otherwise.
282
+ */
283
+ export declare function isBoolean(value: unknown): value is boolean;
@@ -0,0 +1,86 @@
1
+ import { hexToBytes as hexToBytesNoble } from "@noble/curves/abstract/utils";
2
+ import assert from "./assert.mjs";
3
+ import { addHexPrefix, removeHexPrefix } from "./encode.mjs";
4
+ export function isHex(hex) {
5
+ return /^0x[0-9a-f]*$/i.test(hex);
6
+ }
7
+ export function toBigInt(value) {
8
+ return BigInt(value);
9
+ }
10
+ export function isBigInt(value) {
11
+ return typeof value === "bigint";
12
+ }
13
+ export function toHex(value) {
14
+ return addHexPrefix(toBigInt(value).toString(16));
15
+ }
16
+ export const toHexString = toHex;
17
+ export function toStorageKey(number) {
18
+ return addHexPrefix(toBigInt(number).toString(16).padStart(64, "0"));
19
+ }
20
+ export function hexToDecimalString(hex) {
21
+ return BigInt(addHexPrefix(hex)).toString(10);
22
+ }
23
+ export function cleanHex(hex) {
24
+ return hex.toLowerCase().replace(/^(0x)0+/, "$1");
25
+ }
26
+ export function assertInRange(input, lowerBound, upperBound, inputName = "") {
27
+ const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
28
+ const inputBigInt = BigInt(input);
29
+ const lowerBoundBigInt = BigInt(lowerBound);
30
+ const upperBoundBigInt = BigInt(upperBound);
31
+ assert(
32
+ inputBigInt >= lowerBoundBigInt && inputBigInt <= upperBoundBigInt,
33
+ `Message not signable, ${messageSuffix}.`
34
+ );
35
+ }
36
+ export function bigNumberishArrayToDecimalStringArray(data) {
37
+ return data.map((x) => toBigInt(x).toString(10));
38
+ }
39
+ export function bigNumberishArrayToHexadecimalStringArray(data) {
40
+ return data.map((x) => toHex(x));
41
+ }
42
+ export function isStringWholeNumber(str) {
43
+ return /^\d+$/.test(str);
44
+ }
45
+ export function getDecimalString(str) {
46
+ if (isHex(str)) {
47
+ return hexToDecimalString(str);
48
+ }
49
+ if (isStringWholeNumber(str)) {
50
+ return str;
51
+ }
52
+ throw new Error(`${str} needs to be a hex-string or whole-number-string`);
53
+ }
54
+ export function getHexString(str) {
55
+ if (isHex(str)) {
56
+ return str;
57
+ }
58
+ if (isStringWholeNumber(str)) {
59
+ return toHexString(str);
60
+ }
61
+ throw new Error(`${str} needs to be a hex-string or whole-number-string`);
62
+ }
63
+ export function getHexStringArray(array) {
64
+ return array.map(getHexString);
65
+ }
66
+ export function toCairoBool(value) {
67
+ return (+value).toString();
68
+ }
69
+ export function hexToBytes(str) {
70
+ if (!isHex(str)) throw new Error(`${str} needs to be a hex-string`);
71
+ let adaptedValue = removeHexPrefix(str);
72
+ if (adaptedValue.length % 2 !== 0) {
73
+ adaptedValue = `0${adaptedValue}`;
74
+ }
75
+ return hexToBytesNoble(adaptedValue);
76
+ }
77
+ export function addPercent(number, percent) {
78
+ const bigIntNum = BigInt(number);
79
+ return bigIntNum + bigIntNum * BigInt(percent) / 100n;
80
+ }
81
+ export function isNumber(value) {
82
+ return typeof value === "number";
83
+ }
84
+ export function isBoolean(value) {
85
+ return typeof value === "boolean";
86
+ }
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Block = void 0;
7
+ exports.createSierraContractClass = createSierraContractClass;
8
+ exports.getDefaultNodeUrl = void 0;
9
+ exports.isPendingBlock = isPendingBlock;
10
+ exports.isPendingStateUpdate = isPendingStateUpdate;
11
+ exports.isPendingTransaction = isPendingTransaction;
12
+ exports.isV3Tx = isV3Tx;
13
+ exports.isVersion = isVersion;
14
+ exports.parseContract = parseContract;
15
+ exports.validBlockTags = void 0;
16
+ exports.wait = wait;
17
+ var _constants = require("../constants.cjs");
18
+ var _types = require("../types/index.cjs");
19
+ var _api = require("../types/api/index.cjs");
20
+ var _contract = require("./contract.cjs");
21
+ var _hash = require("./hash/index.cjs");
22
+ var _json = require("./json.cjs");
23
+ var _num = require("./num.cjs");
24
+ var _shortString = require("./shortString.cjs");
25
+ var _stark = require("./stark.cjs");
26
+ function wait(delay) {
27
+ return new Promise(res => {
28
+ setTimeout(res, delay);
29
+ });
30
+ }
31
+ function createSierraContractClass(contract) {
32
+ const result = {
33
+ ...contract
34
+ };
35
+ delete result.sierra_program_debug_info;
36
+ result.abi = (0, _hash.formatSpaces)((0, _json.stringify)(contract.abi));
37
+ result.sierra_program = (0, _hash.formatSpaces)((0, _json.stringify)(contract.sierra_program));
38
+ result.sierra_program = (0, _stark.compressProgram)(result.sierra_program);
39
+ return result;
40
+ }
41
+ function parseContract(contract) {
42
+ const parsedContract = (0, _shortString.isString)(contract) ? (0, _json.parse)(contract) : contract;
43
+ if (!(0, _contract.isSierra)(contract)) {
44
+ return {
45
+ ...parsedContract,
46
+ ...("program" in parsedContract && {
47
+ program: (0, _stark.compressProgram)(parsedContract.program)
48
+ })
49
+ };
50
+ }
51
+ return createSierraContractClass(parsedContract);
52
+ }
53
+ const getDefaultNodeUrl = (networkName, mute = false) => {
54
+ if (!mute) {
55
+ console.warn("Using default public node url, please provide nodeUrl in provider options!");
56
+ }
57
+ const nodes = _constants.RPC_NODES[networkName ?? _constants.NetworkName.SN_SEPOLIA];
58
+ const randIdx = Math.floor(Math.random() * nodes.length);
59
+ return nodes[randIdx];
60
+ };
61
+ exports.getDefaultNodeUrl = getDefaultNodeUrl;
62
+ const validBlockTags = exports.validBlockTags = Object.values(_types.BlockTag);
63
+ class Block {
64
+ /**
65
+ * @param {BlockIdentifier} hash if not null, contains the block hash
66
+ */
67
+ hash = null;
68
+ /**
69
+ * @param {BlockIdentifier} number if not null, contains the block number
70
+ */
71
+ number = null;
72
+ /**
73
+ * @param {BlockIdentifier} tag if not null, contains "pending" or "latest"
74
+ */
75
+ tag = null;
76
+ setIdentifier(__identifier) {
77
+ if ((0, _shortString.isString)(__identifier)) {
78
+ if ((0, _shortString.isDecimalString)(__identifier)) {
79
+ this.number = parseInt(__identifier, 10);
80
+ } else if ((0, _num.isHex)(__identifier)) {
81
+ this.hash = __identifier;
82
+ } else if (validBlockTags.includes(__identifier)) {
83
+ this.tag = __identifier;
84
+ } else {
85
+ throw TypeError(`Block identifier unmanaged: ${__identifier}`);
86
+ }
87
+ } else if ((0, _num.isBigInt)(__identifier)) {
88
+ this.hash = (0, _num.toHex)(__identifier);
89
+ } else if ((0, _num.isNumber)(__identifier)) {
90
+ this.number = __identifier;
91
+ } else {
92
+ this.tag = _types.BlockTag.PENDING;
93
+ }
94
+ if ((0, _num.isNumber)(this.number) && this.number < 0) {
95
+ throw TypeError(`Block number (${this.number}) can't be negative`);
96
+ }
97
+ }
98
+ /**
99
+ * Create a Block instance
100
+ * @param {BlockIdentifier} _identifier hex string and BigInt are detected as block hashes.
101
+ * decimal string and number are detected as block numbers.
102
+ * text string are detected as block tag.
103
+ * null is considered as a 'pending' block tag.
104
+ */
105
+ constructor(_identifier) {
106
+ this.setIdentifier(_identifier);
107
+ }
108
+ // TODO: fix any
109
+ /**
110
+ * @returns {any} the identifier as a string
111
+ * @example
112
+ * ```typescript
113
+ * const result = new provider.Block(123456n).queryIdentifier;
114
+ * // result = "blockHash=0x1e240"
115
+ * ```
116
+ */
117
+ get queryIdentifier() {
118
+ if (this.number !== null) {
119
+ return `blockNumber=${this.number}`;
120
+ }
121
+ if (this.hash !== null) {
122
+ return `blockHash=${this.hash}`;
123
+ }
124
+ return `blockNumber=${this.tag}`;
125
+ }
126
+ // TODO: fix any
127
+ /**
128
+ * @returns {any} the identifier as an object
129
+ * @example
130
+ * ```typescript
131
+ * const result = new provider.Block(56789).identifier;
132
+ * // result = { block_number: 56789 }
133
+ * ```
134
+ */
135
+ get identifier() {
136
+ if (this.number !== null) {
137
+ return {
138
+ block_number: this.number
139
+ };
140
+ }
141
+ if (this.hash !== null) {
142
+ return {
143
+ block_hash: this.hash
144
+ };
145
+ }
146
+ return this.tag;
147
+ }
148
+ /**
149
+ * change the identifier of an existing Block instance
150
+ * @example
151
+ * ```typescript
152
+ * const myBlock = new provider.Block("latest");
153
+ * myBlock.identifier ="0x3456789abc";
154
+ * const result = myBlock.identifier;
155
+ * // result = { block_hash: '0x3456789abc' }
156
+ * ```
157
+ */
158
+ set identifier(_identifier) {
159
+ this.setIdentifier(_identifier);
160
+ }
161
+ valueOf = () => this.number;
162
+ toString = () => this.hash;
163
+ }
164
+ exports.Block = Block;
165
+ function isV3Tx(details) {
166
+ const version = details.version ? (0, _num.toHex)(details.version) : _api.ETransactionVersion.V3;
167
+ return version === _api.ETransactionVersion.V3 || version === _api.ETransactionVersion.F3;
168
+ }
169
+ function isVersion(version, response) {
170
+ const [majorS, minorS] = version.split(".");
171
+ const [majorR, minorR] = response.split(".");
172
+ return majorS === majorR && minorS === minorR;
173
+ }
174
+ function isPendingBlock(response) {
175
+ return response.status === "PENDING";
176
+ }
177
+ function isPendingTransaction(response) {
178
+ return !("block_hash" in response);
179
+ }
180
+ function isPendingStateUpdate(response) {
181
+ return !("block_hash" in response);
182
+ }