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,655 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Account = void 0;
7
+ var _constants = require("../constants.cjs");
8
+ var _provider = require("../provider/index.cjs");
9
+ var _signer = require("../signer/index.cjs");
10
+ var _types = require("../types/index.cjs");
11
+ var _api = require("../types/api/index.cjs");
12
+ var _calldata = require("../utils/calldata/index.cjs");
13
+ var _contract = require("../utils/contract.cjs");
14
+ var _events = require("../utils/events/index.cjs");
15
+ var _hash = require("../utils/hash/index.cjs");
16
+ var _num = require("../utils/num.cjs");
17
+ var _provider2 = require("../utils/provider.cjs");
18
+ var _shortString = require("../utils/shortString.cjs");
19
+ var _stark = require("../utils/stark.cjs");
20
+ var _transaction = require("../utils/transaction.cjs");
21
+ var _typedData = require("../utils/typedData.cjs");
22
+ class Account extends _provider.Provider {
23
+ signer;
24
+ address;
25
+ cairoVersion;
26
+ transactionVersion;
27
+ constructor(providerOrOptions, address, pkOrSigner, cairoVersion, transactionVersion = _api.ETransactionVersion.V2) {
28
+ super(providerOrOptions);
29
+ this.address = address.toLowerCase();
30
+ this.signer = (0, _shortString.isString)(pkOrSigner) || pkOrSigner instanceof Uint8Array ? new _signer.Signer(pkOrSigner) : pkOrSigner;
31
+ if (cairoVersion) {
32
+ this.cairoVersion = cairoVersion.toString();
33
+ }
34
+ this.transactionVersion = transactionVersion;
35
+ }
36
+ // provided version or contract based preferred transactionVersion
37
+ getPreferredVersion(type12, type3) {
38
+ if (this.transactionVersion === _api.ETransactionVersion.V3) return type3;
39
+ if (this.transactionVersion === _api.ETransactionVersion.V2) return type12;
40
+ return _api.ETransactionVersion.V3;
41
+ }
42
+ async getNonce(blockIdentifier) {
43
+ return super.getNonceForAddress(this.address, blockIdentifier);
44
+ }
45
+ async getNonceSafe(nonce) {
46
+ try {
47
+ return (0, _num.toBigInt)(nonce ?? (await this.getNonce()));
48
+ } catch (error) {
49
+ return 0n;
50
+ }
51
+ }
52
+ /**
53
+ * Retrieves the Cairo version from the network and sets `cairoVersion` if not already set in the constructor.
54
+ * @param classHash if provided detects Cairo version from classHash, otherwise from the account address
55
+ */
56
+ async getCairoVersion(classHash) {
57
+ if (!this.cairoVersion) {
58
+ const {
59
+ cairo
60
+ } = classHash ? await super.getContractVersion(void 0, classHash) : await super.getContractVersion(this.address);
61
+ this.cairoVersion = cairo;
62
+ }
63
+ return this.cairoVersion;
64
+ }
65
+ async estimateFee(calls, estimateFeeDetails = {}) {
66
+ return this.estimateInvokeFee(calls, estimateFeeDetails);
67
+ }
68
+ async estimateInvokeFee(calls, details = {}) {
69
+ const {
70
+ nonce: providedNonce,
71
+ blockIdentifier,
72
+ version: providedVersion,
73
+ skipValidate = true
74
+ } = details;
75
+ const transactions = Array.isArray(calls) ? calls : [calls];
76
+ const nonce = (0, _num.toBigInt)(providedNonce ?? (await this.getNonce()));
77
+ const version = (0, _stark.toTransactionVersion)(this.getPreferredVersion(_api.ETransactionVersion.F1, _api.ETransactionVersion.F3), (0, _stark.toFeeVersion)(providedVersion));
78
+ const chainId = await this.getChainId();
79
+ const signerDetails = {
80
+ ...(0, _stark.v3Details)(details),
81
+ walletAddress: this.address,
82
+ nonce,
83
+ maxFee: _constants.ZERO,
84
+ version,
85
+ chainId,
86
+ cairoVersion: await this.getCairoVersion(),
87
+ skipValidate
88
+ };
89
+ const invocation = await this.buildInvocation(transactions, signerDetails);
90
+ return super.getInvokeEstimateFee({
91
+ ...invocation
92
+ }, {
93
+ ...(0, _stark.v3Details)(details),
94
+ version,
95
+ nonce
96
+ }, blockIdentifier, details.skipValidate);
97
+ }
98
+ async estimateDeclareFee(payload, details = {}) {
99
+ const {
100
+ blockIdentifier,
101
+ nonce: providedNonce,
102
+ version: providedVersion,
103
+ skipValidate = true
104
+ } = details;
105
+ const nonce = (0, _num.toBigInt)(providedNonce ?? (await this.getNonce()));
106
+ const version = (0, _stark.toTransactionVersion)(!(0, _contract.isSierra)(payload.contract) ? _api.ETransactionVersion.F1 : this.getPreferredVersion(_api.ETransactionVersion.F2, _api.ETransactionVersion.F3), (0, _stark.toFeeVersion)(providedVersion));
107
+ const chainId = await this.getChainId();
108
+ const declareContractTransaction = await this.buildDeclarePayload(payload, {
109
+ ...(0, _stark.v3Details)(details),
110
+ nonce,
111
+ chainId,
112
+ version,
113
+ walletAddress: this.address,
114
+ maxFee: _constants.ZERO,
115
+ cairoVersion: void 0,
116
+ // unused parameter
117
+ skipValidate
118
+ });
119
+ return super.getDeclareEstimateFee(declareContractTransaction, {
120
+ ...(0, _stark.v3Details)(details),
121
+ version,
122
+ nonce
123
+ }, blockIdentifier, details.skipValidate);
124
+ }
125
+ async estimateAccountDeployFee({
126
+ classHash,
127
+ addressSalt = 0,
128
+ constructorCalldata = [],
129
+ contractAddress
130
+ }, details = {}) {
131
+ const {
132
+ blockIdentifier,
133
+ version: providedVersion,
134
+ skipValidate = true
135
+ } = details;
136
+ const version = (0, _stark.toTransactionVersion)(this.getPreferredVersion(_api.ETransactionVersion.F1, _api.ETransactionVersion.F3), (0, _stark.toFeeVersion)(providedVersion));
137
+ const nonce = _constants.ZERO;
138
+ const chainId = await this.getChainId();
139
+ const payload = await this.buildAccountDeployPayload({
140
+ classHash,
141
+ addressSalt,
142
+ constructorCalldata,
143
+ contractAddress
144
+ }, {
145
+ ...(0, _stark.v3Details)(details),
146
+ nonce,
147
+ chainId,
148
+ version,
149
+ walletAddress: this.address,
150
+ // unused parameter
151
+ maxFee: _constants.ZERO,
152
+ cairoVersion: void 0,
153
+ // unused parameter,
154
+ skipValidate
155
+ });
156
+ return super.getDeployAccountEstimateFee({
157
+ ...payload
158
+ }, {
159
+ ...(0, _stark.v3Details)(details),
160
+ version,
161
+ nonce
162
+ }, blockIdentifier, details.skipValidate);
163
+ }
164
+ async estimateDeployFee(payload, details = {}) {
165
+ const calls = this.buildUDCContractPayload(payload);
166
+ return this.estimateInvokeFee(calls, details);
167
+ }
168
+ async estimateFeeBulk(invocations, details = {}) {
169
+ const {
170
+ nonce,
171
+ blockIdentifier,
172
+ version,
173
+ skipValidate
174
+ } = details;
175
+ const accountInvocations = await this.accountInvocationsFactory(invocations, {
176
+ ...(0, _stark.v3Details)(details),
177
+ versions: [_api.ETransactionVersion.F1,
178
+ // non-sierra
179
+ (0, _stark.toTransactionVersion)(this.getPreferredVersion(_api.ETransactionVersion.F2, _api.ETransactionVersion.F3), version)
180
+ // sierra
181
+ ],
182
+ nonce,
183
+ blockIdentifier,
184
+ skipValidate
185
+ });
186
+ return super.getEstimateFeeBulk(accountInvocations, {
187
+ blockIdentifier,
188
+ skipValidate
189
+ });
190
+ }
191
+ async simulateTransaction(invocations, details = {}) {
192
+ const {
193
+ nonce,
194
+ blockIdentifier,
195
+ skipValidate = true,
196
+ skipExecute,
197
+ version
198
+ } = details;
199
+ const accountInvocations = await this.accountInvocationsFactory(invocations, {
200
+ ...(0, _stark.v3Details)(details),
201
+ versions: [_api.ETransactionVersion.V1,
202
+ // non-sierra
203
+ (0, _stark.toTransactionVersion)(this.getPreferredVersion(_api.ETransactionVersion.V2, _api.ETransactionVersion.V3), version)],
204
+ nonce,
205
+ blockIdentifier,
206
+ skipValidate
207
+ });
208
+ return super.getSimulateTransaction(accountInvocations, {
209
+ blockIdentifier,
210
+ skipValidate,
211
+ skipExecute
212
+ });
213
+ }
214
+ async execute(transactions, arg2, transactionsDetail = {}) {
215
+ const details = arg2 === void 0 || Array.isArray(arg2) ? transactionsDetail : arg2;
216
+ const calls = Array.isArray(transactions) ? transactions : [transactions];
217
+ const nonce = (0, _num.toBigInt)(details.nonce ?? (await this.getNonce()));
218
+ const version = (0, _stark.toTransactionVersion)(this.getPreferredVersion(_api.ETransactionVersion.V1, _api.ETransactionVersion.V3),
219
+ // TODO: does this depend on cairo version ?
220
+ details.version);
221
+ const estimate = await this.getUniversalSuggestedFee(version, {
222
+ type: _types.TransactionType.INVOKE,
223
+ payload: transactions
224
+ }, {
225
+ ...details,
226
+ version
227
+ });
228
+ const chainId = await this.getChainId();
229
+ const signerDetails = {
230
+ ...(0, _stark.v3Details)(details),
231
+ resourceBounds: estimate.resourceBounds,
232
+ walletAddress: this.address,
233
+ nonce,
234
+ maxFee: estimate.maxFee,
235
+ version,
236
+ chainId,
237
+ cairoVersion: await this.getCairoVersion()
238
+ };
239
+ const signature = await this.signer.signTransaction(calls, signerDetails);
240
+ const calldata = (0, _transaction.getExecuteCalldata)(calls, await this.getCairoVersion());
241
+ return this.invokeFunction({
242
+ contractAddress: this.address,
243
+ calldata,
244
+ signature
245
+ }, {
246
+ ...(0, _stark.v3Details)(details),
247
+ resourceBounds: estimate.resourceBounds,
248
+ nonce,
249
+ maxFee: estimate.maxFee,
250
+ version
251
+ });
252
+ }
253
+ /**
254
+ * First check if contract is already declared, if not declare it
255
+ * If contract already declared returned transaction_hash is ''.
256
+ * Method will pass even if contract is already declared
257
+ * @param transactionsDetail (optional)
258
+ */
259
+ async declareIfNot(payload, transactionsDetail = {}) {
260
+ const declareContractPayload = (0, _contract.extractContractHashes)(payload);
261
+ try {
262
+ await this.getClassByHash(declareContractPayload.classHash);
263
+ } catch (error) {
264
+ return this.declare(payload, transactionsDetail);
265
+ }
266
+ return {
267
+ transaction_hash: "",
268
+ class_hash: declareContractPayload.classHash
269
+ };
270
+ }
271
+ async declare(payload, details = {}) {
272
+ const declareContractPayload = (0, _contract.extractContractHashes)(payload);
273
+ const {
274
+ nonce,
275
+ version: providedVersion
276
+ } = details;
277
+ const version = (0, _stark.toTransactionVersion)(!(0, _contract.isSierra)(payload.contract) ? _api.ETransactionVersion.V1 : this.getPreferredVersion(_api.ETransactionVersion.V2, _api.ETransactionVersion.V3), providedVersion);
278
+ const estimate = await this.getUniversalSuggestedFee(version, {
279
+ type: _types.TransactionType.DECLARE,
280
+ payload: declareContractPayload
281
+ }, {
282
+ ...details,
283
+ version
284
+ });
285
+ const declareDetails = {
286
+ ...(0, _stark.v3Details)(details),
287
+ resourceBounds: estimate.resourceBounds,
288
+ maxFee: estimate.maxFee,
289
+ nonce: (0, _num.toBigInt)(nonce ?? (await this.getNonce())),
290
+ version,
291
+ chainId: await this.getChainId(),
292
+ walletAddress: this.address,
293
+ cairoVersion: void 0
294
+ };
295
+ const declareContractTransaction = await this.buildDeclarePayload(declareContractPayload, declareDetails);
296
+ return this.declareContract(declareContractTransaction, declareDetails);
297
+ }
298
+ async deploy(payload, details = {}) {
299
+ const {
300
+ calls,
301
+ addresses
302
+ } = (0, _transaction.buildUDCCall)(payload, this.address);
303
+ const invokeResponse = await this.execute(calls, void 0, details);
304
+ return {
305
+ ...invokeResponse,
306
+ contract_address: addresses
307
+ };
308
+ }
309
+ async deployContract(payload, details = {}) {
310
+ const deployTx = await this.deploy(payload, details);
311
+ const txReceipt = await this.waitForTransaction(deployTx.transaction_hash);
312
+ return (0, _events.parseUDCEvent)(txReceipt);
313
+ }
314
+ async declareAndDeploy(payload, details = {}) {
315
+ const {
316
+ constructorCalldata,
317
+ salt,
318
+ unique
319
+ } = payload;
320
+ let declare = await this.declareIfNot(payload, details);
321
+ if (declare.transaction_hash !== "") {
322
+ const tx = await this.waitForTransaction(declare.transaction_hash);
323
+ declare = {
324
+ ...declare,
325
+ ...tx
326
+ };
327
+ }
328
+ const deploy = await this.deployContract({
329
+ classHash: declare.class_hash,
330
+ salt,
331
+ unique,
332
+ constructorCalldata
333
+ }, details);
334
+ return {
335
+ declare: {
336
+ ...declare
337
+ },
338
+ deploy
339
+ };
340
+ }
341
+ deploySelf = this.deployAccount;
342
+ async deployAccount({
343
+ classHash,
344
+ constructorCalldata = [],
345
+ addressSalt = 0,
346
+ contractAddress: providedContractAddress
347
+ }, details = {}) {
348
+ const version = (0, _stark.toTransactionVersion)(this.getPreferredVersion(_api.ETransactionVersion.V1, _api.ETransactionVersion.V3), details.version);
349
+ const nonce = _constants.ZERO;
350
+ const chainId = await this.getChainId();
351
+ const compiledCalldata = _calldata.CallData.compile(constructorCalldata);
352
+ const contractAddress = providedContractAddress ?? (0, _hash.calculateContractAddressFromHash)(addressSalt, classHash, compiledCalldata, 0);
353
+ const estimate = await this.getUniversalSuggestedFee(version, {
354
+ type: _types.TransactionType.DEPLOY_ACCOUNT,
355
+ payload: {
356
+ classHash,
357
+ constructorCalldata: compiledCalldata,
358
+ addressSalt,
359
+ contractAddress
360
+ }
361
+ }, details);
362
+ const signature = await this.signer.signDeployAccountTransaction({
363
+ ...(0, _stark.v3Details)(details),
364
+ classHash,
365
+ constructorCalldata: compiledCalldata,
366
+ contractAddress,
367
+ addressSalt,
368
+ chainId,
369
+ resourceBounds: estimate.resourceBounds,
370
+ maxFee: estimate.maxFee,
371
+ version,
372
+ nonce
373
+ });
374
+ return this.deployAccountContract({
375
+ classHash,
376
+ addressSalt,
377
+ constructorCalldata,
378
+ signature
379
+ }, {
380
+ ...(0, _stark.v3Details)(details),
381
+ nonce,
382
+ resourceBounds: estimate.resourceBounds,
383
+ maxFee: estimate.maxFee,
384
+ version
385
+ });
386
+ }
387
+ async signMessage(typedData) {
388
+ return this.signer.signMessage(typedData, this.address);
389
+ }
390
+ async hashMessage(typedData) {
391
+ return (0, _typedData.getMessageHash)(typedData, this.address);
392
+ }
393
+ async verifyMessageHash(hash, signature, signatureVerificationFunctionName, signatureVerificationResponse) {
394
+ const knownSigVerificationFName = signatureVerificationFunctionName ? [signatureVerificationFunctionName] : ["isValidSignature", "is_valid_signature"];
395
+ const knownSignatureResponse = signatureVerificationResponse || {
396
+ okResponse: [
397
+ // any non-nok response is true
398
+ ],
399
+ nokResponse: ["0x0",
400
+ // Devnet
401
+ "0x00"
402
+ // OpenZeppelin 0.7.0 to 0.9.0 invalid signature
403
+ ],
404
+ error: ["argent/invalid-signature",
405
+ // ArgentX 0.3.0 to 0.3.1
406
+ "is invalid, with respect to the public key",
407
+ // OpenZeppelin until 0.6.1, Braavos 0.0.11
408
+ "INVALID_SIG"
409
+ // Braavos 1.0.0
410
+ ]
411
+ };
412
+ let error;
413
+ for (const SigVerificationFName of knownSigVerificationFName) {
414
+ try {
415
+ const resp = await this.callContract({
416
+ contractAddress: this.address,
417
+ entrypoint: SigVerificationFName,
418
+ calldata: _calldata.CallData.compile({
419
+ hash: (0, _num.toBigInt)(hash).toString(),
420
+ signature: (0, _stark.formatSignature)(signature)
421
+ })
422
+ });
423
+ if (knownSignatureResponse.nokResponse.includes(resp[0].toString())) {
424
+ return false;
425
+ }
426
+ if (knownSignatureResponse.okResponse.length === 0 || knownSignatureResponse.okResponse.includes(resp[0].toString())) {
427
+ return true;
428
+ }
429
+ throw Error("signatureVerificationResponse Error: response is not part of known responses");
430
+ } catch (err) {
431
+ if (knownSignatureResponse.error.some(errMessage => err.message.includes(errMessage))) {
432
+ return false;
433
+ }
434
+ error = err;
435
+ }
436
+ }
437
+ throw Error(`Signature verification Error: ${error}`);
438
+ }
439
+ async verifyMessage(typedData, signature, signatureVerificationFunctionName, signatureVerificationResponse) {
440
+ const hash = await this.hashMessage(typedData);
441
+ return this.verifyMessageHash(hash, signature, signatureVerificationFunctionName, signatureVerificationResponse);
442
+ }
443
+ /*
444
+ * Support methods
445
+ */
446
+ async getUniversalSuggestedFee(version, {
447
+ type,
448
+ payload
449
+ }, details) {
450
+ let maxFee = 0;
451
+ let resourceBounds = (0, _stark.estimateFeeToBounds)(_constants.ZERO);
452
+ if (version === _api.ETransactionVersion.V3) {
453
+ resourceBounds = details.resourceBounds ?? (await this.getSuggestedFee({
454
+ type,
455
+ payload
456
+ }, details)).resourceBounds;
457
+ } else {
458
+ maxFee = details.maxFee ?? (await this.getSuggestedFee({
459
+ type,
460
+ payload
461
+ }, details)).suggestedMaxFee;
462
+ }
463
+ return {
464
+ maxFee,
465
+ resourceBounds
466
+ };
467
+ }
468
+ async getSuggestedFee({
469
+ type,
470
+ payload
471
+ }, details) {
472
+ let feeEstimate;
473
+ switch (type) {
474
+ case _types.TransactionType.INVOKE:
475
+ feeEstimate = await this.estimateInvokeFee(payload, details);
476
+ break;
477
+ case _types.TransactionType.DECLARE:
478
+ feeEstimate = await this.estimateDeclareFee(payload, details);
479
+ break;
480
+ case _types.TransactionType.DEPLOY_ACCOUNT:
481
+ feeEstimate = await this.estimateAccountDeployFee(payload, details);
482
+ break;
483
+ case _types.TransactionType.DEPLOY:
484
+ feeEstimate = await this.estimateDeployFee(payload, details);
485
+ break;
486
+ default:
487
+ feeEstimate = {
488
+ gas_consumed: 0n,
489
+ gas_price: 0n,
490
+ overall_fee: _constants.ZERO,
491
+ unit: "FRI",
492
+ suggestedMaxFee: _constants.ZERO,
493
+ resourceBounds: (0, _stark.estimateFeeToBounds)(_constants.ZERO),
494
+ data_gas_consumed: 0n,
495
+ data_gas_price: 0n
496
+ };
497
+ break;
498
+ }
499
+ return feeEstimate;
500
+ }
501
+ async buildInvocation(call, details) {
502
+ const calldata = (0, _transaction.getExecuteCalldata)(call, await this.getCairoVersion());
503
+ const signature = !details.skipValidate ? await this.signer.signTransaction(call, details) : [];
504
+ return {
505
+ ...(0, _stark.v3Details)(details),
506
+ contractAddress: this.address,
507
+ calldata,
508
+ signature
509
+ };
510
+ }
511
+ async buildDeclarePayload(payload, details) {
512
+ const {
513
+ classHash,
514
+ contract,
515
+ compiledClassHash
516
+ } = (0, _contract.extractContractHashes)(payload);
517
+ const compressedCompiledContract = (0, _provider2.parseContract)(contract);
518
+ if (typeof compiledClassHash === "undefined" && (details.version === _api.ETransactionVersion3.F3 || details.version === _api.ETransactionVersion3.V3)) {
519
+ throw Error("V3 Transaction work with Cairo1 Contracts and require compiledClassHash");
520
+ }
521
+ const signature = !details.skipValidate ? await this.signer.signDeclareTransaction({
522
+ ...details,
523
+ ...(0, _stark.v3Details)(details),
524
+ classHash,
525
+ compiledClassHash,
526
+ // TODO: TS, cast because optional for v2 and required for v3, thrown if not present
527
+ senderAddress: details.walletAddress
528
+ }) : [];
529
+ return {
530
+ senderAddress: details.walletAddress,
531
+ signature,
532
+ contract: compressedCompiledContract,
533
+ compiledClassHash
534
+ };
535
+ }
536
+ async buildAccountDeployPayload({
537
+ classHash,
538
+ addressSalt = 0,
539
+ constructorCalldata = [],
540
+ contractAddress: providedContractAddress
541
+ }, details) {
542
+ const compiledCalldata = _calldata.CallData.compile(constructorCalldata);
543
+ const contractAddress = providedContractAddress ?? (0, _hash.calculateContractAddressFromHash)(addressSalt, classHash, compiledCalldata, 0);
544
+ const signature = !details.skipValidate ? await this.signer.signDeployAccountTransaction({
545
+ ...details,
546
+ ...(0, _stark.v3Details)(details),
547
+ classHash,
548
+ contractAddress,
549
+ addressSalt,
550
+ constructorCalldata: compiledCalldata
551
+ }) : [];
552
+ return {
553
+ ...(0, _stark.v3Details)(details),
554
+ classHash,
555
+ addressSalt,
556
+ constructorCalldata: compiledCalldata,
557
+ signature
558
+ };
559
+ }
560
+ buildUDCContractPayload(payload) {
561
+ const calls = [].concat(payload).map(it => {
562
+ const {
563
+ classHash,
564
+ salt = "0",
565
+ unique = true,
566
+ constructorCalldata = []
567
+ } = it;
568
+ const compiledConstructorCallData = _calldata.CallData.compile(constructorCalldata);
569
+ return {
570
+ contractAddress: _constants.UDC.ADDRESS,
571
+ entrypoint: _constants.UDC.ENTRYPOINT,
572
+ calldata: [classHash, salt, (0, _num.toCairoBool)(unique), compiledConstructorCallData.length, ...compiledConstructorCallData]
573
+ };
574
+ });
575
+ return calls;
576
+ }
577
+ async accountInvocationsFactory(invocations, details) {
578
+ const {
579
+ nonce,
580
+ blockIdentifier,
581
+ skipValidate = true
582
+ } = details;
583
+ const safeNonce = await this.getNonceSafe(nonce);
584
+ const chainId = await this.getChainId();
585
+ const versions = details.versions.map(it => (0, _stark.toTransactionVersion)(it));
586
+ const tx0Payload = "payload" in invocations[0] ? invocations[0].payload : invocations[0];
587
+ const cairoVersion = invocations[0].type === _types.TransactionType.DEPLOY_ACCOUNT ? await this.getCairoVersion(tx0Payload.classHash) : await this.getCairoVersion();
588
+ return Promise.all([].concat(invocations).map(async (transaction, index) => {
589
+ const txPayload = "payload" in transaction ? transaction.payload : transaction;
590
+ const signerDetails = {
591
+ ...(0, _stark.v3Details)(details),
592
+ walletAddress: this.address,
593
+ nonce: (0, _num.toBigInt)(Number(safeNonce) + index),
594
+ maxFee: _constants.ZERO,
595
+ chainId,
596
+ cairoVersion,
597
+ version: "",
598
+ skipValidate
599
+ };
600
+ const common = {
601
+ type: transaction.type,
602
+ nonce: (0, _num.toBigInt)(Number(safeNonce) + index),
603
+ blockIdentifier,
604
+ version: ""
605
+ };
606
+ if (transaction.type === _types.TransactionType.INVOKE) {
607
+ const versionX = (0, _stark.reduceV2)(versions[1]);
608
+ signerDetails.version = versionX;
609
+ common.version = versionX;
610
+ const payload = await this.buildInvocation([].concat(txPayload), signerDetails);
611
+ return {
612
+ ...common,
613
+ ...payload
614
+ };
615
+ }
616
+ if (transaction.type === _types.TransactionType.DEPLOY) {
617
+ const versionX = (0, _stark.reduceV2)(versions[1]);
618
+ signerDetails.version = versionX;
619
+ common.version = versionX;
620
+ const calls = this.buildUDCContractPayload(txPayload);
621
+ const payload = await this.buildInvocation(calls, signerDetails);
622
+ return {
623
+ ...common,
624
+ ...payload,
625
+ type: _types.TransactionType.INVOKE
626
+ };
627
+ }
628
+ if (transaction.type === _types.TransactionType.DECLARE) {
629
+ const versionX = !(0, _contract.isSierra)(txPayload.contract) ? versions[0] : versions[1];
630
+ signerDetails.version = versionX;
631
+ common.version = versionX;
632
+ const payload = await this.buildDeclarePayload(txPayload, signerDetails);
633
+ return {
634
+ ...common,
635
+ ...payload
636
+ };
637
+ }
638
+ if (transaction.type === _types.TransactionType.DEPLOY_ACCOUNT) {
639
+ const versionX = (0, _stark.reduceV2)(versions[1]);
640
+ signerDetails.version = versionX;
641
+ common.version = versionX;
642
+ const payload = await this.buildAccountDeployPayload(txPayload, signerDetails);
643
+ return {
644
+ ...common,
645
+ ...payload
646
+ };
647
+ }
648
+ throw Error(`accountInvocationsFactory: unsupported transaction type: ${transaction}`);
649
+ }));
650
+ }
651
+ async getStarkName(address = this.address, StarknetIdContract) {
652
+ return super.getStarkName(address, StarknetIdContract);
653
+ }
654
+ }
655
+ exports.Account = Account;