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