@aeternity/aepp-sdk 11.0.1 → 12.0.0

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 (376) hide show
  1. package/LICENSE +1 -1
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +12 -19
  4. package/dist/aepp-sdk.browser-script.js.map +1 -1
  5. package/dist/aepp-sdk.browser.js +1 -1
  6. package/dist/aepp-sdk.browser.js.map +1 -1
  7. package/dist/aepp-sdk.js +1 -1
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/AeSdk.d.ts +37 -0
  10. package/es/AeSdk.mjs +81 -0
  11. package/es/AeSdk.mjs.map +1 -0
  12. package/es/AeSdkAepp.d.ts +69 -0
  13. package/es/AeSdkAepp.mjs +175 -0
  14. package/es/AeSdkAepp.mjs.map +1 -0
  15. package/es/AeSdkBase.d.ts +212 -0
  16. package/es/AeSdkBase.mjs +310 -0
  17. package/es/AeSdkBase.mjs.map +1 -0
  18. package/es/AeSdkWallet.d.ts +103 -0
  19. package/es/AeSdkWallet.mjs +322 -0
  20. package/es/AeSdkWallet.mjs.map +1 -0
  21. package/es/Node.d.ts +44 -0
  22. package/es/Node.mjs +141 -0
  23. package/es/Node.mjs.map +1 -0
  24. package/es/account/Base.d.ts +65 -0
  25. package/es/account/Base.mjs +123 -0
  26. package/es/account/Base.mjs.map +1 -0
  27. package/es/account/Memory.d.ts +25 -0
  28. package/es/account/Memory.mjs +81 -0
  29. package/es/account/Memory.mjs.map +1 -0
  30. package/es/account/Rpc.d.ts +27 -0
  31. package/es/account/Rpc.mjs +79 -0
  32. package/es/account/Rpc.mjs.map +1 -0
  33. package/es/aens.d.ts +209 -0
  34. package/es/aens.mjs +332 -0
  35. package/es/aens.mjs.map +1 -0
  36. package/es/aepp-wallet-communication/connection/Browser.d.ts +32 -0
  37. package/es/aepp-wallet-communication/connection/Browser.mjs +70 -0
  38. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
  39. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +17 -0
  40. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +57 -0
  41. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
  42. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +35 -0
  43. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +142 -0
  44. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
  45. package/es/aepp-wallet-communication/connection-proxy.d.ts +10 -0
  46. package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +15 -11
  47. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
  48. package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +33 -0
  49. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +169 -0
  50. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -0
  51. package/es/aepp-wallet-communication/rpc/types.d.ts +77 -0
  52. package/es/aepp-wallet-communication/rpc/types.mjs +3 -0
  53. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -0
  54. package/es/aepp-wallet-communication/schema.d.ts +90 -46
  55. package/es/aepp-wallet-communication/schema.mjs +214 -0
  56. package/es/aepp-wallet-communication/schema.mjs.map +1 -0
  57. package/es/aepp-wallet-communication/wallet-detector.d.ts +24 -0
  58. package/es/aepp-wallet-communication/wallet-detector.mjs +63 -0
  59. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  60. package/es/apis/compiler/compiler.d.ts +92 -0
  61. package/es/apis/compiler/compiler.mjs +576 -0
  62. package/es/apis/compiler/compiler.mjs.map +1 -0
  63. package/es/apis/compiler/index.d.ts +2 -0
  64. package/es/apis/compiler/index.mjs +3 -0
  65. package/es/apis/compiler/index.mjs.map +1 -0
  66. package/es/apis/compiler/models/index.d.ts +248 -0
  67. package/es/apis/compiler/models/index.mjs +48 -0
  68. package/es/apis/compiler/models/index.mjs.map +1 -0
  69. package/es/apis/compiler/models/mappers.d.ts +23 -0
  70. package/es/apis/compiler/models/mappers.mjs +585 -0
  71. package/es/apis/compiler/models/mappers.mjs.map +1 -0
  72. package/es/apis/compiler/models/parameters.d.ts +13 -0
  73. package/es/apis/compiler/models/parameters.mjs +71 -0
  74. package/es/apis/compiler/models/parameters.mjs.map +1 -0
  75. package/es/apis/node/index.d.ts +2 -0
  76. package/es/apis/node/index.mjs +3 -0
  77. package/es/apis/node/index.mjs.map +1 -0
  78. package/es/apis/node/models/index.d.ts +1061 -0
  79. package/es/apis/node/models/index.mjs +2 -0
  80. package/es/apis/node/models/index.mjs.map +1 -0
  81. package/es/apis/node/models/mappers.d.ts +95 -0
  82. package/es/apis/node/models/mappers.mjs +4164 -0
  83. package/es/apis/node/models/mappers.mjs.map +1 -0
  84. package/es/apis/node/models/parameters.d.ts +17 -0
  85. package/es/apis/node/models/parameters.mjs +165 -0
  86. package/es/apis/node/models/parameters.mjs.map +1 -0
  87. package/es/apis/node/node.d.ts +215 -0
  88. package/es/apis/node/node.mjs +1165 -0
  89. package/es/apis/node/node.mjs.map +1 -0
  90. package/es/chain.d.ts +220 -0
  91. package/es/chain.mjs +524 -0
  92. package/es/chain.mjs.map +1 -0
  93. package/es/channel/handlers.d.ts +34 -0
  94. package/es/channel/handlers.mjs +147 -112
  95. package/es/channel/handlers.mjs.map +1 -1
  96. package/es/channel/index.d.ts +634 -0
  97. package/es/channel/index.mjs +898 -900
  98. package/es/channel/index.mjs.map +1 -1
  99. package/es/channel/internal.d.ts +100 -0
  100. package/es/channel/internal.mjs +97 -51
  101. package/es/channel/internal.mjs.map +1 -1
  102. package/es/contract/Compiler.d.ts +17 -0
  103. package/es/contract/Compiler.mjs +67 -0
  104. package/es/contract/Compiler.mjs.map +1 -0
  105. package/es/contract/aci.d.ts +125 -0
  106. package/es/contract/aci.mjs +199 -180
  107. package/es/contract/aci.mjs.map +1 -1
  108. package/es/contract/ga.d.ts +68 -0
  109. package/es/contract/ga.mjs +190 -0
  110. package/es/contract/ga.mjs.map +1 -0
  111. package/es/contract/methods.d.ts +68 -0
  112. package/es/contract/methods.mjs +101 -0
  113. package/es/contract/methods.mjs.map +1 -0
  114. package/es/index.d.ts +32 -0
  115. package/es/index.mjs +32 -40
  116. package/es/index.mjs.map +1 -1
  117. package/es/oracle.d.ts +154 -0
  118. package/es/oracle.mjs +288 -0
  119. package/es/oracle.mjs.map +1 -0
  120. package/es/spend.d.ts +61 -0
  121. package/es/spend.mjs +122 -0
  122. package/es/spend.mjs.map +1 -0
  123. package/es/tx/builder/constants.d.ts +41 -0
  124. package/es/tx/builder/constants.mjs +11 -19
  125. package/es/tx/builder/constants.mjs.map +1 -1
  126. package/es/tx/builder/field-types.d.ts +62 -0
  127. package/es/tx/builder/field-types.mjs +62 -10
  128. package/es/tx/builder/field-types.mjs.map +1 -1
  129. package/es/tx/builder/helpers.d.ts +131 -0
  130. package/es/tx/builder/helpers.mjs +71 -169
  131. package/es/tx/builder/helpers.mjs.map +1 -1
  132. package/es/tx/builder/index.d.ts +75 -0
  133. package/es/tx/builder/index.mjs +141 -323
  134. package/es/tx/builder/index.mjs.map +1 -1
  135. package/es/tx/builder/schema.d.ts +350 -0
  136. package/es/tx/builder/schema.mjs +173 -510
  137. package/es/tx/builder/schema.mjs.map +1 -1
  138. package/es/tx/index.d.ts +63 -0
  139. package/es/tx/index.mjs +171 -265
  140. package/es/tx/index.mjs.map +1 -1
  141. package/es/tx/min-fee.d.ts +20 -0
  142. package/es/tx/min-fee.mjs +148 -0
  143. package/es/tx/min-fee.mjs.map +1 -0
  144. package/es/tx/validator.d.ts +19 -0
  145. package/es/tx/validator.mjs +64 -71
  146. package/es/tx/validator.mjs.map +1 -1
  147. package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
  148. package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
  149. package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
  150. package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
  151. package/es/typings/bip32-path/index.d.mjs +2 -0
  152. package/es/typings/bip32-path/index.d.mjs.map +1 -0
  153. package/es/typings/blakejs/index.d.mjs.map +1 -1
  154. package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
  155. package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
  156. package/es/utils/amount-formatter.d.ts +42 -0
  157. package/es/utils/amount-formatter.mjs +28 -41
  158. package/es/utils/amount-formatter.mjs.map +1 -1
  159. package/es/utils/autorest.d.ts +6 -0
  160. package/es/utils/autorest.mjs +97 -0
  161. package/es/utils/autorest.mjs.map +1 -0
  162. package/es/utils/bignumber.d.ts +13 -0
  163. package/es/utils/bignumber.mjs +10 -8
  164. package/es/utils/bignumber.mjs.map +1 -1
  165. package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
  166. package/es/utils/bytes.mjs +10 -14
  167. package/es/utils/bytes.mjs.map +1 -1
  168. package/es/utils/crypto.d.ts +103 -0
  169. package/es/utils/crypto.mjs +60 -68
  170. package/es/utils/crypto.mjs.map +1 -1
  171. package/es/utils/encoder.d.ts +26 -0
  172. package/es/utils/encoder.mjs +47 -51
  173. package/es/utils/encoder.mjs.map +1 -1
  174. package/es/{errors.d.ts → utils/errors.d.ts} +254 -57
  175. package/es/utils/errors.mjs +318 -125
  176. package/es/utils/errors.mjs.map +1 -1
  177. package/es/utils/hd-wallet.d.ts +34 -0
  178. package/es/utils/hd-wallet.mjs +27 -16
  179. package/es/utils/hd-wallet.mjs.map +1 -1
  180. package/es/utils/json-big.d.ts +5 -0
  181. package/es/utils/json-big.mjs +10 -14
  182. package/es/utils/json-big.mjs.map +1 -1
  183. package/es/utils/keystore.d.ts +51 -0
  184. package/es/utils/keystore.mjs +98 -193
  185. package/es/utils/keystore.mjs.map +1 -1
  186. package/es/{mptree.d.ts → utils/mptree.d.ts} +5 -8
  187. package/es/utils/mptree.mjs +13 -14
  188. package/es/utils/mptree.mjs.map +1 -1
  189. package/es/utils/other.d.ts +14 -0
  190. package/es/utils/other.mjs +21 -36
  191. package/es/utils/other.mjs.map +1 -1
  192. package/es/{semver-satisfies.d.ts → utils/semver-satisfies.d.ts} +0 -0
  193. package/es/utils/semver-satisfies.mjs.map +1 -1
  194. package/es/utils/string.d.ts +24 -0
  195. package/es/utils/string.mjs +8 -10
  196. package/es/utils/string.mjs.map +1 -1
  197. package/package.json +49 -39
  198. package/src/AeSdk.ts +65 -0
  199. package/src/AeSdkAepp.ts +167 -0
  200. package/src/AeSdkBase.ts +320 -0
  201. package/src/AeSdkWallet.ts +332 -0
  202. package/src/Node.ts +167 -0
  203. package/src/account/Base.ts +114 -0
  204. package/src/account/Memory.ts +83 -0
  205. package/src/account/Rpc.ts +67 -0
  206. package/src/aens.ts +391 -0
  207. package/src/aepp-wallet-communication/connection/Browser.ts +68 -0
  208. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +58 -0
  209. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +111 -0
  210. package/{es/utils/crypto-ts.mjs → src/aepp-wallet-communication/connection-proxy.ts} +16 -17
  211. package/src/aepp-wallet-communication/rpc/RpcClient.ts +137 -0
  212. package/src/aepp-wallet-communication/rpc/types.ts +66 -0
  213. package/src/aepp-wallet-communication/schema.ts +181 -0
  214. package/src/aepp-wallet-communication/wallet-detector.ts +71 -0
  215. package/src/apis/compiler/code-model-v4.yaml +2649 -0
  216. package/src/apis/compiler/compiler.ts +585 -0
  217. package/src/apis/compiler/index.ts +2 -0
  218. package/src/apis/compiler/models/index.ts +301 -0
  219. package/src/apis/compiler/models/mappers.ts +583 -0
  220. package/src/apis/compiler/models/parameters.ts +93 -0
  221. package/src/apis/node/code-model-v4.yaml +10046 -0
  222. package/src/apis/node/index.ts +2 -0
  223. package/src/apis/node/models/index.ts +1253 -0
  224. package/src/apis/node/models/mappers.ts +4278 -0
  225. package/src/apis/node/models/parameters.ts +188 -0
  226. package/src/apis/node/node.ts +1299 -0
  227. package/src/chain.ts +444 -0
  228. package/src/channel/{handlers.js → handlers.ts} +220 -128
  229. package/src/channel/index.ts +991 -0
  230. package/src/channel/internal.ts +345 -0
  231. package/src/contract/Compiler.ts +66 -0
  232. package/src/contract/aci.ts +529 -0
  233. package/src/contract/ga.ts +178 -0
  234. package/src/contract/methods.ts +118 -0
  235. package/src/index.ts +51 -0
  236. package/src/oracle.ts +342 -0
  237. package/src/spend.ts +152 -0
  238. package/src/tx/builder/{constants.js → constants.ts} +12 -16
  239. package/src/tx/builder/field-types.ts +111 -0
  240. package/src/tx/builder/helpers.ts +253 -0
  241. package/src/tx/builder/index.ts +394 -0
  242. package/src/tx/builder/schema.ts +771 -0
  243. package/src/tx/index.ts +199 -0
  244. package/src/tx/min-fee.ts +136 -0
  245. package/src/tx/validator.ts +226 -0
  246. package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
  247. package/src/typings/@aeternity__uuid/index.d.ts +3 -0
  248. package/src/typings/bip32-path/index.d.ts +33 -0
  249. package/src/typings/tweetnacl-auth/index.d.ts +14 -0
  250. package/src/utils/amount-formatter.ts +29 -42
  251. package/src/utils/autorest.ts +90 -0
  252. package/src/utils/bignumber.ts +9 -11
  253. package/src/utils/bytes.ts +12 -14
  254. package/src/utils/crypto.ts +217 -0
  255. package/src/utils/encoder.ts +52 -55
  256. package/src/utils/errors.ts +268 -134
  257. package/src/utils/hd-wallet.ts +134 -0
  258. package/src/utils/json-big.ts +26 -0
  259. package/src/utils/keystore.ts +179 -0
  260. package/src/utils/mptree.ts +14 -14
  261. package/src/utils/other.ts +28 -43
  262. package/src/utils/string.ts +8 -10
  263. package/es/account/base.mjs +0 -179
  264. package/es/account/base.mjs.map +0 -1
  265. package/es/account/memory.mjs +0 -99
  266. package/es/account/memory.mjs.map +0 -1
  267. package/es/account/multiple.mjs +0 -179
  268. package/es/account/multiple.mjs.map +0 -1
  269. package/es/ae/aens.mjs +0 -404
  270. package/es/ae/aens.mjs.map +0 -1
  271. package/es/ae/aepp.mjs +0 -45
  272. package/es/ae/aepp.mjs.map +0 -1
  273. package/es/ae/contract.mjs +0 -159
  274. package/es/ae/contract.mjs.map +0 -1
  275. package/es/ae/index.mjs +0 -207
  276. package/es/ae/index.mjs.map +0 -1
  277. package/es/ae/oracle.mjs +0 -339
  278. package/es/ae/oracle.mjs.map +0 -1
  279. package/es/ae/universal.mjs +0 -45
  280. package/es/ae/universal.mjs.map +0 -1
  281. package/es/ae/wallet.mjs +0 -50
  282. package/es/ae/wallet.mjs.map +0 -1
  283. package/es/amount-formatter.d.ts +0 -58
  284. package/es/bignumber.d.ts +0 -18
  285. package/es/chain/index.mjs +0 -272
  286. package/es/chain/index.mjs.map +0 -1
  287. package/es/chain/node.mjs +0 -442
  288. package/es/chain/node.mjs.map +0 -1
  289. package/es/contract/compiler.mjs +0 -115
  290. package/es/contract/compiler.mjs.map +0 -1
  291. package/es/contract/ga/helpers.mjs +0 -30
  292. package/es/contract/ga/helpers.mjs.map +0 -1
  293. package/es/contract/ga/index.mjs +0 -178
  294. package/es/contract/ga/index.mjs.map +0 -1
  295. package/es/crypto-ts.d.ts +0 -9
  296. package/es/encoder.d.ts +0 -26
  297. package/es/node-pool/index.mjs +0 -188
  298. package/es/node-pool/index.mjs.map +0 -1
  299. package/es/node.mjs +0 -133
  300. package/es/node.mjs.map +0 -1
  301. package/es/other.d.ts +0 -31
  302. package/es/string.d.ts +0 -26
  303. package/es/tx/tx-object.mjs +0 -283
  304. package/es/tx/tx-object.mjs.map +0 -1
  305. package/es/tx/tx.mjs +0 -938
  306. package/es/tx/tx.mjs.map +0 -1
  307. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs +0 -132
  308. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +0 -1
  309. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +0 -183
  310. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +0 -1
  311. package/es/utils/aepp-wallet-communication/connection/index.mjs +0 -87
  312. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +0 -1
  313. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs +0 -98
  314. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +0 -1
  315. package/es/utils/aepp-wallet-communication/helpers.mjs +0 -92
  316. package/es/utils/aepp-wallet-communication/helpers.mjs.map +0 -1
  317. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +0 -375
  318. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +0 -1
  319. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +0 -275
  320. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +0 -1
  321. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +0 -541
  322. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +0 -1
  323. package/es/utils/aepp-wallet-communication/schema.mjs +0 -102
  324. package/es/utils/aepp-wallet-communication/schema.mjs.map +0 -1
  325. package/es/utils/aepp-wallet-communication/wallet-detector.mjs +0 -110
  326. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +0 -1
  327. package/es/utils/async-init.mjs +0 -64
  328. package/es/utils/async-init.mjs.map +0 -1
  329. package/es/utils/crypto-ts.mjs.map +0 -1
  330. package/es/utils/swagger.mjs +0 -164
  331. package/es/utils/swagger.mjs.map +0 -1
  332. package/src/account/base.js +0 -153
  333. package/src/account/memory.js +0 -83
  334. package/src/account/multiple.js +0 -162
  335. package/src/ae/aens.js +0 -361
  336. package/src/ae/aepp.js +0 -45
  337. package/src/ae/contract.js +0 -148
  338. package/src/ae/index.js +0 -168
  339. package/src/ae/oracle.js +0 -311
  340. package/src/ae/universal.js +0 -47
  341. package/src/ae/wallet.js +0 -50
  342. package/src/chain/index.js +0 -269
  343. package/src/chain/node.js +0 -320
  344. package/src/channel/index.js +0 -903
  345. package/src/channel/internal.js +0 -236
  346. package/src/contract/aci.js +0 -376
  347. package/src/contract/compiler.js +0 -100
  348. package/src/contract/ga/helpers.js +0 -19
  349. package/src/contract/ga/index.js +0 -150
  350. package/src/index.js +0 -89
  351. package/src/node-pool/index.js +0 -172
  352. package/src/node.js +0 -116
  353. package/src/tx/builder/field-types.js +0 -61
  354. package/src/tx/builder/helpers.js +0 -334
  355. package/src/tx/builder/index.js +0 -465
  356. package/src/tx/builder/schema.js +0 -1100
  357. package/src/tx/index.js +0 -301
  358. package/src/tx/tx-object.js +0 -187
  359. package/src/tx/tx.js +0 -631
  360. package/src/tx/validator.js +0 -181
  361. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -119
  362. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -165
  363. package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
  364. package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -86
  365. package/src/utils/aepp-wallet-communication/helpers.js +0 -60
  366. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -294
  367. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -232
  368. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -401
  369. package/src/utils/aepp-wallet-communication/schema.ts +0 -80
  370. package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -92
  371. package/src/utils/async-init.js +0 -45
  372. package/src/utils/crypto.js +0 -219
  373. package/src/utils/hd-wallet.js +0 -100
  374. package/src/utils/json-big.js +0 -26
  375. package/src/utils/keystore.js +0 -219
  376. package/src/utils/swagger.js +0 -156
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/contract/aci.js"],"names":["DRY_RUN_ACCOUNT","GAS_MAX","TxObject","decode","MissingContractDefError","MissingContractAddressError","InactiveContractError","BytecodeMismatchError","InternalError","DuplicateContractError","MissingFunctionNameError","InvalidMethodInvocationError","NotPayableFunctionError","TypeError","NodeInvocationError","IllegalArgumentError","NoSuchContractFunctionError","MissingEventDefinitionError","AmbiguousEventDefinitionError","hash","getContractInstance","source","bytecode","aci","_aci","contractAddress","filesystem","validateBytecode","otherOptions","compilerApi","generateACI","code","options","resolveName","resolveByNode","contract","getContract","active","instance","_name","encoded_aci","name","calldata","Calldata","external_encoded_aci","deployInfo","address","Ae","defaults","callStatic","compilerVersion","onChanBytecode","getContractByteCode","isValid","validateByteCode","then","res","Object","entries","length","compile","compileContract","sendAndProcess","tx","txData","send","result","rawTx","waitMined","callInfo","api","getTransactionInfoByHash","assign","handleCallError","returnType","returnValue","message","decodeFateString","toString","_estimateGas","params","gasUsed","call","Math","floor","deploy","opt","ownerId","contractId","contractCreateTx","gas","callData","encode","freeze","owner","transaction","getFunctionACI","fn","functions","find","f","payable","fnACI","amount","callerId","catch","error","pub","top","getKeyBlock","txOpt","nonce","getAccount","contractCallTx","callObj","dryRunOther","txDryRun","decodedResult","returns","decodedEvents","decodeEvents","log","getContractNameByEvent","nameHash","contractAddressToName","addressToName","matchedEvents","filter","event","map","variant","events","keys","flat","eventName","BigInt","omitUnknown","topics","t","contractName","decoded","decodeEvent","data","args","e","methods","fromEntries","arguments","aciArgs","stateful","genHandler","pop","get"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA,mCAAoC,0BAApC;;;;SACSA,e,EAAiBC,O;OACnBC,Q;SACEC,M;SAEPC,uB,EACAC,2B,EACAC,qB,EACAC,qB,EACAC,a,EACAC,sB,EACAC,wB,EACAC,4B,EACAC,uB,EACAC,S,EACAC,mB,EACAC,oB,EACAC,2B,EACAC,2B,EACAC,6B;SAEOC,I;AAET;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,eAAeC,mBAAf,GAQP;AAAA;;AAAA,MAR2C;AACjDC,IAAAA,MADiD;AAEjDC,IAAAA,QAFiD;AAGjDC,IAAAA,GAAG,EAAEC,IAH4C;AAI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AAEErF,MAAAA,IAAI,EAAEqF,UAAU,CAAC,KAAD;AAFlB,KAFF,CAFK,CAAP;AAUD,GAlBmC,CAAnB,CAAnB;AAqBA,SAAOhH,QAAP;AACD","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * ContractACI module\n *\n * @module @aeternity/aepp-sdk/es/contract/aci\n * @export getContractInstance\n */\n\nimport { Encoder as Calldata } from '@aeternity/aepp-calldata'\nimport { DRY_RUN_ACCOUNT, GAS_MAX } from '../tx/builder/schema'\nimport TxObject from '../tx/tx-object'\nimport { decode } from '../tx/builder/helpers'\nimport {\n MissingContractDefError,\n MissingContractAddressError,\n InactiveContractError,\n BytecodeMismatchError,\n InternalError,\n DuplicateContractError,\n MissingFunctionNameError,\n InvalidMethodInvocationError,\n NotPayableFunctionError,\n TypeError,\n NodeInvocationError,\n IllegalArgumentError,\n NoSuchContractFunctionError,\n MissingEventDefinitionError,\n AmbiguousEventDefinitionError\n} from '../utils/errors'\nimport { hash } from '../utils/crypto-ts'\n\n/**\n * Generate contract ACI object with predefined js methods for contract usage - can be used for\n * creating a reference to already deployed contracts\n * @alias module:@aeternity/aepp-sdk/es/contract/aci\n * @param {Object} [options={}] Options object\n * @param {String} [options.source] Contract source code\n * @param {String} [options.bytecode] Contract bytecode\n * @param {Object} [options.aci] Contract ACI\n * @param {String} [options.contractAddress] Contract address\n * @param {Object} [options.filesystem] Contact source external namespaces map\n * @param {Boolean} [options.validateBytecode] Compare source code with on-chain version\n * @return {ContractInstance} JS Contract API\n * @example\n * const contractIns = await aeSdk.getContractInstance({ source })\n * await contractIns.deploy([321]) or await contractIns.methods.init(321)\n * const callResult = await contractIns.call('setState', [123]) or\n * await contractIns.methods.setState.send(123, options)\n * const staticCallResult = await contractIns.call('setState', [123], { callStatic: true }) or\n * await contractIns.methods.setState.get(123, options)\n * Also you can call contract like: await contractIns.methods.setState(123, options)\n * Then sdk decide to make on-chain or static call(dry-run API) transaction based on function is\n * stateful or not\n */\nexport default async function getContractInstance ({\n source,\n bytecode,\n aci: _aci,\n contractAddress,\n filesystem = {},\n validateBytecode,\n ...otherOptions\n} = {}) {\n if (!_aci && source) {\n _aci = await this.compilerApi.generateACI({ code: source, options: { filesystem } })\n }\n if (!_aci) throw new MissingContractDefError()\n contractAddress = contractAddress && await this.resolveName(\n contractAddress, 'contract_pubkey', { resolveByNode: true }\n )\n if (!contractAddress && !source && !bytecode) {\n throw new MissingContractAddressError('Can\\'t create instance by ACI without address')\n }\n\n if (contractAddress) {\n const contract = await this.getContract(contractAddress)\n if (!contract.active) throw new InactiveContractError(contractAddress)\n }\n\n const instance = {\n _aci,\n _name: _aci.encoded_aci.contract.name,\n calldata: new Calldata([_aci.encoded_aci, ..._aci.external_encoded_aci]),\n source,\n bytecode,\n deployInfo: { address: contractAddress },\n options: {\n ...this.Ae.defaults,\n callStatic: false,\n filesystem,\n ...otherOptions\n },\n compilerVersion: this.compilerVersion\n }\n\n if (validateBytecode) {\n if (!contractAddress) throw new MissingContractAddressError('Can\\'t validate bytecode without contract address')\n const onChanBytecode = (await this.getContractByteCode(contractAddress)).bytecode\n const isValid = source\n ? await this.compilerApi.validateByteCode(\n { bytecode: onChanBytecode, source, options: instance.options }\n ).then((res) => Object.entries(res).length === 0, () => false)\n : bytecode === onChanBytecode\n if (!isValid) throw new BytecodeMismatchError(source ? 'source' : 'bytecode')\n }\n\n /**\n * Compile contract\n * @alias module:@aeternity/aepp-sdk/es/contract/aci\n * @rtype () => ContractInstance: Object\n * @return {String} bytecode bytecode\n */\n instance.compile = async (options = {}) => {\n if (instance.bytecode) throw new IllegalArgumentError('Contract already compiled')\n if (!instance.source) throw new IllegalArgumentError('Can\\'t compile without source code')\n const { bytecode } = await this.compilerApi.compileContract({\n code: instance.source, options: { ...instance.options, ...options }\n })\n instance.bytecode = bytecode\n return instance.bytecode\n }\n\n const sendAndProcess = async (tx, options) => {\n const txData = await this.send(tx, options)\n const result = {\n hash: txData.hash, tx: TxObject({ tx: txData.rawTx }), txData, rawTx: txData.rawTx\n }\n if (options.waitMined === false) return result\n const { callInfo } = await this.api.getTransactionInfoByHash(txData.hash)\n Object.assign(result.txData, callInfo) // TODO: don't duplicate data in result\n await handleCallError(callInfo)\n return { ...result, result: callInfo }\n }\n\n const handleCallError = ({ returnType, returnValue }) => {\n let message\n // TODO: ensure that it works correctly https://github.com/aeternity/aepp-calldata-js/issues/88\n switch (returnType) {\n case 'ok': return\n case 'revert':\n message = instance.calldata.decodeFateString(returnValue)\n break\n case 'error':\n message = decode(returnValue).toString()\n break\n default: throw new InternalError(`Unknown returnType: ${returnType}`)\n }\n throw new NodeInvocationError(message)\n }\n\n instance._estimateGas = async (name, params, options) => {\n const { result: { gasUsed } } =\n await instance.call(name, params, { ...options, callStatic: true })\n // taken from https://github.com/aeternity/aepp-sdk-js/issues/1286#issuecomment-977814771\n return Math.floor(gasUsed * 1.25)\n }\n\n /**\n * Deploy contract\n * @alias module:@aeternity/aepp-sdk/es/contract/aci\n * @rtype (init: Array, options: Object) => ContractInstance: Object\n * @param {Array} params Contract init function arguments array\n * @param {Object} [options] options\n * @return {Object} deploy info\n */\n instance.deploy = async (params = [], options) => {\n const opt = { ...instance.options, ...options }\n if (!instance.bytecode) await instance.compile(opt)\n if (opt.callStatic) return instance.call('init', params, opt)\n if (instance.deployInfo.address) throw new DuplicateContractError()\n\n const ownerId = await this.address(opt)\n const { tx, contractId } = await this.contractCreateTx({\n ...opt,\n gas: opt.gas ?? await instance._estimateGas('init', params, opt),\n callData: instance.calldata.encode(instance._name, 'init', params),\n code: instance.bytecode,\n ownerId\n })\n const { hash, rawTx, result, txData } = await sendAndProcess(tx, opt)\n instance.deployInfo = Object.freeze({\n result,\n owner: ownerId,\n transaction: hash,\n rawTx,\n txData,\n address: contractId\n })\n return instance.deployInfo\n }\n\n /**\n * Get function schema from contract ACI object\n * @param {String} name Function name\n * @return {Object} function ACI\n */\n function getFunctionACI (name) {\n const fn = instance._aci.encoded_aci.contract.functions.find(f => f.name === name)\n if (fn) return fn\n if (name === 'init') return { payable: false }\n throw new NoSuchContractFunctionError(`Function ${name} doesn't exist in contract`)\n }\n\n /**\n * Call contract function\n * @alias module:@aeternity/aepp-sdk/es/contract/aci\n * @rtype (init: Array, options: Object = { callStatic: false }) => CallResult: Object\n * @param {String} fn Function name\n * @param {Array} params Array of function arguments\n * @param {Object} [options={}] Array of function arguments\n * @param {Boolean} [options.callStatic=false] Static function call\n * @return {Object} CallResult\n */\n instance.call = async (fn, params = [], options = {}) => {\n const opt = { ...instance.options, ...options }\n const fnACI = getFunctionACI(fn)\n const contractId = instance.deployInfo.address\n\n if (!fn) throw new MissingFunctionNameError()\n if (fn === 'init' && !opt.callStatic) throw new InvalidMethodInvocationError('\"init\" can be called only via dryRun')\n if (!contractId && fn !== 'init') throw new InvalidMethodInvocationError('You need to deploy contract before calling!')\n if (fn !== 'init' && opt.amount > 0 && fnACI.payable === false) throw new NotPayableFunctionError(`You try to pay \"${opt.amount}\" to function \"${fn}\" which is not payable. Only payable function can accept coins`)\n\n const callerId = await this.address(opt).catch(error => {\n if (opt.callStatic) return DRY_RUN_ACCOUNT.pub\n else throw error\n })\n const callData = instance.calldata.encode(instance._name, fn, params)\n\n let res\n if (opt.callStatic) {\n if (typeof opt.top === 'number') {\n opt.top = (await this.getKeyBlock(opt.top)).hash\n }\n const txOpt = {\n ...opt,\n gas: opt.gas ?? GAS_MAX,\n callData,\n nonce: opt.nonce ??\n (opt.top && (await this.getAccount(callerId, { hash: opt.top })).nonce + 1)\n }\n const tx = fn === 'init'\n ? (await this.contractCreateTx({ ...txOpt, code: instance.bytecode, ownerId: callerId })).tx\n : await this.contractCallTx({ ...txOpt, callerId, contractId })\n\n const { callObj, ...dryRunOther } = await this.txDryRun(tx, callerId, opt)\n await handleCallError(callObj)\n res = { ...dryRunOther, tx: TxObject({ tx }), result: callObj }\n } else {\n const tx = await this.contractCallTx({\n ...opt,\n gas: opt.gas ?? await instance._estimateGas(fn, params, opt),\n callerId,\n contractId,\n callData\n })\n res = await sendAndProcess(tx, opt)\n }\n if (opt.waitMined || opt.callStatic) {\n res.decodedResult = fnACI.returns && fnACI.returns !== 'unit' && fn !== 'init' &&\n instance.calldata.decode(instance._name, fn, res.result.returnValue)\n res.decodedEvents = instance.decodeEvents(res.result.log, opt)\n }\n return res\n }\n\n /**\n * @param {String} address Contract address that emitted event\n * @param {BigInt} nameHash Hash of emitted event name\n * @param {Object} [options]\n * @param {Object} [options.contractAddressToName] Map of contract addresses to their names\n * @return {String} Contract name\n * @throws {MissingEventDefinitionError}\n * @throws {AmbiguousEventDefinitionError}\n */\n function getContractNameByEvent (address, nameHash, { contractAddressToName }) {\n const addressToName = { ...instance.options.contractAddressToName, ...contractAddressToName }\n if (addressToName[address]) return addressToName[address]\n\n const matchedEvents = [\n instance._aci.encoded_aci,\n ...instance._aci.external_encoded_aci\n ]\n .filter(({ contract }) => contract?.event)\n .map(({ contract }) => [contract.name, contract.event.variant])\n .map(([name, events]) => events.map(event => [name, Object.keys(event)[0]]))\n .flat()\n .filter(([, eventName]) => BigInt('0x' + hash(eventName).toString('hex')) === nameHash)\n switch (matchedEvents.length) {\n case 0: throw new MissingEventDefinitionError(nameHash, address)\n case 1: return matchedEvents[0][0]\n default: throw new AmbiguousEventDefinitionError(address, matchedEvents)\n }\n }\n\n /**\n * Decode Events\n * @alias module:@aeternity/aepp-sdk/es/contract/aci\n * @rtype (events: Array) => DecodedEvents: Array\n * @param {Array} events Array of encoded events (callRes.result.log)\n * @param {Object} [options]\n * @param {Boolean} [options.omitUnknown] Omit events that can't be decoded in case ACI is not\n * complete\n * @return {Object} DecodedEvents\n */\n instance.decodeEvents = (events, { omitUnknown, ...opt } = {}) => events\n .map(event => {\n const topics = event.topics.map(t => BigInt(t))\n let contractName\n try {\n contractName = getContractNameByEvent(event.address, topics[0], opt)\n } catch (error) {\n if (omitUnknown && error instanceof MissingEventDefinitionError) return null\n throw error\n }\n const decoded = instance.calldata.decodeEvent(contractName, event.data, topics)\n const [name, args] = Object.entries(decoded)[0]\n return {\n name,\n args,\n contract: {\n name: contractName,\n address: event.address\n }\n }\n })\n .filter(e => e)\n\n /**\n * Generate proto function based on contract function using Contract ACI schema\n * All function can be called like:\n * 'await contract.methods.testFunction()' -> then sdk will decide to use dry-run or send tx\n * on-chain base on if function stateful or not.\n * Also you can manually do that:\n * `await contract.methods.testFunction.get()` -> use call-static(dry-run)\n * `await contract.methods.testFunction.send()` -> send tx on-chain\n */\n instance.methods = Object.fromEntries(instance._aci.encoded_aci.contract.functions\n .map(({ name, arguments: aciArgs, stateful }) => {\n const genHandler = callStatic => (...args) => {\n const options = args.length === aciArgs.length + 1 ? args.pop() : {}\n if (typeof options !== 'object') throw new TypeError(`Options should be an object: ${options}`)\n if (name === 'init') return instance.deploy(args, { callStatic, ...options })\n return instance.call(name, args, { callStatic, ...options })\n }\n return [\n name,\n Object.assign(\n genHandler(name === 'init' ? false : !stateful),\n {\n get: genHandler(true),\n send: genHandler(false)\n }\n )\n ]\n })\n )\n\n return instance\n}\n"],"file":"aci.mjs"}
1
+ {"version":3,"file":"aci.mjs","names":["DRY_RUN_ACCOUNT","GAS_MAX","TX_TYPE","AMOUNT","buildContractIdByContractTx","unpackTx","_buildTx","send","decode","MissingContractDefError","MissingContractAddressError","InactiveContractError","BytecodeMismatchError","DuplicateContractError","MissingFunctionNameError","InvalidMethodInvocationError","NotPayableFunctionError","TypeError","NodeInvocationError","IllegalArgumentError","NoSuchContractFunctionError","MissingEventDefinitionError","AmbiguousEventDefinitionError","UnexpectedTsError","hash","getAccount","getContract","getContractByteCode","getKeyBlock","resolveName","txDryRun","getContractInstance","onAccount","onCompiler","onNode","source","bytecode","aci","_aci","contractAddress","fileSystem","validateBytecode","otherOptions","generateACI","code","options","resolveByNode","contract","active","instance","_name","encodedAci","name","calldata","Calldata","externalEncodedAci","deployInfo","address","amount","callStatic","compile","_options","_estimateGas","_params","deploy","call","_fn","decodeEvents","_events","methods","undefined","onChanBytecode","isValid","validateByteCode","then","compileContract","sendAndProcess","tx","txData","result","rawTx","blockHeight","callInfo","getTransactionInfoByHash","Object","assign","handleCallError","transaction","returnType","returnValue","message","decodeFateString","toString","params","gasUsed","Math","floor","opt","ownerId","contractCreate","gasLimit","callData","encode","contractId","freeze","owner","getFunctionACI","fn","functions","find","f","payable","fnACI","callerId","Promise","resolve","catch","error","pub","res","top","txOpt","nonce","contractCall","callObj","dryRunOther","decodedResult","returns","decodedEvents","log","getContractNameByEvent","nameHash","contractAddressToName","addressToName","matchedEvents","filter","event","map","variant","events","keys","flat","eventName","BigInt","length","omitUnknown","topics","t","contractName","decoded","decodeEvent","data","args","entries","e","fromEntries","arguments","aciArgs","stateful","genHandler","pop","get"],"sources":["../../src/contract/aci.ts"],"sourcesContent":["/*\n* ISC License (ISC)\n* Copyright (c) 2022 aeternity developers\n*\n* Permission to use, copy, modify, and/or distribute this software for any\n* purpose with or without fee is hereby granted, provided that the above\n* copyright notice and this permission notice appear in all copies.\n*\n* THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n* PERFORMANCE OF THIS SOFTWARE.\n*/\n// @ts-expect-error TODO remove\nimport { Encoder as Calldata } from '@aeternity/aepp-calldata'\nimport { DRY_RUN_ACCOUNT, GAS_MAX, TX_TYPE, AMOUNT, AensName } from '../tx/builder/schema'\nimport { buildContractIdByContractTx, unpackTx } from '../tx/builder'\nimport { _buildTx } from '../tx'\nimport { send } from '../spend'\nimport { decode, EncodedData, EncodingType } from '../utils/encoder'\nimport {\n MissingContractDefError,\n MissingContractAddressError,\n InactiveContractError,\n BytecodeMismatchError,\n DuplicateContractError,\n MissingFunctionNameError,\n InvalidMethodInvocationError,\n NotPayableFunctionError,\n TypeError,\n NodeInvocationError,\n IllegalArgumentError,\n NoSuchContractFunctionError,\n MissingEventDefinitionError,\n AmbiguousEventDefinitionError,\n UnexpectedTsError\n} from '../utils/errors'\nimport { hash } from '../utils/crypto'\nimport { Aci as BaseAci } from '../apis/compiler'\nimport Compiler from './Compiler'\nimport Node from '../Node'\nimport {\n getAccount, getContract, getContractByteCode, getKeyBlock, resolveName, txDryRun\n} from '../chain'\nimport AccountBase from '../account/Base'\n\ninterface FunctionACI {\n arguments: any[]\n name: string\n payable: boolean\n returns: string\n stateful: boolean\n}\n\ninterface Aci extends BaseAci {\n encodedAci: {\n contract: {\n name: string\n event: any\n kind: string\n state: any\n type_defs: any[]\n functions: FunctionACI[]\n }\n }\n externalEncodedAci: any[]\n}\n\ninterface Event {\n address: EncodedData<'ct'>\n data: string\n topics: Array<string | number>\n}\n\ninterface DecodedEvent {\n name: string\n args: unknown\n contract: {\n name: string\n address: EncodedData<'ct'>\n }\n}\n\ntype TxData = Awaited<ReturnType<typeof send>>\n\nexport interface ContractInstance {\n _aci: Aci\n _name: string\n calldata: any\n source?: string\n bytecode?: EncodedData<'cb'>\n deployInfo: {\n address?: EncodedData<'ct'>\n result?: {\n callerId: string\n callerNonce: string\n contractId: string\n gasPrice: bigint\n gasUsed: number\n height: number\n log: any[]\n returnType: string\n returnValue: string\n }\n owner?: EncodedData<'ak'>\n transaction?: string\n rawTx?: string\n txData?: TxData\n }\n options: any\n compile: (options?: {}) => Promise<EncodedData<'cb'>>\n _estimateGas: (name: string, params: any[], options: object) => Promise<number>\n deploy: (params?: any[], options?: object) => Promise<any>\n call: (fn: string, params?: any[], options?: {}) => Promise<{\n hash: string\n tx: any\n txData: TxData\n rawTx: string\n result: {\n callerId: EncodedData<'ak'>\n callerNonce: number\n contractId: EncodedData<'ct'>\n gasPrice: number\n gasUsed: number\n height: number\n log: any[]\n returnType: string\n returnValue: string\n }\n decodedResult: any\n decodedEvents: DecodedEvent[]\n }>\n decodeEvents: (\n events: Event[], options?: { omitUnknown?: boolean, contractAddressToName?: any }\n ) => DecodedEvent[]\n methods: any\n}\n\ntype ContractCallReturnType = 'ok' | 'error' | 'revert'\n\n/**\n * Generate contract ACI object with predefined js methods for contract usage - can be used for\n * creating a reference to already deployed contracts\n * @param options - Options object\n * @returns JS Contract API\n * @example\n * ```js\n * const contractIns = await aeSdk.getContractInstance({ source })\n * await contractIns.deploy([321]) or await contractIns.methods.init(321)\n * const callResult = await contractIns.call('setState', [123]) or\n * await contractIns.methods.setState.send(123, options)\n * const staticCallResult = await contractIns.call('setState', [123], { callStatic: true }) or\n * await contractIns.methods.setState.get(123, options)\n * ```\n * Also you can call contract like: `await contractIns.methods.setState(123, options)`\n * Then sdk decide to make on-chain or static call(dry-run API) transaction based on function is\n * stateful or not\n */\nexport default async function getContractInstance ({\n onAccount,\n onCompiler,\n onNode,\n source,\n bytecode,\n aci: _aci,\n contractAddress,\n fileSystem = {},\n validateBytecode,\n ...otherOptions\n}: {\n onAccount: AccountBase\n onCompiler: Compiler\n onNode: Node\n source?: string\n bytecode?: EncodedData<'cb'>\n aci?: Aci\n contractAddress?: EncodedData<'ct'> | AensName\n fileSystem?: Record<string, string>\n validateBytecode?: boolean\n [key: string]: any\n}): Promise<ContractInstance> {\n if (_aci == null && source != null) {\n // TODO: should be fixed when the compiledAci interface gets updated\n _aci = await onCompiler.generateACI({ code: source, options: { fileSystem } }) as Aci\n }\n if (_aci == null) throw new MissingContractDefError()\n\n if (contractAddress != null) {\n contractAddress = await resolveName(\n contractAddress, 'contract_pubkey', { resolveByNode: true, onNode }\n ) as EncodedData<'ct'>\n }\n\n if (contractAddress == null && source == null && bytecode == null) {\n throw new MissingContractAddressError('Can\\'t create instance by ACI without address')\n }\n\n if (contractAddress != null) {\n const contract = await getContract(contractAddress, { onNode })\n if (contract.active == null) throw new InactiveContractError(contractAddress)\n }\n\n const instance: ContractInstance = {\n _aci,\n _name: _aci.encodedAci.contract.name,\n calldata: new Calldata([_aci.encodedAci, ..._aci.externalEncodedAci]),\n source,\n bytecode,\n deployInfo: { address: contractAddress },\n options: {\n onAccount,\n onCompiler,\n onNode,\n amount: AMOUNT,\n callStatic: false,\n fileSystem,\n ...otherOptions\n },\n compile: async function (_options?: {}): Promise<any> {},\n _estimateGas: async function (\n _name: string, _params: any[], _options: object\n ): Promise<any> {},\n deploy: async function (_params?: any[], _options?: any): Promise<any> {},\n call: async function (_fn: string, _params?: any[], _options?: {}): Promise<any> {},\n decodeEvents (_events: Event[], options?: { omitUnknown?: boolean }): any {},\n methods: undefined\n }\n\n if (validateBytecode != null) {\n if (contractAddress == null) throw new MissingContractAddressError('Can\\'t validate bytecode without contract address')\n const onChanBytecode = (await getContractByteCode(contractAddress, { onNode })).bytecode\n const isValid: boolean = source != null\n ? await onCompiler.validateByteCode(\n { bytecode: onChanBytecode, source, options: instance.options }\n ).then(() => true, () => false)\n : bytecode === onChanBytecode\n if (!isValid) throw new BytecodeMismatchError(source != null ? 'source' : 'bytecode')\n }\n\n /**\n * Compile contract\n * @returns bytecode\n */\n instance.compile = async (options = {}): Promise<EncodedData<'cb'>> => {\n if (instance.bytecode != null) throw new IllegalArgumentError('Contract already compiled')\n if (instance.source == null) throw new IllegalArgumentError('Can\\'t compile without source code')\n instance.bytecode = (await onCompiler.compileContract({\n code: instance.source, options: { ...instance.options, ...options }\n })).bytecode as EncodedData<'cb'>\n return instance.bytecode\n }\n\n const sendAndProcess = async (tx: EncodedData<'tx'>, options: any): Promise<{\n result?: ContractInstance['deployInfo']['result']\n hash: TxData['hash']\n tx: Awaited<ReturnType<typeof unpackTx<TX_TYPE.contractCall | TX_TYPE.contractCreate>>>\n txData: TxData\n rawTx: EncodedData<'tx'>\n }> => {\n options = { ...instance.options, ...options }\n const txData = await send(tx, options)\n const result = {\n hash: txData.hash,\n tx: unpackTx<TX_TYPE.contractCall | TX_TYPE.contractCreate>(txData.rawTx),\n txData,\n rawTx: txData.rawTx\n }\n if (txData.blockHeight == null) return result\n const { callInfo } = await onNode.getTransactionInfoByHash(txData.hash)\n Object.assign(result.txData, callInfo) // TODO: don't duplicate data in result\n // @ts-expect-error TODO api should be updated to match types\n handleCallError(callInfo, tx)\n return { ...result, result: callInfo }\n }\n const handleCallError = (\n { returnType, returnValue }: {\n returnType: ContractCallReturnType\n returnValue: EncodedData<EncodingType>\n },\n transaction: string): void => {\n let message: string\n switch (returnType) {\n case 'ok': return\n case 'revert':\n message = instance.calldata.decodeFateString(returnValue)\n break\n case 'error':\n message = decode(returnValue).toString()\n break\n }\n throw new NodeInvocationError(message, transaction)\n }\n\n instance._estimateGas = async (\n name: string, params: any[], options: object): Promise<number> => {\n const { result: { gasUsed } } =\n await instance.call(name, params, { ...options, callStatic: true })\n // taken from https://github.com/aeternity/aepp-sdk-js/issues/1286#issuecomment-977814771\n return Math.floor(gasUsed * 1.25)\n }\n\n /**\n * Deploy contract\n * @param params - Contract init function arguments array\n * @param options - Options\n * @returns deploy info\n */\n instance.deploy = async (params = [],\n options:\n Parameters<typeof instance.compile>[0] &\n Parameters<typeof instance.call>[2] &\n Parameters<AccountBase['address']>[0] &\n Parameters<typeof sendAndProcess>[1]\n ): Promise<ContractInstance['deployInfo']> => {\n const opt = { ...instance.options, ...options }\n if (instance.bytecode == null) await instance.compile(opt)\n // @ts-expect-error\n if (opt.callStatic === true) return await instance.call('init', params, opt)\n if (instance.deployInfo.address != null) throw new DuplicateContractError()\n\n const ownerId = await opt.onAccount.address(options)\n const tx = await _buildTx(TX_TYPE.contractCreate, {\n ...opt,\n gasLimit: opt.gasLimit ?? await instance._estimateGas('init', params, opt),\n callData: instance.calldata.encode(instance._name, 'init', params),\n code: instance.bytecode,\n ownerId,\n onNode\n })\n const contractId = buildContractIdByContractTx(tx)\n const { hash, rawTx, result, txData } = await sendAndProcess(tx, opt)\n instance.deployInfo = Object.freeze({\n result,\n owner: ownerId,\n transaction: hash,\n rawTx,\n txData,\n address: contractId\n })\n return instance.deployInfo\n }\n\n /**\n * Get function schema from contract ACI object\n * @param name - Function name\n * @returns function ACI\n */\n function getFunctionACI (name: string): Partial<FunctionACI> {\n const fn = instance._aci.encodedAci.contract.functions.find(\n (f: { name: string }) => f.name === name)\n if (fn != null) {\n return fn\n }\n if (name === 'init') return { payable: false }\n throw new NoSuchContractFunctionError(`Function ${name} doesn't exist in contract`)\n }\n\n /**\n * Call contract function\n * @param fn - Function name\n * @param params - Array of function arguments\n * @param options - Array of function arguments\n * @returns CallResult\n */\n instance.call = async (fn: string, params: any[] = [], options: object = {}) => {\n const opt = { ...instance.options, ...options }\n const fnACI = getFunctionACI(fn)\n const contractId = instance.deployInfo.address\n\n if (fn == null) throw new MissingFunctionNameError()\n if (fn === 'init' && opt.callStatic === false) throw new InvalidMethodInvocationError('\"init\" can be called only via dryRun')\n if (contractId == null && fn !== 'init') throw new InvalidMethodInvocationError('You need to deploy contract before calling!')\n if (fn !== 'init' && opt.amount > 0 && fnACI.payable === false) throw new NotPayableFunctionError(opt.amount, fn)\n\n const callerId = await Promise.resolve()\n .then(() => opt.onAccount.address(opt))\n .catch((error: any) => {\n if (opt.callStatic === true) return DRY_RUN_ACCOUNT.pub\n else throw error\n }) as EncodedData<'ak'>\n const callData = instance.calldata.encode(instance._name, fn, params)\n\n let res: any\n if (opt.callStatic === true) {\n if (typeof opt.top === 'number') {\n opt.top = (await getKeyBlock(opt.top, { onNode })).hash\n }\n const txOpt = {\n ...opt,\n onNode,\n gasLimit: opt.gasLimit ?? GAS_MAX,\n callData\n }\n if (opt.nonce == null && opt.top != null) {\n opt.nonce = (await getAccount(callerId, { hash: opt.top, onNode })).nonce + 1\n }\n const tx = await (fn === 'init'\n ? _buildTx(TX_TYPE.contractCreate, { ...txOpt, code: instance.bytecode, ownerId: callerId })\n : _buildTx(TX_TYPE.contractCall, { ...txOpt, callerId, contractId }))\n\n const { callObj, ...dryRunOther } = await txDryRun(tx, callerId, { onNode, ...opt })\n if (callObj == null) throw new UnexpectedTsError()\n handleCallError({\n returnType: callObj.returnType as ContractCallReturnType,\n returnValue: callObj.returnValue as EncodedData<EncodingType>\n }, tx)\n res = { ...dryRunOther, tx: unpackTx(tx), result: callObj }\n } else {\n const tx = await _buildTx(TX_TYPE.contractCall, {\n ...opt,\n onNode,\n gasLimit: opt.gasLimit ?? await instance._estimateGas(fn, params, opt),\n callerId,\n contractId,\n callData\n })\n res = await sendAndProcess(tx, opt)\n }\n if (opt.callStatic === true || res.txData.blockHeight != null) {\n res.decodedResult = fnACI.returns != null && fnACI.returns !== 'unit' && fn !== 'init' &&\n instance.calldata.decode(instance._name, fn, res.result.returnValue)\n res.decodedEvents = instance.decodeEvents(res.result.log, opt)\n }\n return res\n }\n\n /**\n * @param address - Contract address that emitted event\n * @param nameHash - Hash of emitted event name\n * @param options - Options\n * @returns Contract name\n * @throws {@link MissingEventDefinitionError}\n * @throws {@link AmbiguousEventDefinitionError}\n */\n function getContractNameByEvent (\n address: EncodedData<'ct'>,\n nameHash: BigInt,\n { contractAddressToName }: { contractAddressToName?: { [key: EncodedData<'ct'>]: string } }\n ): string {\n const addressToName = { ...instance.options.contractAddressToName, ...contractAddressToName }\n if (addressToName[address] != null) return addressToName[address]\n\n const matchedEvents = [\n instance._aci.encodedAci,\n ...instance._aci.externalEncodedAci\n ]\n .filter(({ contract }) => contract?.event)\n .map(({ contract }) => [contract.name, contract.event.variant])\n .map(([name, events]) => events.map((event: {}) => [name, Object.keys(event)[0]]))\n .flat()\n .filter(([, eventName]) => BigInt('0x' + hash(eventName).toString('hex')) === nameHash)\n switch (matchedEvents.length) {\n case 0: throw new MissingEventDefinitionError(nameHash.toString(), address)\n case 1: return matchedEvents[0][0]\n default: throw new AmbiguousEventDefinitionError(address, matchedEvents)\n }\n }\n\n /**\n * Decode Events\n * @param events - Array of encoded events (callRes.result.log)\n * @param options - Options\n * @returns DecodedEvents\n */\n instance.decodeEvents = (\n events: Event[],\n { omitUnknown, ...opt }: { omitUnknown?: boolean } = {}\n ): DecodedEvent[] => events\n .map(event => {\n const topics = event.topics.map((t: string | number) => BigInt(t))\n let contractName\n try {\n contractName = getContractNameByEvent(event.address, topics[0], opt)\n } catch (error) {\n if ((omitUnknown ?? false) && error instanceof MissingEventDefinitionError) return null\n throw error\n }\n const decoded = instance.calldata.decodeEvent(contractName, event.data, topics)\n const [name, args] = Object.entries(decoded)[0]\n return {\n name,\n args,\n contract: {\n name: contractName,\n address: event.address\n }\n }\n }).filter((e: DecodedEvent | null): e is DecodedEvent => e != null)\n\n /**\n * Generate proto function based on contract function using Contract ACI schema\n * All function can be called like:\n * ```js\n * await contract.methods.testFunction()\n * ```\n * then sdk will decide to use dry-run or send tx\n * on-chain base on if function stateful or not.\n * Also, you can manually do that:\n * ```js\n * await contract.methods.testFunction.get() // use call-static (dry-run)\n * await contract.methods.testFunction.send() // send tx on-chain\n * ```\n */\n instance.methods = Object.fromEntries(instance._aci.encodedAci.contract.functions\n .map(({ name, arguments: aciArgs, stateful }: FunctionACI) => {\n const genHandler = (callStatic: boolean) => async (...args: any[]) => {\n const options = args.length === aciArgs.length + 1 ? args.pop() : {}\n if (typeof options !== 'object') throw new TypeError(`Options should be an object: ${options as string}`)\n if (name === 'init') return await instance.deploy(args, { callStatic, ...options })\n return await instance.call(name, args, { callStatic, ...options })\n }\n return [\n name,\n Object.assign(\n genHandler(name === 'init' ? false : !stateful),\n {\n get: genHandler(true),\n send: genHandler(false)\n }\n )\n ]\n })\n )\n\n return instance\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mCAAoC,0BAApC;;;;SACSA,e,EAAiBC,O,EAASC,O,EAASC,M;SACnCC,2B,EAA6BC,Q;SAC7BC,Q;SACAC,I;SACAC,M;SAEPC,uB,EACAC,2B,EACAC,qB,EACAC,qB,EACAC,sB,EACAC,wB,EACAC,4B,EACAC,uB,EACAC,S,EACAC,mB,EACAC,oB,EACAC,2B,EACAC,2B,EACAC,6B,EACAC,iB;SAEOC,I;SAKPC,U,EAAYC,W,EAAaC,mB,EAAqBC,W,EAAaC,W,EAAaC,Q;;AAkG1E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,eAAeC,mBAAf,OAsBe;EAAA,IAtBqB;IACjDC,SADiD;IAEjDC,UAFiD;IAGjDC,MAHiD;IAIjDC,MAJiD;IAKjDC,QALiD;IAMjDC,GAAG,EAAEC,IAN4C;IAOjDC,eAPiD;IAQjDC,UAAU,GAAG,EARoC;IASjDC,gBATiD;IAUjD,GAAGC;EAV8C,CAsBrB;;EAC5B,IAAIJ,IAAI,IAAI,IAAR,IAAgBH,MAAM,IAAI,IAA9B,EAAoC;IAClC;IACAG,IAAI,GAAG,MAAML,UAAU,CAACU,WAAX,CAAuB;MAAEC,IAAI,EAAET,MAAR;MAAgBU,OAAO,EAAE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UAAF;QAAc,GAAGd;MAAjB,CAA1B,CAAb;IACD,CALD;;IAMA,OAAO,CACLO,IADK,EAELgC,MAAM,CAACC,MAAP,CACE0E,UAAU,CAAC3G,IAAI,KAAK,MAAT,GAAkB,KAAlB,GAA0B,CAAC0G,QAA5B,CADZ,EAEE;MACEG,GAAG,EAAEF,UAAU,CAAC,IAAD,CADjB;MAEExJ,IAAI,EAAEwJ,UAAU,CAAC,KAAD;IAFlB,CAFF,CAFK,CAAP;EAUD,CAlBmC,CAAnB,CAAnB;EAqBA,OAAO9G,QAAP;AACD"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Generalized Account module - routines to use generalized account
3
+ */
4
+ import { TX_TYPE } from '../tx/builder/schema';
5
+ import { BuildTxOptions } from '../tx';
6
+ import { EncodedData } from '../utils/encoder';
7
+ import AccountBase from '../account/Base';
8
+ import { SendOptions } from '../spend';
9
+ import Node from '../Node';
10
+ import { getAccount } from '../chain';
11
+ import Compiler from './Compiler';
12
+ /**
13
+ * Check if account is GA
14
+ * @param address - Account address
15
+ * @param options - Options
16
+ * @returns if account is GA
17
+ */
18
+ export declare function isGA(address: EncodedData<'ak'>, options: Parameters<typeof getAccount>[1]): Promise<boolean>;
19
+ /**
20
+ * Convert current account to GA
21
+ * @param authFnName - Authorization function name
22
+ * @param source - Auth contract source code
23
+ * @param args - init arguments
24
+ * @param options - Options
25
+ * @returns General Account Object
26
+ */
27
+ export declare function createGeneralizedAccount(authFnName: string, source: string, args: any[], { onAccount, onCompiler, onNode, ...options }: CreateGeneralizedAccountOptions): Promise<Readonly<{
28
+ owner: EncodedData<'ak'>;
29
+ transaction: EncodedData<'th'>;
30
+ rawTx: EncodedData<'tx'>;
31
+ gaContractId: EncodedData<'ct'>;
32
+ }>>;
33
+ interface CreateGeneralizedAccountOptions extends BuildTxOptions<TX_TYPE.gaAttach, 'authFun' | 'callData' | 'code' | 'ownerId' | 'gasLimit'>, SendOptions {
34
+ onAccount: AccountBase;
35
+ onCompiler: Compiler;
36
+ onNode: Node;
37
+ gasLimit?: number;
38
+ }
39
+ /**
40
+ * Create a metaTx transaction
41
+ * @param rawTransaction - Inner transaction
42
+ * @param authData - Object with gaMeta params
43
+ * @param authFnName - Authorization function name
44
+ * @param options - Options
45
+ * @param options.onAccount - Account to use
46
+ * @returns Transaction string
47
+ */
48
+ export declare function createMetaTx(rawTransaction: EncodedData<'tx'>, authData: {
49
+ gasLimit?: number;
50
+ callData?: EncodedData<'cb'>;
51
+ source?: string;
52
+ args?: any[];
53
+ }, authFnName: string, { onAccount, onCompiler, onNode, ...options }: {
54
+ onAccount: AccountBase;
55
+ onCompiler: Compiler;
56
+ onNode: Node;
57
+ } & Parameters<AccountBase['address']>[0]): Promise<EncodedData<'tx'>>;
58
+ /**
59
+ * Build a transaction hash the same as `Auth.tx_hash`
60
+ * @param transaction - tx-encoded transaction
61
+ * @param options - Options
62
+ * @param options.onNode - Node to use
63
+ * @returns Transaction hash
64
+ */
65
+ export declare function buildAuthTxHash(transaction: EncodedData<'tx'>, { onNode }: {
66
+ onNode: Node;
67
+ }): Promise<Uint8Array>;
68
+ export {};
@@ -0,0 +1,190 @@
1
+ import _buffer from "buffer";
2
+ const {
3
+ Buffer: _Buffer
4
+ } = _buffer;
5
+
6
+ /*
7
+ * ISC License (ISC)
8
+ * Copyright (c) 2022 aeternity developers
9
+ *
10
+ * Permission to use, copy, modify, and/or distribute this software for any
11
+ * purpose with or without fee is hereby granted, provided that the above
12
+ * copyright notice and this permission notice appear in all copies.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16
+ * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
+ * PERFORMANCE OF THIS SOFTWARE.
21
+ */
22
+
23
+ /**
24
+ * Generalized Account module - routines to use generalized account
25
+ */
26
+ import { TX_TYPE, MAX_AUTH_FUN_GAS } from "../tx/builder/schema.mjs";
27
+ import { buildContractIdByContractTx, buildTx, unpackTx } from "../tx/builder/index.mjs";
28
+ import { _buildTx, getVmVersion, prepareTxParams } from "../tx/index.mjs";
29
+ import { hash } from "../utils/crypto.mjs";
30
+ import { decode } from "../utils/encoder.mjs";
31
+ import { IllegalArgumentError, MissingParamError, InvalidAuthDataError } from "../utils/errors.mjs";
32
+ import { concatBuffers } from "../utils/other.mjs";
33
+ import { getContractInstance } from "./methods.mjs";
34
+ import { send } from "../spend.mjs";
35
+ import { getAccount } from "../chain.mjs";
36
+
37
+ /**
38
+ * Check if account is GA
39
+ * @param address - Account address
40
+ * @param options - Options
41
+ * @returns if account is GA
42
+ */
43
+ export async function isGA(address, options) {
44
+ const {
45
+ contractId
46
+ } = await getAccount(address, options);
47
+ return contractId != null;
48
+ }
49
+ /**
50
+ * Convert current account to GA
51
+ * @param authFnName - Authorization function name
52
+ * @param source - Auth contract source code
53
+ * @param args - init arguments
54
+ * @param options - Options
55
+ * @returns General Account Object
56
+ */
57
+
58
+ export async function createGeneralizedAccount(authFnName, source, args, _ref) {
59
+ var _options$gasLimit;
60
+
61
+ let {
62
+ onAccount,
63
+ onCompiler,
64
+ onNode,
65
+ ...options
66
+ } = _ref;
67
+ const ownerId = await onAccount.address(options);
68
+ if (await isGA(ownerId, {
69
+ onNode
70
+ })) throw new IllegalArgumentError(`Account ${ownerId} is already GA`);
71
+ const contract = await getContractInstance({
72
+ onAccount,
73
+ onCompiler,
74
+ onNode,
75
+ source
76
+ });
77
+ const tx = await _buildTx(TX_TYPE.gaAttach, { ...options,
78
+ onNode,
79
+ code: await contract.compile(),
80
+ gasLimit: (_options$gasLimit = options.gasLimit) !== null && _options$gasLimit !== void 0 ? _options$gasLimit : await contract._estimateGas('init', args, options),
81
+ ownerId,
82
+ callData: contract.calldata.encode(contract._name, 'init', args),
83
+ authFun: hash(authFnName)
84
+ });
85
+ const contractId = buildContractIdByContractTx(tx);
86
+ const {
87
+ hash: transaction,
88
+ rawTx
89
+ } = await send(tx, {
90
+ onNode,
91
+ onAccount,
92
+ onCompiler,
93
+ ...options
94
+ });
95
+ return Object.freeze({
96
+ owner: ownerId,
97
+ transaction,
98
+ rawTx,
99
+ gaContractId: contractId
100
+ });
101
+ }
102
+
103
+ /**
104
+ * Create a metaTx transaction
105
+ * @param rawTransaction - Inner transaction
106
+ * @param authData - Object with gaMeta params
107
+ * @param authFnName - Authorization function name
108
+ * @param options - Options
109
+ * @param options.onAccount - Account to use
110
+ * @returns Transaction string
111
+ */
112
+ export async function createMetaTx(rawTransaction, authData, authFnName, _ref2) {
113
+ var _authData$gasLimit, _authData$callData;
114
+
115
+ let {
116
+ onAccount,
117
+ onCompiler,
118
+ onNode,
119
+ ...options
120
+ } = _ref2;
121
+
122
+ const wrapInEmptySignedTx = tx => buildTx({
123
+ encodedTx: tx,
124
+ signatures: []
125
+ }, TX_TYPE.signed);
126
+
127
+ if (Object.keys(authData).length <= 0) throw new MissingParamError('authData is required');
128
+ const gasLimit = (_authData$gasLimit = authData.gasLimit) !== null && _authData$gasLimit !== void 0 ? _authData$gasLimit : MAX_AUTH_FUN_GAS;
129
+
130
+ if (gasLimit > MAX_AUTH_FUN_GAS) {
131
+ throw new InvalidAuthDataError(`the maximum gasLimit value for ga authFun is ${MAX_AUTH_FUN_GAS}, got ${gasLimit}`);
132
+ }
133
+
134
+ const authCallData = (_authData$callData = authData.callData) !== null && _authData$callData !== void 0 ? _authData$callData : await (async () => {
135
+ if (authData.source == null || authData.args == null) throw new InvalidAuthDataError('Auth data must contain source code and arguments.');
136
+ const contract = await getContractInstance({
137
+ onAccount,
138
+ onCompiler,
139
+ onNode,
140
+ source: authData.source
141
+ });
142
+ return contract.calldata.encode(contract._name, authFnName, authData.args);
143
+ })();
144
+ const {
145
+ abiVersion
146
+ } = await getVmVersion(TX_TYPE.contractCall, {
147
+ onNode
148
+ });
149
+ const wrappedTx = wrapInEmptySignedTx(unpackTx(rawTransaction));
150
+ const params = { ...options,
151
+ tx: { ...wrappedTx,
152
+ tx: wrappedTx.txObject
153
+ },
154
+ gaId: await onAccount.address(options),
155
+ abiVersion,
156
+ authData: authCallData,
157
+ gasLimit,
158
+ vsn: 2
159
+ }; // @ts-expect-error createMetaTx needs to be integrated into tx builder
160
+
161
+ const {
162
+ fee
163
+ } = await prepareTxParams(TX_TYPE.gaMeta, { ...params,
164
+ onNode
165
+ });
166
+ const {
167
+ rlpEncoded: metaTxRlp
168
+ } = buildTx({ ...params,
169
+ fee
170
+ }, TX_TYPE.gaMeta);
171
+ return wrapInEmptySignedTx(metaTxRlp).tx;
172
+ }
173
+ /**
174
+ * Build a transaction hash the same as `Auth.tx_hash`
175
+ * @param transaction - tx-encoded transaction
176
+ * @param options - Options
177
+ * @param options.onNode - Node to use
178
+ * @returns Transaction hash
179
+ */
180
+
181
+ export async function buildAuthTxHash(transaction, _ref3) {
182
+ let {
183
+ onNode
184
+ } = _ref3;
185
+ const {
186
+ networkId
187
+ } = await onNode.getStatus();
188
+ return new Uint8Array(hash(concatBuffers([_Buffer.from(networkId), decode(transaction)])));
189
+ }
190
+ //# sourceMappingURL=ga.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ga.mjs","names":["TX_TYPE","MAX_AUTH_FUN_GAS","buildContractIdByContractTx","buildTx","unpackTx","_buildTx","getVmVersion","prepareTxParams","hash","decode","IllegalArgumentError","MissingParamError","InvalidAuthDataError","concatBuffers","getContractInstance","send","getAccount","isGA","address","options","contractId","createGeneralizedAccount","authFnName","source","args","onAccount","onCompiler","onNode","ownerId","contract","tx","gaAttach","code","compile","gasLimit","_estimateGas","callData","calldata","encode","_name","authFun","transaction","rawTx","Object","freeze","owner","gaContractId","createMetaTx","rawTransaction","authData","wrapInEmptySignedTx","encodedTx","signatures","signed","keys","length","authCallData","abiVersion","contractCall","wrappedTx","params","txObject","gaId","vsn","fee","gaMeta","rlpEncoded","metaTxRlp","buildAuthTxHash","networkId","getStatus","Uint8Array","from"],"sources":["../../src/contract/ga.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2022 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Generalized Account module - routines to use generalized account\n */\n\nimport { TX_TYPE, MAX_AUTH_FUN_GAS, TxSchema } from '../tx/builder/schema'\nimport { buildContractIdByContractTx, buildTx, BuiltTx, TxUnpacked, unpackTx } from '../tx/builder'\nimport { _buildTx, BuildTxOptions, getVmVersion, prepareTxParams } from '../tx'\nimport { hash } from '../utils/crypto'\nimport { decode, EncodedData } from '../utils/encoder'\nimport { IllegalArgumentError, MissingParamError, InvalidAuthDataError } from '../utils/errors'\nimport { concatBuffers } from '../utils/other'\nimport AccountBase from '../account/Base'\nimport { getContractInstance } from './methods'\nimport { send, SendOptions } from '../spend'\nimport Node from '../Node'\nimport { getAccount } from '../chain'\nimport Compiler from './Compiler'\n\n/**\n * Check if account is GA\n * @param address - Account address\n * @param options - Options\n * @returns if account is GA\n */\nexport async function isGA (\n address: EncodedData<'ak'>, options: Parameters<typeof getAccount>[1]\n): Promise<boolean> {\n const { contractId } = await getAccount(address, options)\n return contractId != null\n}\n\n/**\n * Convert current account to GA\n * @param authFnName - Authorization function name\n * @param source - Auth contract source code\n * @param args - init arguments\n * @param options - Options\n * @returns General Account Object\n */\nexport async function createGeneralizedAccount (\n authFnName: string,\n source: string,\n args: any[],\n { onAccount, onCompiler, onNode, ...options }: CreateGeneralizedAccountOptions\n): Promise<Readonly<{\n owner: EncodedData<'ak'>\n transaction: EncodedData<'th'>\n rawTx: EncodedData<'tx'>\n gaContractId: EncodedData<'ct'>\n }>> {\n const ownerId = await onAccount.address(options)\n if (await isGA(ownerId, { onNode })) throw new IllegalArgumentError(`Account ${ownerId} is already GA`)\n\n const contract = await getContractInstance({ onAccount, onCompiler, onNode, source })\n\n const tx = await _buildTx(TX_TYPE.gaAttach, {\n ...options,\n onNode,\n code: await contract.compile(),\n gasLimit: options.gasLimit ?? await contract._estimateGas('init', args, options),\n ownerId,\n callData: contract.calldata.encode(contract._name, 'init', args),\n authFun: hash(authFnName)\n })\n const contractId = buildContractIdByContractTx(tx)\n const { hash: transaction, rawTx } = await send(tx, { onNode, onAccount, onCompiler, ...options })\n\n return Object.freeze({\n owner: ownerId,\n transaction,\n rawTx,\n gaContractId: contractId\n })\n}\n\ninterface CreateGeneralizedAccountOptions extends\n BuildTxOptions<TX_TYPE.gaAttach, 'authFun' | 'callData' | 'code' | 'ownerId' | 'gasLimit'>,\n SendOptions {\n onAccount: AccountBase\n onCompiler: Compiler\n onNode: Node\n gasLimit?: number\n}\n\n/**\n * Create a metaTx transaction\n * @param rawTransaction - Inner transaction\n * @param authData - Object with gaMeta params\n * @param authFnName - Authorization function name\n * @param options - Options\n * @param options.onAccount - Account to use\n * @returns Transaction string\n */\nexport async function createMetaTx (\n rawTransaction: EncodedData<'tx'>,\n authData: {\n gasLimit?: number\n callData?: EncodedData<'cb'>\n source?: string\n args?: any[]\n },\n authFnName: string,\n { onAccount, onCompiler, onNode, ...options }:\n { onAccount: AccountBase, onCompiler: Compiler, onNode: Node }\n & Parameters<AccountBase['address']>[0]\n): Promise<EncodedData<'tx'>> {\n const wrapInEmptySignedTx = (\n tx: EncodedData<'tx'> | Uint8Array | TxUnpacked<TxSchema>\n ): BuiltTx<TxSchema, 'tx'> => buildTx({ encodedTx: tx, signatures: [] }, TX_TYPE.signed)\n\n if (Object.keys(authData).length <= 0) throw new MissingParamError('authData is required')\n\n const gasLimit = authData.gasLimit ?? MAX_AUTH_FUN_GAS\n if (gasLimit > MAX_AUTH_FUN_GAS) {\n throw new InvalidAuthDataError(`the maximum gasLimit value for ga authFun is ${MAX_AUTH_FUN_GAS}, got ${gasLimit}`)\n }\n\n const authCallData = authData.callData ?? await (async () => {\n if (authData.source == null || authData.args == null) throw new InvalidAuthDataError('Auth data must contain source code and arguments.')\n const contract = await getContractInstance({\n onAccount, onCompiler, onNode, source: authData.source\n })\n return contract.calldata.encode(contract._name, authFnName, authData.args)\n })()\n\n const { abiVersion } = await getVmVersion(TX_TYPE.contractCall, { onNode })\n const wrappedTx = wrapInEmptySignedTx(unpackTx<TX_TYPE.signed>(rawTransaction))\n const params = {\n ...options,\n tx: {\n ...wrappedTx,\n tx: wrappedTx.txObject\n },\n gaId: await onAccount.address(options),\n abiVersion,\n authData: authCallData,\n gasLimit,\n vsn: 2\n }\n // @ts-expect-error createMetaTx needs to be integrated into tx builder\n const { fee } = await prepareTxParams(TX_TYPE.gaMeta, { ...params, onNode })\n const { rlpEncoded: metaTxRlp } = buildTx({ ...params, fee }, TX_TYPE.gaMeta)\n return wrapInEmptySignedTx(metaTxRlp).tx\n}\n\n/**\n * Build a transaction hash the same as `Auth.tx_hash`\n * @param transaction - tx-encoded transaction\n * @param options - Options\n * @param options.onNode - Node to use\n * @returns Transaction hash\n */\nexport async function buildAuthTxHash (\n transaction: EncodedData<'tx'>,\n { onNode }: { onNode: Node }\n): Promise<Uint8Array> {\n const { networkId } = await onNode.getStatus()\n return new Uint8Array(hash(\n concatBuffers([Buffer.from(networkId), decode(transaction)])\n ))\n}\n"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;SAESA,O,EAASC,gB;SACTC,2B,EAA6BC,O,EAA8BC,Q;SAC3DC,Q,EAA0BC,Y,EAAcC,e;SACxCC,I;SACAC,M;SACAC,oB,EAAsBC,iB,EAAmBC,oB;SACzCC,a;SAEAC,mB;SACAC,I;SAEAC,U;;AAGT;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,IAAf,CACLC,OADK,EACuBC,OADvB,EAEa;EAClB,MAAM;IAAEC;EAAF,IAAiB,MAAMJ,UAAU,CAACE,OAAD,EAAUC,OAAV,CAAvC;EACA,OAAOC,UAAU,IAAI,IAArB;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,eAAeC,wBAAf,CACLC,UADK,EAELC,MAFK,EAGLC,IAHK,QAUD;EAAA;;EAAA,IANJ;IAAEC,SAAF;IAAaC,UAAb;IAAyBC,MAAzB;IAAiC,GAAGR;EAApC,CAMI;EACJ,MAAMS,OAAO,GAAG,MAAMH,SAAS,CAACP,OAAV,CAAkBC,OAAlB,CAAtB;EACA,IAAI,MAAMF,IAAI,CAACW,OAAD,EAAU;IAAED;EAAF,CAAV,CAAd,EAAqC,MAAM,IAAIjB,oBAAJ,CAA0B,WAAUkB,OAAQ,gBAA5C,CAAN;EAErC,MAAMC,QAAQ,GAAG,MAAMf,mBAAmB,CAAC;IAAEW,SAAF;IAAaC,UAAb;IAAyBC,MAAzB;IAAiCJ;EAAjC,CAAD,CAA1C;EAEA,MAAMO,EAAE,GAAG,MAAMzB,QAAQ,CAACL,OAAO,CAAC+B,QAA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G,EAAE;EAVQ,CAAf,CAtB4B,CAkC5B;;EACA,MAAM;IAAEC;EAAF,IAAU,MAAMzD,eAAe,CAACP,OAAO,CAACiE,MAAT,EAAiB,EAAE,GAAGL,MAAL;IAAajC;EAAb,CAAjB,CAArC;EACA,MAAM;IAAEuC,UAAU,EAAEC;EAAd,IAA4BhE,OAAO,CAAC,EAAE,GAAGyD,MAAL;IAAaI;EAAb,CAAD,EAAqBhE,OAAO,CAACiE,MAA7B,CAAzC;EACA,OAAOf,mBAAmB,CAACiB,SAAD,CAAnB,CAA+BrC,EAAtC;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,eAAesC,eAAf,CACL3B,WADK,SAGgB;EAAA,IADrB;IAAEd;EAAF,CACqB;EACrB,MAAM;IAAE0C;EAAF,IAAgB,MAAM1C,MAAM,CAAC2C,SAAP,EAA5B;EACA,OAAO,IAAIC,UAAJ,CAAe/D,IAAI,CACxBK,aAAa,CAAC,CAAC,QAAO2D,IAAP,CAAYH,SAAZ,CAAD,EAAyB5D,MAAM,CAACgC,WAAD,CAA/B,CAAD,CADW,CAAnB,CAAP;AAGD"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Contract module - routines to interact with the æternity contract
3
+ *
4
+ * High level documentation of the contracts are available at
5
+ * https://github.com/aeternity/protocol/tree/master/contracts and
6
+ */
7
+ import { AensName } from '../tx/builder/schema';
8
+ import { EncodedData } from '../utils/encoder';
9
+ import AccountBase from '../account/Base';
10
+ import Node from '../Node';
11
+ export { default as getContractInstance } from './aci';
12
+ /**
13
+ * Utility method to create a delegate signature for a contract
14
+ * @param ids - The list of id's to prepend
15
+ * @param opt - Options
16
+ * @param opt.onNode - Node to use
17
+ * @param opt.onAccount - Account to use
18
+ * @returns Signature in hex representation
19
+ */
20
+ declare function delegateSignatureCommon(ids: (`th_${string}` | `ok_${string}` | `ba_${string}` | `cb_${string}` | `or_${string}` | `ov_${string}` | `pi_${string}` | `ss_${string}` | `cs_${string}` | `ck_${string}` | `cv_${string}` | `st_${string}` | `tx_${string}` | `ak_${string}` | `bf_${string}` | `bs_${string}` | `bx_${string}` | `ch_${string}` | `cm_${string}` | `ct_${string}` | `kh_${string}` | `mh_${string}` | `nm_${string}` | `oq_${string}` | `pp_${string}` | `sg_${string}`)[] | undefined, { onAccount, onNode, ...opt }: {
21
+ onAccount: AccountBase;
22
+ onNode: Node;
23
+ } & Parameters<AccountBase['sign']>[1]): Promise<string>;
24
+ /**
25
+ * Helper to generate a signature to delegate pre-claim/claim/transfer/revoke of a name to
26
+ * a contract.
27
+ * @param contractId - Contract Id
28
+ * @param opt - Options
29
+ * @param opt.name - The name
30
+ * @returns Signature for delegation
31
+ * @example
32
+ * ```js
33
+ * const aeSdk = new AeSdk({ ... })
34
+ * const contractId = 'ct_asd2ks...' // contract address
35
+ * const name = 'example.chain' // AENS name
36
+ * const onAccount = await aeSdk.address() // Sign with a specific account
37
+ * // Preclaim signature
38
+ * const preclaimSig = await aeSdk.createAensDelegationSignature(contractId, { onAccount: current })
39
+ * // Claim, transfer and revoke signature
40
+ * const aensDelegationSig = await contract.createAensDelegationSignature(
41
+ * contractId, { name, onAccount: current }
42
+ * )
43
+ * ```
44
+ */
45
+ export declare function createAensDelegationSignature(contractId: EncodedData<'ct'>, opt: Parameters<AccountBase['address']>[0] & Parameters<typeof delegateSignatureCommon>[1] & {
46
+ name?: AensName;
47
+ }): Promise<string>;
48
+ /**
49
+ * Helper to generate a signature to delegate register/extend/respond of a Oracle to a contract.
50
+ * @param contractId - Contract Id
51
+ * @param opt - Options
52
+ * @param opt.queryId - Oracle Query Id
53
+ * @returns Signature for delegation
54
+ * @example
55
+ * ```js
56
+ * const aeSdk = new AeSdk({ ... })
57
+ * const contractId = 'ct_asd2ks...' // contract address
58
+ * const queryId = 'oq_...' // Oracle Query Id
59
+ * const onAccount = await aeSdk.address() // Sign with a specific account
60
+ * // Oracle register and extend signature
61
+ * const oracleDelegationSig = await aeSdk.createOracleDelegationSignature(contractId)
62
+ * // Oracle respond signature
63
+ * const respondSig = await aeSdk.createOracleDelegationSignature(contractId, { queryId })
64
+ * ```
65
+ */
66
+ export declare function createOracleDelegationSignature(contractId: EncodedData<'ct'>, opt: Parameters<AccountBase['address']>[0] & Parameters<typeof delegateSignatureCommon>[1] & {
67
+ queryId?: EncodedData<'oq'>;
68
+ }): Promise<string>;
@@ -0,0 +1,101 @@
1
+ import _buffer from "buffer";
2
+ const {
3
+ Buffer: _Buffer
4
+ } = _buffer;
5
+
6
+ /*
7
+ * ISC License (ISC)
8
+ * Copyright (c) 2022 aeternity developers
9
+ *
10
+ * Permission to use, copy, modify, and/or distribute this software for any
11
+ * purpose with or without fee is hereby granted, provided that the above
12
+ * copyright notice and this permission notice appear in all copies.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16
+ * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
+ * PERFORMANCE OF THIS SOFTWARE.
21
+ */
22
+
23
+ /**
24
+ * Contract module - routines to interact with the æternity contract
25
+ *
26
+ * High level documentation of the contracts are available at
27
+ * https://github.com/aeternity/protocol/tree/master/contracts and
28
+ */
29
+ import { decode, produceNameId } from "../tx/builder/helpers.mjs";
30
+ import { concatBuffers } from "../utils/other.mjs";
31
+ export { default as getContractInstance } from "./aci.mjs";
32
+ /**
33
+ * Utility method to create a delegate signature for a contract
34
+ * @param ids - The list of id's to prepend
35
+ * @param opt - Options
36
+ * @param opt.onNode - Node to use
37
+ * @param opt.onAccount - Account to use
38
+ * @returns Signature in hex representation
39
+ */
40
+
41
+ async function delegateSignatureCommon() {
42
+ let ids = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
43
+ let {
44
+ onAccount,
45
+ onNode,
46
+ ...opt
47
+ } = arguments.length > 1 ? arguments[1] : undefined;
48
+ const signature = await onAccount.sign(concatBuffers([_Buffer.from((await onNode.getStatus()).networkId), ...ids.map(e => decode(e))]), opt);
49
+ return _Buffer.from(signature).toString('hex');
50
+ }
51
+ /**
52
+ * Helper to generate a signature to delegate pre-claim/claim/transfer/revoke of a name to
53
+ * a contract.
54
+ * @param contractId - Contract Id
55
+ * @param opt - Options
56
+ * @param opt.name - The name
57
+ * @returns Signature for delegation
58
+ * @example
59
+ * ```js
60
+ * const aeSdk = new AeSdk({ ... })
61
+ * const contractId = 'ct_asd2ks...' // contract address
62
+ * const name = 'example.chain' // AENS name
63
+ * const onAccount = await aeSdk.address() // Sign with a specific account
64
+ * // Preclaim signature
65
+ * const preclaimSig = await aeSdk.createAensDelegationSignature(contractId, { onAccount: current })
66
+ * // Claim, transfer and revoke signature
67
+ * const aensDelegationSig = await contract.createAensDelegationSignature(
68
+ * contractId, { name, onAccount: current }
69
+ * )
70
+ * ```
71
+ */
72
+
73
+
74
+ export async function createAensDelegationSignature(contractId, opt) {
75
+ return await delegateSignatureCommon([await opt.onAccount.address(opt), ...(opt.name != null ? [produceNameId(opt.name)] : []), contractId], opt);
76
+ }
77
+ /**
78
+ * Helper to generate a signature to delegate register/extend/respond of a Oracle to a contract.
79
+ * @param contractId - Contract Id
80
+ * @param opt - Options
81
+ * @param opt.queryId - Oracle Query Id
82
+ * @returns Signature for delegation
83
+ * @example
84
+ * ```js
85
+ * const aeSdk = new AeSdk({ ... })
86
+ * const contractId = 'ct_asd2ks...' // contract address
87
+ * const queryId = 'oq_...' // Oracle Query Id
88
+ * const onAccount = await aeSdk.address() // Sign with a specific account
89
+ * // Oracle register and extend signature
90
+ * const oracleDelegationSig = await aeSdk.createOracleDelegationSignature(contractId)
91
+ * // Oracle respond signature
92
+ * const respondSig = await aeSdk.createOracleDelegationSignature(contractId, { queryId })
93
+ * ```
94
+ */
95
+
96
+ export async function createOracleDelegationSignature(contractId, opt) {
97
+ var _opt$queryId;
98
+
99
+ return await delegateSignatureCommon([(_opt$queryId = opt.queryId) !== null && _opt$queryId !== void 0 ? _opt$queryId : await opt.onAccount.address(opt), contractId], opt);
100
+ }
101
+ //# sourceMappingURL=methods.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"methods.mjs","names":["decode","produceNameId","concatBuffers","default","getContractInstance","delegateSignatureCommon","ids","onAccount","onNode","opt","signature","sign","from","getStatus","networkId","map","e","toString","createAensDelegationSignature","contractId","address","name","createOracleDelegationSignature","queryId"],"sources":["../../src/contract/methods.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2022 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Contract module - routines to interact with the æternity contract\n *\n * High level documentation of the contracts are available at\n * https://github.com/aeternity/protocol/tree/master/contracts and\n */\n\nimport { AensName } from '../tx/builder/schema'\nimport { decode, produceNameId } from '../tx/builder/helpers'\nimport { concatBuffers } from '../utils/other'\nimport { EncodedData, EncodingType } from '../utils/encoder'\nimport AccountBase from '../account/Base'\nimport Node from '../Node'\nexport { default as getContractInstance } from './aci'\n\n/**\n * Utility method to create a delegate signature for a contract\n * @param ids - The list of id's to prepend\n * @param opt - Options\n * @param opt.onNode - Node to use\n * @param opt.onAccount - Account to use\n * @returns Signature in hex representation\n */\nasync function delegateSignatureCommon (\n ids: Array<EncodedData<EncodingType>> = [],\n { onAccount, onNode, ...opt }:\n { onAccount: AccountBase, onNode: Node } & Parameters<AccountBase['sign']>[1]\n): Promise<string> {\n const signature = await onAccount.sign(\n concatBuffers([\n Buffer.from((await onNode.getStatus()).networkId),\n ...ids.map(e => decode(e))\n ]),\n opt\n )\n return Buffer.from(signature).toString('hex')\n}\n\n/**\n * Helper to generate a signature to delegate pre-claim/claim/transfer/revoke of a name to\n * a contract.\n * @param contractId - Contract Id\n * @param opt - Options\n * @param opt.name - The name\n * @returns Signature for delegation\n * @example\n * ```js\n * const aeSdk = new AeSdk({ ... })\n * const contractId = 'ct_asd2ks...' // contract address\n * const name = 'example.chain' // AENS name\n * const onAccount = await aeSdk.address() // Sign with a specific account\n * // Preclaim signature\n * const preclaimSig = await aeSdk.createAensDelegationSignature(contractId, { onAccount: current })\n * // Claim, transfer and revoke signature\n * const aensDelegationSig = await contract.createAensDelegationSignature(\n * contractId, { name, onAccount: current }\n * )\n * ```\n */\nexport async function createAensDelegationSignature (\n contractId: EncodedData<'ct'>,\n opt: Parameters<AccountBase['address']>[0] & Parameters<typeof delegateSignatureCommon>[1] &\n { name?: AensName }\n): Promise<string> {\n return await delegateSignatureCommon(\n [\n await opt.onAccount.address(opt),\n ...opt.name != null ? [produceNameId(opt.name)] : [],\n contractId\n ],\n opt\n )\n}\n\n/**\n * Helper to generate a signature to delegate register/extend/respond of a Oracle to a contract.\n * @param contractId - Contract Id\n * @param opt - Options\n * @param opt.queryId - Oracle Query Id\n * @returns Signature for delegation\n * @example\n * ```js\n * const aeSdk = new AeSdk({ ... })\n * const contractId = 'ct_asd2ks...' // contract address\n * const queryId = 'oq_...' // Oracle Query Id\n * const onAccount = await aeSdk.address() // Sign with a specific account\n * // Oracle register and extend signature\n * const oracleDelegationSig = await aeSdk.createOracleDelegationSignature(contractId)\n * // Oracle respond signature\n * const respondSig = await aeSdk.createOracleDelegationSignature(contractId, { queryId })\n * ```\n */\nexport async function createOracleDelegationSignature (\n contractId: EncodedData<'ct'>,\n opt: Parameters<AccountBase['address']>[0] & Parameters<typeof delegateSignatureCommon>[1] &\n { queryId?: EncodedData<'oq'> }\n): Promise<string> {\n return await delegateSignatureCommon(\n [opt.queryId ?? await opt.onAccount.address(opt), contractId], opt\n )\n}\n"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;SAGSA,M,EAAQC,a;SACRC,a;SAIAC,OAAO,IAAIC,mB;AAEpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAeC,uBAAf,GAImB;EAAA,IAHjBC,GAGiB,uEAHuB,EAGvB;EAAA,IAFjB;IAAEC,SAAF;IAAaC,MAAb;IAAqB,GAAGC;EAAxB,CAEiB;EACjB,MAAMC,SAAS,GAAG,MAAMH,SAAS,CAACI,IAAV,CACtBT,aAAa,CAAC,CACZ,QAAOU,IAAP,CAAY,CAAC,MAAMJ,MAAM,CAACK,SAAP,EAAP,EAA2BC,SAAvC,CADY,EAEZ,GAAGR,GAAG,CAACS,GAAJ,CAAQC,CAAC,IAAIhB,MAAM,CAACgB,CAAD,CAAnB,CAFS,CAAD,CADS,EAKtBP,GALsB,CAAxB;EAOA,OAAO,QAAOG,IAAP,CAAYF,SAAZ,EAAuBO,QAAvB,CAAgC,KAAhC,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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