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,302 @@
1
+ import { bytesToHex } from "@noble/curves/abstract/utils";
2
+ import { keccak_256 } from "@noble/hashes/sha3";
3
+ import { RPC06, RpcChannel } from "../channel/index.mjs";
4
+ import {
5
+ BlockTag,
6
+ TransactionType
7
+ } from "../types/index.mjs";
8
+ import assert from "../utils/assert.mjs";
9
+ import { getAbiContractVersion } from "../utils/calldata/cairo.mjs";
10
+ import { isSierra } from "../utils/contract.mjs";
11
+ import { addHexPrefix, removeHexPrefix } from "../utils/encode.mjs";
12
+ import { hexToBytes, toHex } from "../utils/num.mjs";
13
+ import { wait } from "../utils/provider.mjs";
14
+ import { RPCResponseParser } from "../utils/responseParser/rpc.mjs";
15
+ import { ReceiptTx } from "../utils/transactionReceipt.mjs";
16
+ import { LibraryError } from "./errors.mjs";
17
+ export class RpcProvider {
18
+ responseParser;
19
+ channel;
20
+ constructor(optionsOrProvider) {
21
+ if (optionsOrProvider && "channel" in optionsOrProvider) {
22
+ this.channel = optionsOrProvider.channel;
23
+ this.responseParser = "responseParser" in optionsOrProvider ? optionsOrProvider.responseParser : new RPCResponseParser();
24
+ } else {
25
+ this.channel = new RpcChannel({ ...optionsOrProvider, waitMode: false });
26
+ this.responseParser = new RPCResponseParser(optionsOrProvider?.feeMarginPercentage);
27
+ }
28
+ }
29
+ fetch(method, params, id = 0) {
30
+ return this.channel.fetch(method, params, id);
31
+ }
32
+ async getChainId() {
33
+ return this.channel.getChainId();
34
+ }
35
+ async getSpecVersion() {
36
+ return this.channel.getSpecVersion();
37
+ }
38
+ async getNonceForAddress(contractAddress, blockIdentifier) {
39
+ return this.channel.getNonceForAddress(contractAddress, blockIdentifier);
40
+ }
41
+ async getBlock(blockIdentifier) {
42
+ return this.channel.getBlockWithTxHashes(blockIdentifier).then(this.responseParser.parseGetBlockResponse);
43
+ }
44
+ /**
45
+ * Get the most recent accepted block hash and number
46
+ */
47
+ async getBlockLatestAccepted() {
48
+ return this.channel.getBlockLatestAccepted();
49
+ }
50
+ /**
51
+ * Get the most recent accepted block number
52
+ * redundant use getBlockLatestAccepted();
53
+ * @returns Number of the latest block
54
+ */
55
+ async getBlockNumber() {
56
+ return this.channel.getBlockNumber();
57
+ }
58
+ async getBlockWithTxHashes(blockIdentifier) {
59
+ return this.channel.getBlockWithTxHashes(blockIdentifier);
60
+ }
61
+ async getBlockWithTxs(blockIdentifier) {
62
+ return this.channel.getBlockWithTxs(blockIdentifier);
63
+ }
64
+ /**
65
+ * Pause the execution of the script until a specified block is created.
66
+ * @param {BlockIdentifier} blockIdentifier bloc number (BigNumberisk) or 'pending' or 'latest'.
67
+ * Use of 'latest" or of a block already created will generate no pause.
68
+ * @param {number} [retryInterval] number of milliseconds between 2 requests to the node
69
+ * @example
70
+ * ```typescript
71
+ * await myProvider.waitForBlock();
72
+ * // wait the creation of the pending block
73
+ * ```
74
+ */
75
+ async waitForBlock(blockIdentifier = "pending", retryInterval = 5e3) {
76
+ if (blockIdentifier === BlockTag.LATEST) return;
77
+ const currentBlock = await this.getBlockNumber();
78
+ const targetBlock = blockIdentifier === BlockTag.PENDING ? currentBlock + 1 : Number(toHex(blockIdentifier));
79
+ if (targetBlock <= currentBlock) return;
80
+ const { retries } = this.channel;
81
+ let retriesCount = retries;
82
+ let isTargetBlock = false;
83
+ while (!isTargetBlock) {
84
+ const currBlock = await this.getBlockNumber();
85
+ if (currBlock === targetBlock) {
86
+ isTargetBlock = true;
87
+ } else {
88
+ await wait(retryInterval);
89
+ }
90
+ retriesCount -= 1;
91
+ if (retriesCount <= 0) {
92
+ throw new Error(`waitForBlock() timed-out after ${retries} tries.`);
93
+ }
94
+ }
95
+ }
96
+ async getL1GasPrice(blockIdentifier) {
97
+ return this.channel.getBlockWithTxHashes(blockIdentifier).then(this.responseParser.parseL1GasPriceResponse);
98
+ }
99
+ async getL1MessageHash(l2TxHash) {
100
+ const transaction = await this.channel.getTransactionByHash(l2TxHash);
101
+ assert(transaction.type === "L1_HANDLER", "This L2 transaction is not a L1 message.");
102
+ const { calldata, contract_address, entry_point_selector, nonce } = transaction;
103
+ const params = [
104
+ calldata[0],
105
+ contract_address,
106
+ nonce,
107
+ entry_point_selector,
108
+ calldata.length - 1,
109
+ ...calldata.slice(1)
110
+ ];
111
+ const myEncode = addHexPrefix(
112
+ params.reduce(
113
+ (res, par) => res + removeHexPrefix(toHex(par)).padStart(64, "0"),
114
+ ""
115
+ )
116
+ );
117
+ return addHexPrefix(bytesToHex(keccak_256(hexToBytes(myEncode))));
118
+ }
119
+ async getBlockWithReceipts(blockIdentifier) {
120
+ if (this.channel instanceof RPC06.RpcChannel)
121
+ throw new LibraryError("Unsupported method for RPC version");
122
+ return this.channel.getBlockWithReceipts(blockIdentifier);
123
+ }
124
+ getStateUpdate = this.getBlockStateUpdate;
125
+ async getBlockStateUpdate(blockIdentifier) {
126
+ return this.channel.getBlockStateUpdate(blockIdentifier);
127
+ }
128
+ async getBlockTransactionsTraces(blockIdentifier) {
129
+ return this.channel.getBlockTransactionsTraces(blockIdentifier);
130
+ }
131
+ async getBlockTransactionCount(blockIdentifier) {
132
+ return this.channel.getBlockTransactionCount(blockIdentifier);
133
+ }
134
+ /**
135
+ * Return transactions from pending block
136
+ * @deprecated Instead use getBlock(BlockTag.PENDING); (will be removed in next minor version)
137
+ * Utility method, same result can be achieved using getBlockWithTxHashes(BlockTag.pending);
138
+ */
139
+ async getPendingTransactions() {
140
+ const { transactions } = await this.getBlockWithTxHashes(BlockTag.PENDING).then(
141
+ this.responseParser.parseGetBlockResponse
142
+ );
143
+ return Promise.all(transactions.map((it) => this.getTransactionByHash(it)));
144
+ }
145
+ async getTransaction(txHash) {
146
+ return this.channel.getTransactionByHash(txHash);
147
+ }
148
+ async getTransactionByHash(txHash) {
149
+ return this.channel.getTransactionByHash(txHash);
150
+ }
151
+ async getTransactionByBlockIdAndIndex(blockIdentifier, index) {
152
+ return this.channel.getTransactionByBlockIdAndIndex(blockIdentifier, index);
153
+ }
154
+ async getTransactionReceipt(txHash) {
155
+ const txReceiptWoHelper = await this.channel.getTransactionReceipt(txHash);
156
+ const txReceiptWoHelperModified = this.responseParser.parseTransactionReceipt(txReceiptWoHelper);
157
+ return new ReceiptTx(txReceiptWoHelperModified);
158
+ }
159
+ async getTransactionTrace(txHash) {
160
+ return this.channel.getTransactionTrace(txHash);
161
+ }
162
+ /**
163
+ * Get the status of a transaction
164
+ */
165
+ async getTransactionStatus(transactionHash) {
166
+ return this.channel.getTransactionStatus(transactionHash);
167
+ }
168
+ /**
169
+ * @param invocations AccountInvocations
170
+ * @param options blockIdentifier and flags to skip validation and fee charge<br/>
171
+ * - blockIdentifier<br/>
172
+ * - skipValidate (default false)<br/>
173
+ * - skipFeeCharge (default true)<br/>
174
+ */
175
+ async getSimulateTransaction(invocations, options) {
176
+ return this.channel.simulateTransaction(invocations, options).then((r) => this.responseParser.parseSimulateTransactionResponse(r));
177
+ }
178
+ async waitForTransaction(txHash, options) {
179
+ const receiptWoHelper = await this.channel.waitForTransaction(
180
+ txHash,
181
+ options
182
+ );
183
+ return new ReceiptTx(receiptWoHelper);
184
+ }
185
+ async getStorageAt(contractAddress, key, blockIdentifier) {
186
+ return this.channel.getStorageAt(contractAddress, key, blockIdentifier);
187
+ }
188
+ async getClassHashAt(contractAddress, blockIdentifier) {
189
+ return this.channel.getClassHashAt(contractAddress, blockIdentifier);
190
+ }
191
+ async getClassByHash(classHash) {
192
+ return this.getClass(classHash);
193
+ }
194
+ async getClass(classHash, blockIdentifier) {
195
+ return this.channel.getClass(classHash, blockIdentifier).then(this.responseParser.parseContractClassResponse);
196
+ }
197
+ async getClassAt(contractAddress, blockIdentifier) {
198
+ return this.channel.getClassAt(contractAddress, blockIdentifier).then(this.responseParser.parseContractClassResponse);
199
+ }
200
+ async getContractVersion(contractAddress, classHash, {
201
+ blockIdentifier = this.channel.blockIdentifier,
202
+ compiler = true
203
+ } = {}) {
204
+ let contractClass;
205
+ if (contractAddress) {
206
+ contractClass = await this.getClassAt(contractAddress, blockIdentifier);
207
+ } else if (classHash) {
208
+ contractClass = await this.getClass(classHash, blockIdentifier);
209
+ } else {
210
+ throw Error("getContractVersion require contractAddress or classHash");
211
+ }
212
+ if (isSierra(contractClass)) {
213
+ if (compiler) {
214
+ const abiTest = getAbiContractVersion(contractClass.abi);
215
+ return { cairo: "1", compiler: abiTest.compiler };
216
+ }
217
+ return { cairo: "1", compiler: void 0 };
218
+ }
219
+ return { cairo: "0", compiler: "0" };
220
+ }
221
+ /**
222
+ * @deprecated use get*type*EstimateFee (will be refactored based on type after sequencer deprecation)
223
+ */
224
+ async getEstimateFee(invocation, invocationDetails, blockIdentifier, skipValidate) {
225
+ return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier, skipValidate);
226
+ }
227
+ async getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier, skipValidate) {
228
+ return this.channel.getEstimateFee(
229
+ [
230
+ {
231
+ type: TransactionType.INVOKE,
232
+ ...invocation,
233
+ ...invocationDetails
234
+ }
235
+ ],
236
+ { blockIdentifier, skipValidate }
237
+ ).then((r) => this.responseParser.parseFeeEstimateResponse(r));
238
+ }
239
+ async getDeclareEstimateFee(invocation, details, blockIdentifier, skipValidate) {
240
+ return this.channel.getEstimateFee(
241
+ [
242
+ {
243
+ type: TransactionType.DECLARE,
244
+ ...invocation,
245
+ ...details
246
+ }
247
+ ],
248
+ { blockIdentifier, skipValidate }
249
+ ).then((r) => this.responseParser.parseFeeEstimateResponse(r));
250
+ }
251
+ async getDeployAccountEstimateFee(invocation, details, blockIdentifier, skipValidate) {
252
+ return this.channel.getEstimateFee(
253
+ [
254
+ {
255
+ type: TransactionType.DEPLOY_ACCOUNT,
256
+ ...invocation,
257
+ ...details
258
+ }
259
+ ],
260
+ { blockIdentifier, skipValidate }
261
+ ).then((r) => this.responseParser.parseFeeEstimateResponse(r));
262
+ }
263
+ async getEstimateFeeBulk(invocations, options) {
264
+ return this.channel.getEstimateFee(invocations, options).then((r) => this.responseParser.parseFeeEstimateBulkResponse(r));
265
+ }
266
+ async invokeFunction(functionInvocation, details) {
267
+ return this.channel.invoke(functionInvocation, details);
268
+ }
269
+ async declareContract(transaction, details) {
270
+ return this.channel.declare(transaction, details);
271
+ }
272
+ async deployAccountContract(transaction, details) {
273
+ return this.channel.deployAccount(
274
+ transaction,
275
+ details
276
+ );
277
+ }
278
+ async callContract(call, blockIdentifier) {
279
+ return this.channel.callContract(call, blockIdentifier);
280
+ }
281
+ /**
282
+ * NEW: Estimate the fee for a message from L1
283
+ * @param message Message From L1
284
+ */
285
+ async estimateMessageFee(message, blockIdentifier) {
286
+ return this.channel.estimateMessageFee(message, blockIdentifier);
287
+ }
288
+ /**
289
+ * Returns an object about the sync status, or false if the node is not synching
290
+ * @returns Object with the stats data
291
+ */
292
+ async getSyncingStats() {
293
+ return this.channel.getSyncingStats();
294
+ }
295
+ /**
296
+ * Returns all events matching the given filter
297
+ * @returns events and the pagination of the events
298
+ */
299
+ async getEvents(eventFilter) {
300
+ return this.channel.getEvents(eventFilter);
301
+ }
302
+ }
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,5 @@
1
+ import { BlockIdentifier } from '../types';
2
+ export type getEstimateFeeBulkOptions = {
3
+ blockIdentifier?: BlockIdentifier;
4
+ skipValidate?: boolean;
5
+ };
File without changes
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Signer = void 0;
7
+ var _api = require("../types/api/index.cjs");
8
+ var _calldata = require("../utils/calldata/index.cjs");
9
+ var _ec = require("../utils/ec.cjs");
10
+ var _encode = require("../utils/encode.cjs");
11
+ var _hash = require("../utils/hash/index.cjs");
12
+ var _num = require("../utils/num.cjs");
13
+ var _stark = require("../utils/stark.cjs");
14
+ var _transaction = require("../utils/transaction.cjs");
15
+ var _typedData = require("../utils/typedData.cjs");
16
+ class Signer {
17
+ pk;
18
+ constructor(pk = _ec.starkCurve.utils.randomPrivateKey()) {
19
+ this.pk = pk instanceof Uint8Array ? (0, _encode.buf2hex)(pk) : (0, _num.toHex)(pk);
20
+ }
21
+ async getPubKey() {
22
+ return _ec.starkCurve.getStarkKey(this.pk);
23
+ }
24
+ async signMessage(typedData, accountAddress) {
25
+ const msgHash = (0, _typedData.getMessageHash)(typedData, accountAddress);
26
+ return this.signRaw(msgHash);
27
+ }
28
+ async signTransaction(transactions, details) {
29
+ const compiledCalldata = (0, _transaction.getExecuteCalldata)(transactions, details.cairoVersion);
30
+ let msgHash;
31
+ if (Object.values(_api.ETransactionVersion2).includes(details.version)) {
32
+ const det = details;
33
+ msgHash = (0, _hash.calculateInvokeTransactionHash)({
34
+ ...det,
35
+ senderAddress: det.walletAddress,
36
+ compiledCalldata,
37
+ version: det.version
38
+ });
39
+ } else if (Object.values(_api.ETransactionVersion3).includes(details.version)) {
40
+ const det = details;
41
+ msgHash = (0, _hash.calculateInvokeTransactionHash)({
42
+ ...det,
43
+ senderAddress: det.walletAddress,
44
+ compiledCalldata,
45
+ version: det.version,
46
+ nonceDataAvailabilityMode: (0, _stark.intDAM)(det.nonceDataAvailabilityMode),
47
+ feeDataAvailabilityMode: (0, _stark.intDAM)(det.feeDataAvailabilityMode)
48
+ });
49
+ } else {
50
+ throw Error("unsupported signTransaction version");
51
+ }
52
+ return this.signRaw(msgHash);
53
+ }
54
+ async signDeployAccountTransaction(details) {
55
+ const compiledConstructorCalldata = _calldata.CallData.compile(details.constructorCalldata);
56
+ let msgHash;
57
+ if (Object.values(_api.ETransactionVersion2).includes(details.version)) {
58
+ const det = details;
59
+ msgHash = (0, _hash.calculateDeployAccountTransactionHash)({
60
+ ...det,
61
+ salt: det.addressSalt,
62
+ constructorCalldata: compiledConstructorCalldata,
63
+ version: det.version
64
+ });
65
+ } else if (Object.values(_api.ETransactionVersion3).includes(details.version)) {
66
+ const det = details;
67
+ msgHash = (0, _hash.calculateDeployAccountTransactionHash)({
68
+ ...det,
69
+ salt: det.addressSalt,
70
+ compiledConstructorCalldata,
71
+ version: det.version,
72
+ nonceDataAvailabilityMode: (0, _stark.intDAM)(det.nonceDataAvailabilityMode),
73
+ feeDataAvailabilityMode: (0, _stark.intDAM)(det.feeDataAvailabilityMode)
74
+ });
75
+ } else {
76
+ throw Error("unsupported signDeployAccountTransaction version");
77
+ }
78
+ return this.signRaw(msgHash);
79
+ }
80
+ async signDeclareTransaction(details) {
81
+ let msgHash;
82
+ if (Object.values(_api.ETransactionVersion2).includes(details.version)) {
83
+ const det = details;
84
+ msgHash = (0, _hash.calculateDeclareTransactionHash)({
85
+ ...det,
86
+ version: det.version
87
+ });
88
+ } else if (Object.values(_api.ETransactionVersion3).includes(details.version)) {
89
+ const det = details;
90
+ msgHash = (0, _hash.calculateDeclareTransactionHash)({
91
+ ...det,
92
+ version: det.version,
93
+ nonceDataAvailabilityMode: (0, _stark.intDAM)(det.nonceDataAvailabilityMode),
94
+ feeDataAvailabilityMode: (0, _stark.intDAM)(det.feeDataAvailabilityMode)
95
+ });
96
+ } else {
97
+ throw Error("unsupported signDeclareTransaction version");
98
+ }
99
+ return this.signRaw(msgHash);
100
+ }
101
+ async signRaw(msgHash) {
102
+ return _ec.starkCurve.sign(msgHash, this.pk);
103
+ }
104
+ }
105
+ exports.Signer = Signer;
@@ -0,0 +1,12 @@
1
+ import { Call, DeclareSignerDetails, DeployAccountSignerDetails, InvocationsSignerDetails, Signature, TypedData } from '../types';
2
+ import { SignerInterface } from './interface';
3
+ export declare class Signer implements SignerInterface {
4
+ protected pk: Uint8Array | string;
5
+ constructor(pk?: Uint8Array | string);
6
+ getPubKey(): Promise<string>;
7
+ signMessage(typedData: TypedData, accountAddress: string): Promise<Signature>;
8
+ signTransaction(transactions: Call[], details: InvocationsSignerDetails): Promise<Signature>;
9
+ signDeployAccountTransaction(details: DeployAccountSignerDetails): Promise<Signature>;
10
+ signDeclareTransaction(details: DeclareSignerDetails): Promise<Signature>;
11
+ protected signRaw(msgHash: string): Promise<Signature>;
12
+ }
@@ -0,0 +1,102 @@
1
+ import { ETransactionVersion2, ETransactionVersion3 } from "../types/api/index.mjs";
2
+ import { CallData } from "../utils/calldata/index.mjs";
3
+ import { starkCurve } from "../utils/ec.mjs";
4
+ import { buf2hex } from "../utils/encode.mjs";
5
+ import {
6
+ calculateDeclareTransactionHash,
7
+ calculateDeployAccountTransactionHash,
8
+ calculateInvokeTransactionHash
9
+ } from "../utils/hash/index.mjs";
10
+ import { toHex } from "../utils/num.mjs";
11
+ import { intDAM } from "../utils/stark.mjs";
12
+ import { getExecuteCalldata } from "../utils/transaction.mjs";
13
+ import { getMessageHash } from "../utils/typedData.mjs";
14
+ export class Signer {
15
+ pk;
16
+ constructor(pk = starkCurve.utils.randomPrivateKey()) {
17
+ this.pk = pk instanceof Uint8Array ? buf2hex(pk) : toHex(pk);
18
+ }
19
+ async getPubKey() {
20
+ return starkCurve.getStarkKey(this.pk);
21
+ }
22
+ async signMessage(typedData, accountAddress) {
23
+ const msgHash = getMessageHash(typedData, accountAddress);
24
+ return this.signRaw(msgHash);
25
+ }
26
+ async signTransaction(transactions, details) {
27
+ const compiledCalldata = getExecuteCalldata(transactions, details.cairoVersion);
28
+ let msgHash;
29
+ if (Object.values(ETransactionVersion2).includes(details.version)) {
30
+ const det = details;
31
+ msgHash = calculateInvokeTransactionHash({
32
+ ...det,
33
+ senderAddress: det.walletAddress,
34
+ compiledCalldata,
35
+ version: det.version
36
+ });
37
+ } else if (Object.values(ETransactionVersion3).includes(details.version)) {
38
+ const det = details;
39
+ msgHash = calculateInvokeTransactionHash({
40
+ ...det,
41
+ senderAddress: det.walletAddress,
42
+ compiledCalldata,
43
+ version: det.version,
44
+ nonceDataAvailabilityMode: intDAM(det.nonceDataAvailabilityMode),
45
+ feeDataAvailabilityMode: intDAM(det.feeDataAvailabilityMode)
46
+ });
47
+ } else {
48
+ throw Error("unsupported signTransaction version");
49
+ }
50
+ return this.signRaw(msgHash);
51
+ }
52
+ async signDeployAccountTransaction(details) {
53
+ const compiledConstructorCalldata = CallData.compile(details.constructorCalldata);
54
+ let msgHash;
55
+ if (Object.values(ETransactionVersion2).includes(details.version)) {
56
+ const det = details;
57
+ msgHash = calculateDeployAccountTransactionHash({
58
+ ...det,
59
+ salt: det.addressSalt,
60
+ constructorCalldata: compiledConstructorCalldata,
61
+ version: det.version
62
+ });
63
+ } else if (Object.values(ETransactionVersion3).includes(details.version)) {
64
+ const det = details;
65
+ msgHash = calculateDeployAccountTransactionHash({
66
+ ...det,
67
+ salt: det.addressSalt,
68
+ compiledConstructorCalldata,
69
+ version: det.version,
70
+ nonceDataAvailabilityMode: intDAM(det.nonceDataAvailabilityMode),
71
+ feeDataAvailabilityMode: intDAM(det.feeDataAvailabilityMode)
72
+ });
73
+ } else {
74
+ throw Error("unsupported signDeployAccountTransaction version");
75
+ }
76
+ return this.signRaw(msgHash);
77
+ }
78
+ async signDeclareTransaction(details) {
79
+ let msgHash;
80
+ if (Object.values(ETransactionVersion2).includes(details.version)) {
81
+ const det = details;
82
+ msgHash = calculateDeclareTransactionHash({
83
+ ...det,
84
+ version: det.version
85
+ });
86
+ } else if (Object.values(ETransactionVersion3).includes(details.version)) {
87
+ const det = details;
88
+ msgHash = calculateDeclareTransactionHash({
89
+ ...det,
90
+ version: det.version,
91
+ nonceDataAvailabilityMode: intDAM(det.nonceDataAvailabilityMode),
92
+ feeDataAvailabilityMode: intDAM(det.feeDataAvailabilityMode)
93
+ });
94
+ } else {
95
+ throw Error("unsupported signDeclareTransaction version");
96
+ }
97
+ return this.signRaw(msgHash);
98
+ }
99
+ async signRaw(msgHash) {
100
+ return starkCurve.sign(msgHash, this.pk);
101
+ }
102
+ }
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.EthSigner = void 0;
7
+ var _secp256k = require("@noble/curves/secp256k1");
8
+ var _api = require("../types/api/index.cjs");
9
+ var _calldata = require("../utils/calldata/index.cjs");
10
+ var _encode = require("../utils/encode.cjs");
11
+ var _eth = require("../utils/eth.cjs");
12
+ var _hash = require("../utils/hash/index.cjs");
13
+ var _num = require("../utils/num.cjs");
14
+ var _stark = require("../utils/stark.cjs");
15
+ var _transaction = require("../utils/transaction.cjs");
16
+ var _typedData = require("../utils/typedData.cjs");
17
+ var _uint = require("../utils/uint256.cjs");
18
+ class EthSigner {
19
+ pk;
20
+ // hex string without 0x and with an odd number of characters
21
+ constructor(pk = (0, _eth.ethRandomPrivateKey)()) {
22
+ this.pk = pk instanceof Uint8Array ? (0, _encode.buf2hex)(pk).padStart(64, "0") : (0, _encode.removeHexPrefix)((0, _num.toHex)(pk)).padStart(64, "0");
23
+ }
24
+ /**
25
+ * provides the Ethereum full public key (without parity prefix)
26
+ * @returns an hex string : 64 first characters are Point X coordinate. 64 last characters are Point Y coordinate.
27
+ */
28
+ async getPubKey() {
29
+ return (0, _encode.addHexPrefix)((0, _encode.buf2hex)(_secp256k.secp256k1.getPublicKey(this.pk, false)).padStart(130, "0").slice(2));
30
+ }
31
+ async signMessage(typedData, accountAddress) {
32
+ const msgHash = (0, _typedData.getMessageHash)(typedData, accountAddress);
33
+ const signature = _secp256k.secp256k1.sign((0, _encode.removeHexPrefix)((0, _encode.sanitizeHex)(msgHash)), this.pk);
34
+ return this.formatEthSignature(signature);
35
+ }
36
+ async signTransaction(transactions, details) {
37
+ const compiledCalldata = (0, _transaction.getExecuteCalldata)(transactions, details.cairoVersion);
38
+ let msgHash;
39
+ if (Object.values(_api.ETransactionVersion2).includes(details.version)) {
40
+ const det = details;
41
+ msgHash = (0, _hash.calculateInvokeTransactionHash)({
42
+ ...det,
43
+ senderAddress: det.walletAddress,
44
+ compiledCalldata,
45
+ version: det.version
46
+ });
47
+ } else if (Object.values(_api.ETransactionVersion3).includes(details.version)) {
48
+ const det = details;
49
+ msgHash = (0, _hash.calculateInvokeTransactionHash)({
50
+ ...det,
51
+ senderAddress: det.walletAddress,
52
+ compiledCalldata,
53
+ version: det.version,
54
+ nonceDataAvailabilityMode: (0, _stark.intDAM)(det.nonceDataAvailabilityMode),
55
+ feeDataAvailabilityMode: (0, _stark.intDAM)(det.feeDataAvailabilityMode)
56
+ });
57
+ } else {
58
+ throw Error("unsupported signTransaction version");
59
+ }
60
+ const signature = _secp256k.secp256k1.sign((0, _encode.removeHexPrefix)((0, _encode.sanitizeHex)(msgHash)), this.pk);
61
+ return this.formatEthSignature(signature);
62
+ }
63
+ async signDeployAccountTransaction(details) {
64
+ const compiledConstructorCalldata = _calldata.CallData.compile(details.constructorCalldata);
65
+ let msgHash;
66
+ if (Object.values(_api.ETransactionVersion2).includes(details.version)) {
67
+ const det = details;
68
+ msgHash = (0, _hash.calculateDeployAccountTransactionHash)({
69
+ ...det,
70
+ salt: det.addressSalt,
71
+ constructorCalldata: compiledConstructorCalldata,
72
+ version: det.version
73
+ });
74
+ } else if (Object.values(_api.ETransactionVersion3).includes(details.version)) {
75
+ const det = details;
76
+ msgHash = (0, _hash.calculateDeployAccountTransactionHash)({
77
+ ...det,
78
+ salt: det.addressSalt,
79
+ compiledConstructorCalldata,
80
+ version: det.version,
81
+ nonceDataAvailabilityMode: (0, _stark.intDAM)(det.nonceDataAvailabilityMode),
82
+ feeDataAvailabilityMode: (0, _stark.intDAM)(det.feeDataAvailabilityMode)
83
+ });
84
+ } else {
85
+ throw Error("unsupported signDeployAccountTransaction version");
86
+ }
87
+ const signature = _secp256k.secp256k1.sign((0, _encode.removeHexPrefix)((0, _encode.sanitizeHex)(msgHash)), this.pk);
88
+ return this.formatEthSignature(signature);
89
+ }
90
+ async signDeclareTransaction(details) {
91
+ let msgHash;
92
+ if (Object.values(_api.ETransactionVersion2).includes(details.version)) {
93
+ const det = details;
94
+ msgHash = (0, _hash.calculateDeclareTransactionHash)({
95
+ ...det,
96
+ version: det.version
97
+ });
98
+ } else if (Object.values(_api.ETransactionVersion3).includes(details.version)) {
99
+ const det = details;
100
+ msgHash = (0, _hash.calculateDeclareTransactionHash)({
101
+ ...det,
102
+ version: det.version,
103
+ nonceDataAvailabilityMode: (0, _stark.intDAM)(det.nonceDataAvailabilityMode),
104
+ feeDataAvailabilityMode: (0, _stark.intDAM)(det.feeDataAvailabilityMode)
105
+ });
106
+ } else {
107
+ throw Error("unsupported signDeclareTransaction version");
108
+ }
109
+ const signature = _secp256k.secp256k1.sign((0, _encode.removeHexPrefix)((0, _encode.sanitizeHex)(msgHash)), this.pk);
110
+ return this.formatEthSignature(signature);
111
+ }
112
+ /**
113
+ * Serialize the signature in conformity with starknet::eth_signature::Signature
114
+ * @param ethSignature secp256k1 signature from Noble curves library
115
+ * @return an array of felts, representing a Cairo Eth Signature.
116
+ */
117
+ formatEthSignature(ethSignature) {
118
+ const r = (0, _uint.bnToUint256)(ethSignature.r);
119
+ const s = (0, _uint.bnToUint256)(ethSignature.s);
120
+ return [(0, _num.toHex)(r.low), (0, _num.toHex)(r.high), (0, _num.toHex)(s.low), (0, _num.toHex)(s.high), (0, _num.toHex)(ethSignature.recovery)];
121
+ }
122
+ }
123
+ exports.EthSigner = EthSigner;
@@ -0,0 +1,25 @@
1
+ import type { RecoveredSignatureType } from '@noble/curves/abstract/weierstrass';
2
+ import { ArraySignatureType, Call, DeclareSignerDetails, DeployAccountSignerDetails, InvocationsSignerDetails, Signature, TypedData } from '../types';
3
+ import { SignerInterface } from './interface';
4
+ /**
5
+ * Signer for accounts using Ethereum signature
6
+ */
7
+ export declare class EthSigner implements SignerInterface {
8
+ protected pk: string;
9
+ constructor(pk?: Uint8Array | string);
10
+ /**
11
+ * provides the Ethereum full public key (without parity prefix)
12
+ * @returns an hex string : 64 first characters are Point X coordinate. 64 last characters are Point Y coordinate.
13
+ */
14
+ getPubKey(): Promise<string>;
15
+ signMessage(typedData: TypedData, accountAddress: string): Promise<Signature>;
16
+ signTransaction(transactions: Call[], details: InvocationsSignerDetails): Promise<Signature>;
17
+ signDeployAccountTransaction(details: DeployAccountSignerDetails): Promise<Signature>;
18
+ signDeclareTransaction(details: DeclareSignerDetails): Promise<Signature>;
19
+ /**
20
+ * Serialize the signature in conformity with starknet::eth_signature::Signature
21
+ * @param ethSignature secp256k1 signature from Noble curves library
22
+ * @return an array of felts, representing a Cairo Eth Signature.
23
+ */
24
+ protected formatEthSignature(ethSignature: RecoveredSignatureType): ArraySignatureType;
25
+ }