@aeternity/aepp-sdk 10.0.0 → 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 (424) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +15 -14
  3. package/dist/aepp-sdk.browser-script.js +1 -1
  4. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +13 -40
  5. package/dist/aepp-sdk.browser-script.js.map +1 -1
  6. package/dist/aepp-sdk.browser.js +1 -1
  7. package/dist/aepp-sdk.browser.js.map +1 -1
  8. package/dist/aepp-sdk.js +1 -1
  9. package/dist/aepp-sdk.js.map +1 -1
  10. package/es/AeSdk.d.ts +37 -0
  11. package/es/AeSdk.mjs +81 -0
  12. package/es/AeSdk.mjs.map +1 -0
  13. package/es/AeSdkAepp.d.ts +69 -0
  14. package/es/AeSdkAepp.mjs +175 -0
  15. package/es/AeSdkAepp.mjs.map +1 -0
  16. package/es/AeSdkBase.d.ts +212 -0
  17. package/es/AeSdkBase.mjs +310 -0
  18. package/es/AeSdkBase.mjs.map +1 -0
  19. package/es/AeSdkWallet.d.ts +103 -0
  20. package/es/AeSdkWallet.mjs +322 -0
  21. package/es/AeSdkWallet.mjs.map +1 -0
  22. package/es/Node.d.ts +44 -0
  23. package/es/Node.mjs +141 -0
  24. package/es/Node.mjs.map +1 -0
  25. package/es/account/Base.d.ts +65 -0
  26. package/es/account/Base.mjs +123 -0
  27. package/es/account/Base.mjs.map +1 -0
  28. package/es/account/Memory.d.ts +25 -0
  29. package/es/account/Memory.mjs +81 -0
  30. package/es/account/Memory.mjs.map +1 -0
  31. package/es/account/Rpc.d.ts +27 -0
  32. package/es/account/Rpc.mjs +79 -0
  33. package/es/account/Rpc.mjs.map +1 -0
  34. package/es/aens.d.ts +209 -0
  35. package/es/aens.mjs +332 -0
  36. package/es/aens.mjs.map +1 -0
  37. package/es/aepp-wallet-communication/connection/Browser.d.ts +32 -0
  38. package/es/aepp-wallet-communication/connection/Browser.mjs +70 -0
  39. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
  40. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +17 -0
  41. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +57 -0
  42. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
  43. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +35 -0
  44. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +142 -0
  45. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
  46. package/es/aepp-wallet-communication/connection-proxy.d.ts +10 -0
  47. package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +15 -11
  48. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
  49. package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +33 -0
  50. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +169 -0
  51. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -0
  52. package/es/aepp-wallet-communication/rpc/types.d.ts +77 -0
  53. package/es/aepp-wallet-communication/rpc/types.mjs +3 -0
  54. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -0
  55. package/es/aepp-wallet-communication/schema.d.ts +118 -0
  56. package/es/aepp-wallet-communication/schema.mjs +214 -0
  57. package/es/aepp-wallet-communication/schema.mjs.map +1 -0
  58. package/es/aepp-wallet-communication/wallet-detector.d.ts +24 -0
  59. package/es/aepp-wallet-communication/wallet-detector.mjs +63 -0
  60. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  61. package/es/apis/compiler/compiler.d.ts +92 -0
  62. package/es/apis/compiler/compiler.mjs +576 -0
  63. package/es/apis/compiler/compiler.mjs.map +1 -0
  64. package/es/apis/compiler/index.d.ts +2 -0
  65. package/es/apis/compiler/index.mjs +3 -0
  66. package/es/apis/compiler/index.mjs.map +1 -0
  67. package/es/apis/compiler/models/index.d.ts +248 -0
  68. package/es/apis/compiler/models/index.mjs +48 -0
  69. package/es/apis/compiler/models/index.mjs.map +1 -0
  70. package/es/apis/compiler/models/mappers.d.ts +23 -0
  71. package/es/apis/compiler/models/mappers.mjs +585 -0
  72. package/es/apis/compiler/models/mappers.mjs.map +1 -0
  73. package/es/apis/compiler/models/parameters.d.ts +13 -0
  74. package/es/apis/compiler/models/parameters.mjs +71 -0
  75. package/es/apis/compiler/models/parameters.mjs.map +1 -0
  76. package/es/apis/node/index.d.ts +2 -0
  77. package/es/apis/node/index.mjs +3 -0
  78. package/es/apis/node/index.mjs.map +1 -0
  79. package/es/apis/node/models/index.d.ts +1061 -0
  80. package/es/apis/node/models/index.mjs +2 -0
  81. package/es/apis/node/models/index.mjs.map +1 -0
  82. package/es/apis/node/models/mappers.d.ts +95 -0
  83. package/es/apis/node/models/mappers.mjs +4164 -0
  84. package/es/apis/node/models/mappers.mjs.map +1 -0
  85. package/es/apis/node/models/parameters.d.ts +17 -0
  86. package/es/apis/node/models/parameters.mjs +165 -0
  87. package/es/apis/node/models/parameters.mjs.map +1 -0
  88. package/es/apis/node/node.d.ts +215 -0
  89. package/es/apis/node/node.mjs +1165 -0
  90. package/es/apis/node/node.mjs.map +1 -0
  91. package/es/chain.d.ts +220 -0
  92. package/es/chain.mjs +524 -0
  93. package/es/chain.mjs.map +1 -0
  94. package/es/channel/handlers.d.ts +34 -0
  95. package/es/channel/{handlers.js → handlers.mjs} +163 -130
  96. package/es/channel/handlers.mjs.map +1 -0
  97. package/es/channel/index.d.ts +634 -0
  98. package/es/channel/index.mjs +978 -0
  99. package/es/channel/index.mjs.map +1 -0
  100. package/es/channel/internal.d.ts +100 -0
  101. package/es/channel/internal.mjs +328 -0
  102. package/es/channel/internal.mjs.map +1 -0
  103. package/es/contract/Compiler.d.ts +17 -0
  104. package/es/contract/Compiler.mjs +67 -0
  105. package/es/contract/Compiler.mjs.map +1 -0
  106. package/es/contract/aci.d.ts +125 -0
  107. package/es/contract/aci.mjs +496 -0
  108. package/es/contract/aci.mjs.map +1 -0
  109. package/es/contract/ga.d.ts +68 -0
  110. package/es/contract/ga.mjs +190 -0
  111. package/es/contract/ga.mjs.map +1 -0
  112. package/es/contract/methods.d.ts +68 -0
  113. package/es/contract/methods.mjs +101 -0
  114. package/es/contract/methods.mjs.map +1 -0
  115. package/es/index.d.ts +32 -0
  116. package/es/index.mjs +49 -0
  117. package/es/index.mjs.map +1 -0
  118. package/es/oracle.d.ts +154 -0
  119. package/es/oracle.mjs +288 -0
  120. package/es/oracle.mjs.map +1 -0
  121. package/es/spend.d.ts +61 -0
  122. package/es/spend.mjs +122 -0
  123. package/es/spend.mjs.map +1 -0
  124. package/es/tx/builder/constants.d.ts +41 -0
  125. package/es/tx/builder/constants.mjs +100 -0
  126. package/es/tx/builder/constants.mjs.map +1 -0
  127. package/es/tx/builder/field-types.d.ts +62 -0
  128. package/es/tx/builder/field-types.mjs +126 -0
  129. package/es/tx/builder/field-types.mjs.map +1 -0
  130. package/es/tx/builder/helpers.d.ts +131 -0
  131. package/es/tx/builder/helpers.mjs +223 -0
  132. package/es/tx/builder/helpers.mjs.map +1 -0
  133. package/es/tx/builder/index.d.ts +75 -0
  134. package/es/tx/builder/index.mjs +424 -0
  135. package/es/tx/builder/index.mjs.map +1 -0
  136. package/es/tx/builder/schema.d.ts +350 -0
  137. package/es/tx/builder/schema.mjs +320 -0
  138. package/es/tx/builder/schema.mjs.map +1 -0
  139. package/es/tx/index.d.ts +63 -0
  140. package/es/tx/index.mjs +209 -0
  141. package/es/tx/index.mjs.map +1 -0
  142. package/es/tx/min-fee.d.ts +20 -0
  143. package/es/tx/min-fee.mjs +148 -0
  144. package/es/tx/min-fee.mjs.map +1 -0
  145. package/es/tx/validator.d.ts +19 -0
  146. package/es/tx/validator.mjs +240 -0
  147. package/es/tx/validator.mjs.map +1 -0
  148. package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
  149. package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
  150. package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
  151. package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
  152. package/es/typings/bip32-path/index.d.mjs +2 -0
  153. package/es/typings/bip32-path/index.d.mjs.map +1 -0
  154. package/es/typings/blakejs/index.d.mjs +2 -0
  155. package/es/typings/blakejs/index.d.mjs.map +1 -0
  156. package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
  157. package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
  158. package/es/utils/amount-formatter.d.ts +42 -0
  159. package/es/utils/{amount-formatter.js → amount-formatter.mjs} +38 -44
  160. package/es/utils/amount-formatter.mjs.map +1 -0
  161. package/es/utils/autorest.d.ts +6 -0
  162. package/es/utils/autorest.mjs +97 -0
  163. package/es/utils/autorest.mjs.map +1 -0
  164. package/es/utils/bignumber.d.ts +13 -0
  165. package/es/utils/bignumber.mjs +23 -0
  166. package/es/utils/bignumber.mjs.map +1 -0
  167. package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
  168. package/es/utils/{bytes.js → bytes.mjs} +26 -22
  169. package/es/utils/bytes.mjs.map +1 -0
  170. package/es/utils/crypto.d.ts +103 -0
  171. package/es/utils/crypto.mjs +221 -0
  172. package/es/utils/crypto.mjs.map +1 -0
  173. package/es/utils/encoder.d.ts +26 -0
  174. package/es/utils/encoder.mjs +102 -0
  175. package/es/utils/encoder.mjs.map +1 -0
  176. package/es/utils/errors.d.ts +481 -0
  177. package/es/utils/errors.mjs +882 -0
  178. package/es/utils/errors.mjs.map +1 -0
  179. package/es/utils/hd-wallet.d.ts +34 -0
  180. package/es/utils/hd-wallet.mjs +122 -0
  181. package/es/utils/hd-wallet.mjs.map +1 -0
  182. package/es/utils/json-big.d.ts +5 -0
  183. package/es/utils/json-big.mjs +41 -0
  184. package/es/utils/json-big.mjs.map +1 -0
  185. package/es/utils/keystore.d.ts +51 -0
  186. package/es/utils/keystore.mjs +145 -0
  187. package/es/utils/keystore.mjs.map +1 -0
  188. package/es/{mptree.d.ts → utils/mptree.d.ts} +5 -8
  189. package/es/utils/{mptree.js → mptree.mjs} +33 -25
  190. package/es/utils/mptree.mjs.map +1 -0
  191. package/es/utils/other.d.ts +14 -0
  192. package/es/utils/other.mjs +28 -0
  193. package/es/utils/other.mjs.map +1 -0
  194. package/es/{semver-satisfies.d.ts → utils/semver-satisfies.d.ts} +0 -0
  195. package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
  196. package/es/utils/semver-satisfies.mjs.map +1 -0
  197. package/es/utils/string.d.ts +24 -0
  198. package/es/utils/{string.js → string.mjs} +9 -11
  199. package/es/utils/string.mjs.map +1 -0
  200. package/package.json +67 -64
  201. package/src/AeSdk.ts +65 -0
  202. package/src/AeSdkAepp.ts +167 -0
  203. package/src/AeSdkBase.ts +320 -0
  204. package/src/AeSdkWallet.ts +332 -0
  205. package/src/Node.ts +167 -0
  206. package/src/account/Base.ts +114 -0
  207. package/src/account/Memory.ts +83 -0
  208. package/src/account/Rpc.ts +67 -0
  209. package/src/aens.ts +391 -0
  210. package/src/aepp-wallet-communication/connection/Browser.ts +68 -0
  211. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +58 -0
  212. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +111 -0
  213. package/{es/utils/crypto-ts.js → src/aepp-wallet-communication/connection-proxy.ts} +16 -9
  214. package/src/aepp-wallet-communication/rpc/RpcClient.ts +137 -0
  215. package/src/aepp-wallet-communication/rpc/types.ts +66 -0
  216. package/src/aepp-wallet-communication/schema.ts +181 -0
  217. package/src/aepp-wallet-communication/wallet-detector.ts +71 -0
  218. package/src/apis/compiler/code-model-v4.yaml +2649 -0
  219. package/src/apis/compiler/compiler.ts +585 -0
  220. package/src/apis/compiler/index.ts +2 -0
  221. package/src/apis/compiler/models/index.ts +301 -0
  222. package/src/apis/compiler/models/mappers.ts +583 -0
  223. package/src/apis/compiler/models/parameters.ts +93 -0
  224. package/src/apis/node/code-model-v4.yaml +10046 -0
  225. package/src/apis/node/index.ts +2 -0
  226. package/src/apis/node/models/index.ts +1253 -0
  227. package/src/apis/node/models/mappers.ts +4278 -0
  228. package/src/apis/node/models/parameters.ts +188 -0
  229. package/src/apis/node/node.ts +1299 -0
  230. package/src/chain.ts +444 -0
  231. package/src/channel/{handlers.js → handlers.ts} +238 -143
  232. package/src/channel/index.ts +991 -0
  233. package/src/channel/internal.ts +345 -0
  234. package/src/contract/Compiler.ts +66 -0
  235. package/src/contract/aci.ts +529 -0
  236. package/src/contract/ga.ts +178 -0
  237. package/src/contract/methods.ts +118 -0
  238. package/src/index.ts +51 -0
  239. package/src/oracle.ts +342 -0
  240. package/src/spend.ts +152 -0
  241. package/src/tx/builder/constants.ts +96 -0
  242. package/src/tx/builder/field-types.ts +111 -0
  243. package/src/tx/builder/helpers.ts +253 -0
  244. package/src/tx/builder/index.ts +394 -0
  245. package/src/tx/builder/schema.ts +771 -0
  246. package/src/tx/index.ts +199 -0
  247. package/src/tx/min-fee.ts +136 -0
  248. package/src/tx/validator.ts +226 -0
  249. package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
  250. package/src/typings/@aeternity__uuid/index.d.ts +3 -0
  251. package/src/typings/bip32-path/index.d.ts +33 -0
  252. package/src/typings/tweetnacl-auth/index.d.ts +14 -0
  253. package/src/utils/amount-formatter.ts +29 -41
  254. package/src/utils/autorest.ts +90 -0
  255. package/src/utils/bignumber.ts +9 -19
  256. package/src/utils/bytes.ts +15 -16
  257. package/src/utils/crypto.ts +217 -0
  258. package/src/utils/encoder.ts +98 -0
  259. package/src/utils/errors.ts +817 -0
  260. package/src/utils/hd-wallet.ts +134 -0
  261. package/src/utils/json-big.ts +26 -0
  262. package/src/utils/keystore.ts +179 -0
  263. package/src/utils/mptree.ts +26 -20
  264. package/src/utils/other.ts +28 -43
  265. package/src/utils/string.ts +8 -10
  266. package/CHANGELOG.md +0 -1603
  267. package/es/account/base.js +0 -169
  268. package/es/account/base.js.map +0 -1
  269. package/es/account/memory.js +0 -84
  270. package/es/account/memory.js.map +0 -1
  271. package/es/account/multiple.js +0 -178
  272. package/es/account/multiple.js.map +0 -1
  273. package/es/ae/aens.js +0 -408
  274. package/es/ae/aens.js.map +0 -1
  275. package/es/ae/aepp.js +0 -45
  276. package/es/ae/aepp.js.map +0 -1
  277. package/es/ae/contract.js +0 -312
  278. package/es/ae/contract.js.map +0 -1
  279. package/es/ae/index.js +0 -206
  280. package/es/ae/index.js.map +0 -1
  281. package/es/ae/oracle.js +0 -322
  282. package/es/ae/oracle.js.map +0 -1
  283. package/es/ae/universal.js +0 -45
  284. package/es/ae/universal.js.map +0 -1
  285. package/es/ae/wallet.js +0 -50
  286. package/es/ae/wallet.js.map +0 -1
  287. package/es/amount-formatter.d.ts +0 -58
  288. package/es/bignumber.d.ts +0 -24
  289. package/es/chain/index.js +0 -256
  290. package/es/chain/index.js.map +0 -1
  291. package/es/chain/node.js +0 -394
  292. package/es/chain/node.js.map +0 -1
  293. package/es/channel/handlers.js.map +0 -1
  294. package/es/channel/index.js +0 -980
  295. package/es/channel/index.js.map +0 -1
  296. package/es/channel/internal.js +0 -266
  297. package/es/channel/internal.js.map +0 -1
  298. package/es/contract/aci/helpers.js +0 -298
  299. package/es/contract/aci/helpers.js.map +0 -1
  300. package/es/contract/aci/index.js +0 -361
  301. package/es/contract/aci/index.js.map +0 -1
  302. package/es/contract/aci/transformation.js +0 -66
  303. package/es/contract/aci/transformation.js.map +0 -1
  304. package/es/contract/compiler.js +0 -244
  305. package/es/contract/compiler.js.map +0 -1
  306. package/es/contract/ga/helpers.js +0 -22
  307. package/es/contract/ga/helpers.js.map +0 -1
  308. package/es/contract/ga/index.js +0 -170
  309. package/es/contract/ga/index.js.map +0 -1
  310. package/es/contract/index.js +0 -162
  311. package/es/contract/index.js.map +0 -1
  312. package/es/crypto-ts.d.ts +0 -9
  313. package/es/index.js +0 -57
  314. package/es/index.js.map +0 -1
  315. package/es/node-pool/index.js +0 -187
  316. package/es/node-pool/index.js.map +0 -1
  317. package/es/node.js +0 -132
  318. package/es/node.js.map +0 -1
  319. package/es/other.d.ts +0 -31
  320. package/es/string.d.ts +0 -26
  321. package/es/tx/builder/helpers.js +0 -305
  322. package/es/tx/builder/helpers.js.map +0 -1
  323. package/es/tx/builder/index.js +0 -595
  324. package/es/tx/builder/index.js.map +0 -1
  325. package/es/tx/builder/schema.js +0 -814
  326. package/es/tx/builder/schema.js.map +0 -1
  327. package/es/tx/index.js +0 -300
  328. package/es/tx/index.js.map +0 -1
  329. package/es/tx/tx-object.js +0 -276
  330. package/es/tx/tx-object.js.map +0 -1
  331. package/es/tx/tx.js +0 -937
  332. package/es/tx/tx.js.map +0 -1
  333. package/es/tx/validator.js +0 -208
  334. package/es/tx/validator.js.map +0 -1
  335. package/es/typings/blakejs/index.d.js +0 -2
  336. package/es/typings/blakejs/index.d.js.map +0 -1
  337. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -131
  338. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  339. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -184
  340. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  341. package/es/utils/aepp-wallet-communication/connection/index.js +0 -84
  342. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  343. package/es/utils/aepp-wallet-communication/content-script-bridge.js +0 -97
  344. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  345. package/es/utils/aepp-wallet-communication/helpers.js +0 -103
  346. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  347. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -329
  348. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  349. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -270
  350. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  351. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -533
  352. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  353. package/es/utils/aepp-wallet-communication/schema.js +0 -107
  354. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  355. package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -109
  356. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  357. package/es/utils/amount-formatter.js.map +0 -1
  358. package/es/utils/async-init.js +0 -67
  359. package/es/utils/async-init.js.map +0 -1
  360. package/es/utils/bignumber.js +0 -28
  361. package/es/utils/bignumber.js.map +0 -1
  362. package/es/utils/bytes.js.map +0 -1
  363. package/es/utils/crypto-ts.js.map +0 -1
  364. package/es/utils/crypto.js +0 -304
  365. package/es/utils/crypto.js.map +0 -1
  366. package/es/utils/hd-wallet.js +0 -112
  367. package/es/utils/hd-wallet.js.map +0 -1
  368. package/es/utils/json-big.js +0 -45
  369. package/es/utils/json-big.js.map +0 -1
  370. package/es/utils/keystore.js +0 -228
  371. package/es/utils/keystore.js.map +0 -1
  372. package/es/utils/mptree.js.map +0 -1
  373. package/es/utils/other.js +0 -43
  374. package/es/utils/other.js.map +0 -1
  375. package/es/utils/semver-satisfies.js.map +0 -1
  376. package/es/utils/string.js.map +0 -1
  377. package/es/utils/swagger.js +0 -132
  378. package/es/utils/swagger.js.map +0 -1
  379. package/src/account/base.js +0 -153
  380. package/src/account/memory.js +0 -78
  381. package/src/account/multiple.js +0 -154
  382. package/src/ae/aens.js +0 -366
  383. package/src/ae/aepp.js +0 -45
  384. package/src/ae/contract.js +0 -285
  385. package/src/ae/index.js +0 -167
  386. package/src/ae/oracle.js +0 -296
  387. package/src/ae/universal.js +0 -47
  388. package/src/ae/wallet.js +0 -50
  389. package/src/chain/index.js +0 -250
  390. package/src/chain/node.js +0 -293
  391. package/src/channel/index.js +0 -898
  392. package/src/channel/internal.js +0 -231
  393. package/src/contract/aci/index.js +0 -317
  394. package/src/contract/aci/transformation.js +0 -72
  395. package/src/contract/compiler.js +0 -195
  396. package/src/contract/ga/helpers.js +0 -17
  397. package/src/contract/ga/index.js +0 -147
  398. package/src/contract/index.js +0 -163
  399. package/src/index.js +0 -90
  400. package/src/node-pool/index.js +0 -171
  401. package/src/node.js +0 -118
  402. package/src/tx/builder/helpers.js +0 -325
  403. package/src/tx/builder/index.js +0 -460
  404. package/src/tx/builder/schema.js +0 -1211
  405. package/src/tx/index.js +0 -301
  406. package/src/tx/tx-object.js +0 -186
  407. package/src/tx/tx.js +0 -622
  408. package/src/tx/validator.js +0 -161
  409. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -114
  410. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -161
  411. package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
  412. package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -85
  413. package/src/utils/aepp-wallet-communication/helpers.js +0 -70
  414. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -268
  415. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -223
  416. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -390
  417. package/src/utils/aepp-wallet-communication/schema.js +0 -108
  418. package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -91
  419. package/src/utils/async-init.js +0 -41
  420. package/src/utils/crypto.js +0 -312
  421. package/src/utils/hd-wallet.js +0 -115
  422. package/src/utils/json-big.js +0 -26
  423. package/src/utils/keystore.js +0 -223
  424. package/src/utils/swagger.js +0 -133
package/es/oracle.d.ts ADDED
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Oracle methods - routines to interact with the æternity oracle system
3
+ *
4
+ * The high-level description of the oracle system is
5
+ * https://github.com/aeternity/protocol/blob/master/ORACLE.md in the protocol
6
+ * repository.
7
+ */
8
+ import { send, SendOptions } from './spend';
9
+ import { ORACLE_TTL_TYPES, TX_TYPE } from './tx/builder/schema';
10
+ import { EncodedData } from './utils/encoder';
11
+ import { _getPollInterval } from './chain';
12
+ import { BuildTxOptions } from './tx';
13
+ import Node from './Node';
14
+ import BigNumber from 'bignumber.js';
15
+ import AccountBase from './account/Base';
16
+ declare type OracleQueries = Awaited<ReturnType<Node['getOracleQueriesByPubkey']>>['oracleQueries'];
17
+ /**
18
+ * Constructor for Oracle Object (helper object for using Oracle)
19
+ * @param oracleId - Oracle public key
20
+ * @param options - Options
21
+ * @returns Oracle object
22
+ */
23
+ export declare function getOracleObject(oracleId: EncodedData<'ok'>, options: {
24
+ onNode: Node;
25
+ onAccount: AccountBase;
26
+ }): Promise<GetOracleObjectReturnType>;
27
+ interface GetOracleObjectReturnType extends Awaited<ReturnType<Node['getOracleByPubkey']>> {
28
+ id: EncodedData<'ok'>;
29
+ queries: OracleQueries;
30
+ pollQueries: (cb: Parameters<typeof pollForQueries>[1]) => ReturnType<typeof pollForQueries>;
31
+ postQuery: Function;
32
+ respondToQuery: Function;
33
+ extendOracle: Function;
34
+ getQuery: Function;
35
+ }
36
+ /**
37
+ * Poll for oracle queries
38
+ * @param oracleId - Oracle public key
39
+ * @param onQuery - OnQuery callback
40
+ * @param options - Options object
41
+ * @param options.interval - Poll interval(default: 5000)
42
+ * @param options.onNode - Node to use
43
+ * @returns Callback to stop polling function
44
+ */
45
+ export declare function pollForQueries(oracleId: EncodedData<'ok'>, onQuery: (queries: OracleQueries) => void, { interval, onNode, ...options }: {
46
+ interval?: number;
47
+ onNode: Node;
48
+ } & Parameters<typeof _getPollInterval>[1]): () => void;
49
+ /**
50
+ * Constructor for OracleQuery Object (helper object for using OracleQuery)
51
+ * @param oracleId - Oracle public key
52
+ * @param queryId - Oracle Query id
53
+ * @param options - Options
54
+ * @returns OracleQuery object
55
+ */
56
+ export declare function getQueryObject(oracleId: EncodedData<'ok'>, queryId: EncodedData<'oq'>, options: RespondToQueryOptions & Parameters<typeof pollForQueryResponse>[2]): Promise<GetQueryObjectReturnType>;
57
+ interface GetQueryObjectReturnType extends Awaited<ReturnType<Node['getOracleQueryByPubkeyAndQueryId']>> {
58
+ decodedQuery: string;
59
+ decodedResponse: string;
60
+ respond: (response: string, options?: Parameters<typeof respondToQuery>[3]) => ReturnType<typeof respondToQuery>;
61
+ pollForResponse: (options?: Parameters<typeof pollForQueryResponse>[2]) => ReturnType<typeof pollForQueryResponse>;
62
+ }
63
+ /**
64
+ * Poll for oracle query response
65
+ * @param oracleId - Oracle public key
66
+ * @param queryId - Oracle Query id
67
+ * @param options - Options object
68
+ * @param options.attempts - Poll attempts
69
+ * @param options.interval - Poll interval
70
+ * @param options.onNode - Node to use
71
+ * @returns OracleQuery object
72
+ */
73
+ export declare function pollForQueryResponse(oracleId: EncodedData<'ok'>, queryId: EncodedData<'oq'>, { attempts, interval, onNode, ...options }: {
74
+ attempts?: number;
75
+ interval?: number;
76
+ onNode: Node;
77
+ } & Parameters<typeof _getPollInterval>[1]): Promise<string>;
78
+ /**
79
+ * Register oracle
80
+ * @param queryFormat - Format of query
81
+ * @param responseFormat - Format of query response
82
+ * @param options - Options
83
+ * @param options.queryFee - Oracle query Fee
84
+ * @param options - Options object
85
+ * @param options.abiVersion - Always 0 (do not use virtual machine)
86
+ * @param options.fee - Transaction fee
87
+ * @param options.ttl - Transaction time to leave
88
+ * @returns Oracle object
89
+ */
90
+ export declare function registerOracle(queryFormat: string, responseFormat: string, options: RegisterOracleOptions): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getOracleObject>>>;
91
+ declare type RegisterOracleOptionsType = SendOptions & Parameters<typeof getOracleObject>[1] & BuildTxOptions<TX_TYPE.oracleRegister, 'accountId' | 'queryFormat' | 'responseFormat' | 'queryFee' | 'oracleTtlType' | 'oracleTtlValue'> & {
92
+ queryFee?: number | string | BigNumber;
93
+ oracleTtlType?: ORACLE_TTL_TYPES;
94
+ oracleTtlValue?: number;
95
+ };
96
+ interface RegisterOracleOptions extends RegisterOracleOptionsType {
97
+ }
98
+ /**
99
+ * Post query to oracle
100
+ * @param oracleId - Oracle public key
101
+ * @param query - Oracle query object
102
+ * @param options - Options object
103
+ * @param options.queryTtl - queryTtl Oracle query time to leave
104
+ * @param options.responseTtl - queryFee Oracle query response time to leave
105
+ * @param options.queryFee - queryFee Oracle query fee
106
+ * @param options.fee - fee Transaction fee
107
+ * @param options.ttl - Transaction time to leave
108
+ * @returns Query object
109
+ */
110
+ export declare function postQueryToOracle(oracleId: EncodedData<'ok'>, query: string, options: PostQueryToOracleOptions): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getQueryObject>>>;
111
+ declare type PostQueryToOracleOptionsType = Parameters<typeof send>[1] & Parameters<typeof getQueryObject>[2] & BuildTxOptions<TX_TYPE.oracleQuery, 'oracleId' | 'senderId' | 'query' | 'queryTtlType' | 'queryTtlValue' | 'responseTtlType' | 'responseTtlValue'> & {
112
+ queryTtlType?: ORACLE_TTL_TYPES;
113
+ queryTtlValue?: number;
114
+ responseTtlType?: ORACLE_TTL_TYPES;
115
+ responseTtlValue?: number;
116
+ };
117
+ interface PostQueryToOracleOptions extends PostQueryToOracleOptionsType {
118
+ }
119
+ /**
120
+ * Extend oracle ttl
121
+ * @param oracleId - Oracle public key
122
+ * @param options - Options object
123
+ * @param options.fee - fee Transaction fee
124
+ * @param options.ttl - Transaction time to leave
125
+ * @param options.oracleTtlType - Oracle time to leave for extend
126
+ * @param options.oracleTtlValue - Oracle time to leave for extend
127
+ * @returns Oracle object
128
+ */
129
+ export declare function extendOracleTtl(oracleId: EncodedData<'ok'>, options: ExtendOracleTtlOptions): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getOracleObject>>>;
130
+ declare type ExtendOracleTtlOptionsType = SendOptions & Parameters<typeof getOracleObject>[1] & BuildTxOptions<TX_TYPE.oracleExtend, 'oracleTtlType' | 'oracleTtlValue' | 'callerId' | 'oracleId'> & {
131
+ oracleTtlType?: ORACLE_TTL_TYPES;
132
+ oracleTtlValue?: number;
133
+ };
134
+ interface ExtendOracleTtlOptions extends ExtendOracleTtlOptionsType {
135
+ }
136
+ /**
137
+ * Extend oracle ttl
138
+ * @param oracleId - Oracle public key
139
+ * @param queryId - Oracle query id
140
+ * @param response - Oracle query response
141
+ * @param options - Options object
142
+ * @param options.responseTtl - responseTtl Query response time to leave
143
+ * @param options.fee - Transaction fee
144
+ * @param options.ttl - Transaction time to leave
145
+ * @returns Oracle object
146
+ */
147
+ export declare function respondToQuery(oracleId: EncodedData<'ok'>, queryId: EncodedData<'oq'>, response: string, options: RespondToQueryOptions): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getOracleObject>>>;
148
+ declare type RespondToQueryOptionsType = SendOptions & Parameters<typeof getOracleObject>[1] & BuildTxOptions<TX_TYPE.oracleResponse, 'callerId' | 'oracleId' | 'queryId' | 'response' | 'responseTtlType' | 'responseTtlValue'> & {
149
+ responseTtlType?: ORACLE_TTL_TYPES;
150
+ responseTtlValue?: number;
151
+ };
152
+ interface RespondToQueryOptions extends RespondToQueryOptionsType {
153
+ }
154
+ export {};
package/es/oracle.mjs ADDED
@@ -0,0 +1,288 @@
1
+ /*
2
+ * ISC License (ISC)
3
+ * Copyright (c) 2022 aeternity developers
4
+ *
5
+ * Permission to use, copy, modify, and/or distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ * PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+
18
+ /**
19
+ * Oracle methods - routines to interact with the æternity oracle system
20
+ *
21
+ * The high-level description of the oracle system is
22
+ * https://github.com/aeternity/protocol/blob/master/ORACLE.md in the protocol
23
+ * repository.
24
+ */
25
+ import { send } from "./spend.mjs";
26
+ import { mapObject, pause } from "./utils/other.mjs";
27
+ import { oracleQueryId, decode, encode } from "./tx/builder/helpers.mjs";
28
+ import { unpackTx } from "./tx/builder/index.mjs";
29
+ import { ORACLE_TTL, QUERY_FEE, QUERY_TTL, RESPONSE_TTL, TX_TYPE } from "./tx/builder/schema.mjs";
30
+ import { RequestTimedOutError } from "./utils/errors.mjs";
31
+ import { _getPollInterval } from "./chain.mjs";
32
+ import { _buildTx } from "./tx/index.mjs";
33
+
34
+ /**
35
+ * Constructor for Oracle Object (helper object for using Oracle)
36
+ * @param oracleId - Oracle public key
37
+ * @param options - Options
38
+ * @returns Oracle object
39
+ */
40
+ export async function getOracleObject(oracleId, options) {
41
+ return { ...(await options.onNode.getOracleByPubkey(oracleId)),
42
+ queries: (await options.onNode.getOracleQueriesByPubkey(oracleId)).oracleQueries,
43
+ ...mapObject({
44
+ pollQueries: pollForQueries,
45
+ postQuery: postQueryToOracle,
46
+ respondToQuery,
47
+ extendOracle: extendOracleTtl,
48
+ getQuery: getQueryObject
49
+ }, _ref => {
50
+ let [name, handler] = _ref;
51
+ return [name, function () {
52
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
53
+ args[_key] = arguments[_key];
54
+ }
55
+
56
+ const lastArg = args[args.length - 1];
57
+
58
+ if (lastArg != null && typeof lastArg === 'object' && lastArg.constructor === Object) {
59
+ Object.assign(lastArg, { ...options,
60
+ ...lastArg
61
+ });
62
+ } else args.push(options);
63
+
64
+ return handler(oracleId, ...args);
65
+ }];
66
+ })
67
+ };
68
+ }
69
+
70
+ /**
71
+ * Poll for oracle queries
72
+ * @param oracleId - Oracle public key
73
+ * @param onQuery - OnQuery callback
74
+ * @param options - Options object
75
+ * @param options.interval - Poll interval(default: 5000)
76
+ * @param options.onNode - Node to use
77
+ * @returns Callback to stop polling function
78
+ */
79
+ export function pollForQueries(oracleId, onQuery, _ref2) {
80
+ var _interval;
81
+
82
+ let {
83
+ interval,
84
+ onNode,
85
+ ...options
86
+ } = _ref2;
87
+ (_interval = interval) !== null && _interval !== void 0 ? _interval : interval = _getPollInterval('microblock', options);
88
+ const knownQueryIds = new Set();
89
+
90
+ const checkNewQueries = async () => {
91
+ var _await$onNode$getOrac;
92
+
93
+ const queries = ((_await$onNode$getOrac = (await onNode.getOracleQueriesByPubkey(oracleId)).oracleQueries) !== null && _await$onNode$getOrac !== void 0 ? _await$onNode$getOrac : []).filter(_ref3 => {
94
+ let {
95
+ id
96
+ } = _ref3;
97
+ return !knownQueryIds.has(id);
98
+ });
99
+ queries.forEach(_ref4 => {
100
+ let {
101
+ id
102
+ } = _ref4;
103
+ return knownQueryIds.add(id);
104
+ });
105
+ if (queries.length > 0) onQuery(queries);
106
+ };
107
+
108
+ let stopped = false; // eslint-disable-next-line @typescript-eslint/no-floating-promises
109
+
110
+ (async () => {
111
+ while (!stopped) {
112
+ // eslint-disable-line no-unmodified-loop-condition
113
+ // TODO: allow to handle this error somehow
114
+ await checkNewQueries().catch(console.error);
115
+ await pause(interval);
116
+ }
117
+ })();
118
+
119
+ return () => {
120
+ stopped = true;
121
+ };
122
+ }
123
+ /**
124
+ * Constructor for OracleQuery Object (helper object for using OracleQuery)
125
+ * @param oracleId - Oracle public key
126
+ * @param queryId - Oracle Query id
127
+ * @param options - Options
128
+ * @returns OracleQuery object
129
+ */
130
+
131
+ export async function getQueryObject(oracleId, queryId, options) {
132
+ const record = await options.onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId);
133
+ return { ...record,
134
+ decodedQuery: decode(record.query).toString(),
135
+ decodedResponse: decode(record.response).toString(),
136
+ respond: async (response, opt) => await respondToQuery(oracleId, queryId, response, { ...options,
137
+ ...opt
138
+ }),
139
+ pollForResponse: async opt => await pollForQueryResponse(oracleId, queryId, { ...options,
140
+ ...opt
141
+ })
142
+ };
143
+ }
144
+
145
+ /**
146
+ * Poll for oracle query response
147
+ * @param oracleId - Oracle public key
148
+ * @param queryId - Oracle Query id
149
+ * @param options - Options object
150
+ * @param options.attempts - Poll attempts
151
+ * @param options.interval - Poll interval
152
+ * @param options.onNode - Node to use
153
+ * @returns OracleQuery object
154
+ */
155
+ export async function pollForQueryResponse(oracleId, queryId, _ref5) {
156
+ var _interval2;
157
+
158
+ let {
159
+ attempts = 20,
160
+ interval,
161
+ onNode,
162
+ ...options
163
+ } = _ref5;
164
+ (_interval2 = interval) !== null && _interval2 !== void 0 ? _interval2 : interval = _getPollInterval('microblock', options);
165
+
166
+ for (let i = 0; i < attempts; i++) {
167
+ if (i > 0) await pause(interval);
168
+ const {
169
+ response
170
+ } = await onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId);
171
+ const responseBuffer = decode(response);
172
+ if (responseBuffer.length > 0) return responseBuffer.toString();
173
+ }
174
+
175
+ throw new RequestTimedOutError((attempts - 1) * interval);
176
+ }
177
+ /**
178
+ * Register oracle
179
+ * @param queryFormat - Format of query
180
+ * @param responseFormat - Format of query response
181
+ * @param options - Options
182
+ * @param options.queryFee - Oracle query Fee
183
+ * @param options - Options object
184
+ * @param options.abiVersion - Always 0 (do not use virtual machine)
185
+ * @param options.fee - Transaction fee
186
+ * @param options.ttl - Transaction time to leave
187
+ * @returns Oracle object
188
+ */
189
+
190
+ export async function registerOracle(queryFormat, responseFormat, options) {
191
+ const accountId = await options.onAccount.address(options);
192
+ const oracleRegisterTx = await _buildTx(TX_TYPE.oracleRegister, {
193
+ queryFee: QUERY_FEE,
194
+ oracleTtlValue: ORACLE_TTL.value,
195
+ oracleTtlType: ORACLE_TTL.type,
196
+ ...options,
197
+ accountId,
198
+ queryFormat,
199
+ responseFormat
200
+ });
201
+ return { ...(await send(oracleRegisterTx, options)),
202
+ ...(await getOracleObject(encode(decode(accountId), 'ok'), options))
203
+ };
204
+ }
205
+
206
+ /**
207
+ * Post query to oracle
208
+ * @param oracleId - Oracle public key
209
+ * @param query - Oracle query object
210
+ * @param options - Options object
211
+ * @param options.queryTtl - queryTtl Oracle query time to leave
212
+ * @param options.responseTtl - queryFee Oracle query response time to leave
213
+ * @param options.queryFee - queryFee Oracle query fee
214
+ * @param options.fee - fee Transaction fee
215
+ * @param options.ttl - Transaction time to leave
216
+ * @returns Query object
217
+ */
218
+ export async function postQueryToOracle(oracleId, query, options) {
219
+ var _options$queryFee;
220
+
221
+ (_options$queryFee = options.queryFee) !== null && _options$queryFee !== void 0 ? _options$queryFee : options.queryFee = (await options.onNode.getOracleByPubkey(oracleId)).queryFee.toString();
222
+ const senderId = await options.onAccount.address(options);
223
+ const oracleQueryTx = await _buildTx(TX_TYPE.oracleQuery, {
224
+ queryTtlType: QUERY_TTL.type,
225
+ queryTtlValue: QUERY_TTL.value,
226
+ responseTtlType: RESPONSE_TTL.type,
227
+ responseTtlValue: RESPONSE_TTL.value,
228
+ ...options,
229
+ oracleId,
230
+ senderId,
231
+ query
232
+ });
233
+ const nonce = unpackTx(oracleQueryTx, TX_TYPE.oracleQuery).tx.nonce;
234
+ const queryId = oracleQueryId(senderId, nonce, oracleId);
235
+ return { ...(await send(oracleQueryTx, options)),
236
+ ...(await getQueryObject(oracleId, queryId, options))
237
+ };
238
+ }
239
+
240
+ /**
241
+ * Extend oracle ttl
242
+ * @param oracleId - Oracle public key
243
+ * @param options - Options object
244
+ * @param options.fee - fee Transaction fee
245
+ * @param options.ttl - Transaction time to leave
246
+ * @param options.oracleTtlType - Oracle time to leave for extend
247
+ * @param options.oracleTtlValue - Oracle time to leave for extend
248
+ * @returns Oracle object
249
+ */
250
+ export async function extendOracleTtl(oracleId, options) {
251
+ const oracleExtendTx = await _buildTx(TX_TYPE.oracleExtend, {
252
+ oracleTtlType: ORACLE_TTL.type,
253
+ oracleTtlValue: ORACLE_TTL.value,
254
+ ...options,
255
+ callerId: await options.onAccount.address(options),
256
+ oracleId
257
+ });
258
+ return { ...(await send(oracleExtendTx, options)),
259
+ ...(await getOracleObject(oracleId, options))
260
+ };
261
+ }
262
+
263
+ /**
264
+ * Extend oracle ttl
265
+ * @param oracleId - Oracle public key
266
+ * @param queryId - Oracle query id
267
+ * @param response - Oracle query response
268
+ * @param options - Options object
269
+ * @param options.responseTtl - responseTtl Query response time to leave
270
+ * @param options.fee - Transaction fee
271
+ * @param options.ttl - Transaction time to leave
272
+ * @returns Oracle object
273
+ */
274
+ export async function respondToQuery(oracleId, queryId, response, options) {
275
+ const oracleRespondTx = await _buildTx(TX_TYPE.oracleResponse, {
276
+ responseTtlType: RESPONSE_TTL.type,
277
+ responseTtlValue: RESPONSE_TTL.value,
278
+ ...options,
279
+ callerId: await options.onAccount.address(options),
280
+ oracleId,
281
+ queryId,
282
+ response
283
+ });
284
+ return { ...(await send(oracleRespondTx, options)),
285
+ ...(await getOracleObject(oracleId, options))
286
+ };
287
+ }
288
+ //# sourceMappingURL=oracle.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oracle.mjs","names":["send","mapObject","pause","oracleQueryId","decode","encode","unpackTx","ORACLE_TTL","QUERY_FEE","QUERY_TTL","RESPONSE_TTL","TX_TYPE","RequestTimedOutError","_getPollInterval","_buildTx","getOracleObject","oracleId","options","onNode","getOracleByPubkey","queries","getOracleQueriesByPubkey","oracleQueries","pollQueries","pollForQueries","postQuery","postQueryToOracle","respondToQuery","extendOracle","extendOracleTtl","getQuery","getQueryObject","name","handler","args","lastArg","length","constructor","Object","assign","push","onQuery","interval","knownQueryIds","Set","checkNewQueries","filter","id","has","forEach","add","stopped","catch","console","error","queryId","record","getOracleQueryByPubkeyAndQueryId","decodedQuery","query","toString","decodedResponse","response","respond","opt","pollForResponse","pollForQueryResponse","attempts","i","responseBuffer","registerOracle","queryFormat","responseFormat","accountId","onAccount","address","oracleRegisterTx","oracleRegister","queryFee","oracleTtlValue","value","oracleTtlType","type","senderId","oracleQueryTx","oracleQuery","queryTtlType","queryTtlValue","responseTtlType","responseTtlValue","nonce","tx","oracleExtendTx","oracleExtend","callerId","oracleRespondTx","oracleResponse"],"sources":["../src/oracle.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 * Oracle methods - routines to interact with the æternity oracle system\n *\n * The high-level description of the oracle system is\n * https://github.com/aeternity/protocol/blob/master/ORACLE.md in the protocol\n * repository.\n */\n\nimport { send, SendOptions } from './spend'\nimport { mapObject, pause } from './utils/other'\nimport { oracleQueryId, decode, encode } from './tx/builder/helpers'\nimport { unpackTx } from './tx/builder'\nimport {\n ORACLE_TTL,\n ORACLE_TTL_TYPES,\n QUERY_FEE,\n QUERY_TTL,\n RESPONSE_TTL,\n TX_TYPE\n} from './tx/builder/schema'\nimport { RequestTimedOutError } from './utils/errors'\nimport { EncodedData } from './utils/encoder'\nimport { _getPollInterval } from './chain'\nimport { _buildTx, BuildTxOptions } from './tx'\nimport Node from './Node'\nimport BigNumber from 'bignumber.js'\nimport AccountBase from './account/Base'\n\ntype OracleQueries = Awaited<ReturnType<Node['getOracleQueriesByPubkey']>>['oracleQueries']\n\n/**\n * Constructor for Oracle Object (helper object for using Oracle)\n * @param oracleId - Oracle public key\n * @param options - Options\n * @returns Oracle object\n */\nexport async function getOracleObject (\n oracleId: EncodedData<'ok'>, options: { onNode: Node, onAccount: AccountBase }\n): Promise<GetOracleObjectReturnType> {\n return {\n ...await options.onNode.getOracleByPubkey(oracleId),\n queries: (await options.onNode.getOracleQueriesByPubkey(oracleId)).oracleQueries,\n ...mapObject<Function, Function>(\n {\n pollQueries: pollForQueries,\n postQuery: postQueryToOracle,\n respondToQuery,\n extendOracle: extendOracleTtl,\n getQuery: getQueryObject\n },\n ([name, handler]) => [\n name,\n function (...args: any) {\n const lastArg = args[args.length - 1]\n if (lastArg != null && typeof lastArg === 'object' && lastArg.constructor === Object) {\n Object.assign(lastArg, { ...options, ...lastArg })\n } else args.push(options)\n return handler(oracleId, ...args)\n }\n ])\n } as any\n}\n\ninterface GetOracleObjectReturnType extends Awaited<ReturnType<Node['getOracleByPubkey']>> {\n id: EncodedData<'ok'>\n queries: OracleQueries\n // TODO: replace getOracleObject with a class\n pollQueries: (cb: Parameters<typeof pollForQueries>[1]) => ReturnType<typeof pollForQueries>\n postQuery: Function\n respondToQuery: Function\n extendOracle: Function\n getQuery: Function\n}\n\n/**\n * Poll for oracle queries\n * @param oracleId - Oracle public key\n * @param onQuery - OnQuery callback\n * @param options - Options object\n * @param options.interval - Poll interval(default: 5000)\n * @param options.onNode - Node to use\n * @returns Callback to stop polling function\n */\nexport function pollForQueries (\n oracleId: EncodedData<'ok'>,\n onQuery: (queries: OracleQueries) => void,\n { interval, onNode, ...options }: { interval?: number, onNode: Node }\n & Parameters<typeof _getPollInterval>[1]\n): () => void {\n interval ??= _getPollInterval('microblock', options)\n const knownQueryIds = new Set()\n const checkNewQueries = async (): Promise<void> => {\n const queries = ((await onNode.getOracleQueriesByPubkey(oracleId)).oracleQueries ?? [])\n .filter(({ id }) => !knownQueryIds.has(id))\n queries.forEach(({ id }) => knownQueryIds.add(id))\n if (queries.length > 0) onQuery(queries)\n }\n\n let stopped = false;\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n (async () => {\n while (!stopped) { // eslint-disable-line no-unmodified-loop-condition\n // TODO: allow to handle this error somehow\n await checkNewQueries().catch(console.error)\n await pause(interval)\n }\n })()\n return () => { stopped = true }\n}\n\n/**\n * Constructor for OracleQuery Object (helper object for using OracleQuery)\n * @param oracleId - Oracle public key\n * @param queryId - Oracle Query id\n * @param options - Options\n * @returns OracleQuery object\n */\nexport async function getQueryObject (\n oracleId: EncodedData<'ok'>,\n queryId: EncodedData<'oq'>,\n options: RespondToQueryOptions & Parameters<typeof pollForQueryResponse>[2]\n): Promise<GetQueryObjectReturnType> {\n const record = await options.onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId)\n return {\n ...record,\n decodedQuery: decode(record.query as EncodedData<'oq'>).toString(),\n decodedResponse: decode(record.response as EncodedData<'or'>).toString(),\n respond: async (response, opt) =>\n await respondToQuery(oracleId, queryId, response, { ...options, ...opt }),\n pollForResponse: async (opt) =>\n await pollForQueryResponse(oracleId, queryId, { ...options, ...opt })\n }\n}\n\ninterface GetQueryObjectReturnType extends Awaited<ReturnType<Node['getOracleQueryByPubkeyAndQueryId']>> {\n decodedQuery: string\n decodedResponse: string\n respond: (response: string, options?: Parameters<typeof respondToQuery>[3]) =>\n ReturnType<typeof respondToQuery>\n pollForResponse: (options?: Parameters<typeof pollForQueryResponse>[2]) =>\n ReturnType<typeof pollForQueryResponse>\n}\n\n/**\n * Poll for oracle query response\n * @param oracleId - Oracle public key\n * @param queryId - Oracle Query id\n * @param options - Options object\n * @param options.attempts - Poll attempts\n * @param options.interval - Poll interval\n * @param options.onNode - Node to use\n * @returns OracleQuery object\n */\nexport async function pollForQueryResponse (\n oracleId: EncodedData<'ok'>,\n queryId: EncodedData<'oq'>,\n { attempts = 20, interval, onNode, ...options }:\n { attempts?: number, interval?: number, onNode: Node } & Parameters<typeof _getPollInterval>[1]\n): Promise<string> {\n interval ??= _getPollInterval('microblock', options)\n for (let i = 0; i < attempts; i++) {\n if (i > 0) await pause(interval)\n const { response } = await onNode.getOracleQueryByPubkeyAndQueryId(oracleId, queryId)\n const responseBuffer = decode(response as EncodedData<'or'>)\n if (responseBuffer.length > 0) return responseBuffer.toString()\n }\n throw new RequestTimedOutError((attempts - 1) * interval)\n}\n\n/**\n * Register oracle\n * @param queryFormat - Format of query\n * @param responseFormat - Format of query response\n * @param options - Options\n * @param options.queryFee - Oracle query Fee\n * @param options - Options object\n * @param options.abiVersion - Always 0 (do not use virtual machine)\n * @param options.fee - Transaction fee\n * @param options.ttl - Transaction time to leave\n * @returns Oracle object\n */\nexport async function registerOracle (\n queryFormat: string, responseFormat: string, options: RegisterOracleOptions\n): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getOracleObject>>> {\n const accountId = await options.onAccount.address(options)\n const oracleRegisterTx = await _buildTx(TX_TYPE.oracleRegister, {\n queryFee: QUERY_FEE,\n oracleTtlValue: ORACLE_TTL.value,\n oracleTtlType: ORACLE_TTL.type,\n ...options,\n accountId,\n queryFormat,\n responseFormat\n })\n return {\n ...await send(oracleRegisterTx, options),\n ...await getOracleObject(encode(decode(accountId), 'ok'), options)\n }\n}\n\ntype RegisterOracleOptionsType = SendOptions & Parameters<typeof getOracleObject>[1]\n& BuildTxOptions<TX_TYPE.oracleRegister, 'accountId' | 'queryFormat' | 'responseFormat' | 'queryFee' | 'oracleTtlType' | 'oracleTtlValue'>\n& {\n queryFee?: number | string | BigNumber\n oracleTtlType?: ORACLE_TTL_TYPES\n oracleTtlValue?: number\n}\ninterface RegisterOracleOptions extends RegisterOracleOptionsType {}\n\n/**\n * Post query to oracle\n * @param oracleId - Oracle public key\n * @param query - Oracle query object\n * @param options - Options object\n * @param options.queryTtl - queryTtl Oracle query time to leave\n * @param options.responseTtl - queryFee Oracle query response time to leave\n * @param options.queryFee - queryFee Oracle query fee\n * @param options.fee - fee Transaction fee\n * @param options.ttl - Transaction time to leave\n * @returns Query object\n */\nexport async function postQueryToOracle (oracleId: EncodedData<'ok'>,\n query: string, options: PostQueryToOracleOptions\n): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getQueryObject>>> {\n options.queryFee ??= (await options.onNode.getOracleByPubkey(oracleId)).queryFee.toString()\n const senderId = await options.onAccount.address(options)\n\n const oracleQueryTx = await _buildTx(TX_TYPE.oracleQuery, {\n queryTtlType: QUERY_TTL.type,\n queryTtlValue: QUERY_TTL.value,\n responseTtlType: RESPONSE_TTL.type,\n responseTtlValue: RESPONSE_TTL.value,\n ...options,\n oracleId,\n senderId,\n query\n })\n const nonce = unpackTx(oracleQueryTx, TX_TYPE.oracleQuery).tx.nonce\n const queryId = oracleQueryId(senderId, nonce, oracleId)\n return {\n ...await send(oracleQueryTx, options),\n ...await getQueryObject(oracleId, queryId, options)\n }\n}\n\ntype PostQueryToOracleOptionsType = Parameters<typeof send>[1]\n& Parameters<typeof getQueryObject>[2]\n& BuildTxOptions<TX_TYPE.oracleQuery, 'oracleId' | 'senderId' | 'query' | 'queryTtlType' | 'queryTtlValue' | 'responseTtlType' | 'responseTtlValue'>\n& {\n queryTtlType?: ORACLE_TTL_TYPES\n queryTtlValue?: number\n responseTtlType?: ORACLE_TTL_TYPES\n responseTtlValue?: number\n}\ninterface PostQueryToOracleOptions extends PostQueryToOracleOptionsType {}\n\n/**\n * Extend oracle ttl\n * @param oracleId - Oracle public key\n * @param options - Options object\n * @param options.fee - fee Transaction fee\n * @param options.ttl - Transaction time to leave\n * @param options.oracleTtlType - Oracle time to leave for extend\n * @param options.oracleTtlValue - Oracle time to leave for extend\n * @returns Oracle object\n */\nexport async function extendOracleTtl (\n oracleId: EncodedData<'ok'>,\n options: ExtendOracleTtlOptions\n): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getOracleObject>>> {\n const oracleExtendTx = await _buildTx(TX_TYPE.oracleExtend, {\n oracleTtlType: ORACLE_TTL.type,\n oracleTtlValue: ORACLE_TTL.value,\n ...options,\n callerId: await options.onAccount.address(options),\n oracleId\n })\n return {\n ...await send(oracleExtendTx, options),\n ...await getOracleObject(oracleId, options)\n }\n}\n\ntype ExtendOracleTtlOptionsType = SendOptions & Parameters<typeof getOracleObject>[1]\n& BuildTxOptions<TX_TYPE.oracleExtend, 'oracleTtlType' | 'oracleTtlValue' | 'callerId' | 'oracleId'>\n& { oracleTtlType?: ORACLE_TTL_TYPES, oracleTtlValue?: number }\ninterface ExtendOracleTtlOptions extends ExtendOracleTtlOptionsType {}\n\n/**\n * Extend oracle ttl\n * @param oracleId - Oracle public key\n * @param queryId - Oracle query id\n * @param response - Oracle query response\n * @param options - Options object\n * @param options.responseTtl - responseTtl Query response time to leave\n * @param options.fee - Transaction fee\n * @param options.ttl - Transaction time to leave\n * @returns Oracle object\n */\nexport async function respondToQuery (\n oracleId: EncodedData<'ok'>,\n queryId: EncodedData<'oq'>,\n response: string,\n options: RespondToQueryOptions\n): Promise<Awaited<ReturnType<typeof send>> & Awaited<ReturnType<typeof getOracleObject>>> {\n const oracleRespondTx = await _buildTx(TX_TYPE.oracleResponse, {\n responseTtlType: RESPONSE_TTL.type,\n responseTtlValue: RESPONSE_TTL.value,\n ...options,\n callerId: await options.onAccount.address(options),\n oracleId,\n queryId,\n response\n })\n return {\n ...await send(oracleRespondTx, options),\n ...await getOracleObject(oracleId, options)\n }\n}\n\ntype RespondToQueryOptionsType = SendOptions & Parameters<typeof getOracleObject>[1]\n& BuildTxOptions<TX_TYPE.oracleResponse, 'callerId' | 'oracleId' | 'queryId' | 'response' | 'responseTtlType' | 'responseTtlValue'>\n& { responseTtlType?: ORACLE_TTL_TYPES, responseTtlValue?: number }\ninterface RespondToQueryOptions extends RespondToQueryOptionsType {}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;SAESA,I;SACAC,S,EAAWC,K;SACXC,a,EAAeC,M,EAAQC,M;SACvBC,Q;SAEPC,U,EAE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A;AACA,OAAO,eAAeU,cAAf,CACLX,QADK,EAELuC,OAFK,EAGLO,QAHK,EAIL7C,OAJK,EAKoF;EACzF,MAAM8E,eAAe,GAAG,MAAMjF,QAAQ,CAACH,OAAO,CAACqF,cAAT,EAAyB;IAC7DR,eAAe,EAAE9E,YAAY,CAACwE,IAD+B;IAE7DO,gBAAgB,EAAE/E,YAAY,CAACsE,KAF8B;IAG7D,GAAG/D,OAH0D;IAI7D6E,QAAQ,EAAE,MAAM7E,OAAO,CAACyD,SAAR,CAAkBC,OAAlB,CAA0B1D,OAA1B,CAJ6C;IAK7DD,QAL6D;IAM7DuC,OAN6D;IAO7DO;EAP6D,CAAzB,CAAtC;EASA,OAAO,EACL,IAAG,MAAM9D,IAAI,CAAC+F,eAAD,EAAkB9E,OAAlB,CAAb,CADK;IAEL,IAAG,MAAMF,eAAe,CAACC,QAAD,EAAWC,OAAX,CAAxB;EAFK,CAAP;AAID"}
package/es/spend.d.ts ADDED
@@ -0,0 +1,61 @@
1
+ import { sendTransaction, resolveName } from './chain';
2
+ import { BuildTxOptions } from './tx';
3
+ import { EncodedData } from './utils/encoder';
4
+ import { createMetaTx } from './contract/ga';
5
+ import { TX_TYPE, AensName } from './tx/builder/schema';
6
+ import AccountBase from './account/Base';
7
+ /**
8
+ * Sign and post a transaction to the chain
9
+ * @param tx - Transaction
10
+ * @param options - Options
11
+ * @param options.verify - Verify transaction before broadcast, throw error if not
12
+ * valid
13
+ * @returns Transaction
14
+ */
15
+ export declare function send(tx: EncodedData<'tx'>, options: SendOptions): Promise<SendReturnType>;
16
+ declare type SendOptionsType = Parameters<AccountBase['signTransaction']>[1] & Parameters<typeof sendTransaction>[1] & Partial<Omit<Parameters<typeof signUsingGA>[1], 'onAccount' | 'onCompiler'>> & Pick<Parameters<typeof signUsingGA>[1], 'onAccount' | 'onCompiler'>;
17
+ export interface SendOptions extends SendOptionsType {
18
+ }
19
+ interface SendReturnType extends Awaited<ReturnType<typeof sendTransaction>> {
20
+ }
21
+ export declare function signUsingGA(tx: EncodedData<'tx'>, { authData, authFun, ...options }: {
22
+ authData: Parameters<typeof createMetaTx>[1];
23
+ authFun: Parameters<typeof createMetaTx>[2];
24
+ } & Parameters<typeof createMetaTx>[3]): Promise<EncodedData<'tx'>>;
25
+ /**
26
+ * Send coins to another account
27
+ * @param amount - Amount to spend
28
+ * @param recipientIdOrName - Address or name of recipient account
29
+ * @param options - Options
30
+ * @returns Transaction
31
+ */
32
+ export declare function spend(amount: number | string, recipientIdOrName: EncodedData<'ak'> | AensName, options: SpendOptions): ReturnType<typeof send>;
33
+ declare type SpendOptionsType = BuildTxOptions<TX_TYPE.spend, 'senderId' | 'recipientId' | 'amount'> & Parameters<typeof resolveName>[2] & {
34
+ onAccount: AccountBase;
35
+ } & SendOptions;
36
+ interface SpendOptions extends SpendOptionsType {
37
+ }
38
+ /**
39
+ * Send a fraction of coin balance to another account
40
+ * @param fraction - Fraction of balance to spend (between 0 and 1)
41
+ * @param recipientIdOrName - Address or name of recipient account
42
+ * @param options - Options
43
+ * @returns Transaction
44
+ */
45
+ export declare function transferFunds(fraction: number | string, recipientIdOrName: AensName | EncodedData<'ak'>, options: TransferFundsOptions): ReturnType<typeof send>;
46
+ declare type TransferFundsOptionsType = BuildTxOptions<TX_TYPE.spend, 'senderId' | 'recipientId' | 'amount'> & Parameters<typeof resolveName>[2] & {
47
+ onAccount: AccountBase;
48
+ } & SendOptions;
49
+ interface TransferFundsOptions extends TransferFundsOptionsType {
50
+ }
51
+ /**
52
+ * Submit transaction of another account paying for it (fee and gas)
53
+ * @param transaction - tx_<base64>-encoded transaction
54
+ * @param options - Options
55
+ * @returns Object Transaction
56
+ */
57
+ export declare function payForTransaction(transaction: EncodedData<'tx'>, options: PayForTransactionOptions): ReturnType<typeof send>;
58
+ interface PayForTransactionOptions extends BuildTxOptions<TX_TYPE.payingFor, 'payerId' | 'tx'>, SendOptions {
59
+ onAccount: AccountBase;
60
+ }
61
+ export {};
package/es/spend.mjs ADDED
@@ -0,0 +1,122 @@
1
+ /*
2
+ * ISC License (ISC)
3
+ * Copyright (c) 2022 aeternity developers
4
+ *
5
+ * Permission to use, copy, modify, and/or distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ * PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+ import { sendTransaction, getAccount, getBalance, resolveName } from "./chain.mjs";
18
+ import { _buildTx } from "./tx/index.mjs";
19
+ import { buildTxHash, unpackTx } from "./tx/builder/index.mjs";
20
+ import BigNumber from 'bignumber.js';
21
+ import { ArgumentError } from "./utils/errors.mjs";
22
+ import { createMetaTx } from "./contract/ga.mjs";
23
+ import { TX_TYPE } from "./tx/builder/schema.mjs";
24
+
25
+ /**
26
+ * Sign and post a transaction to the chain
27
+ * @param tx - Transaction
28
+ * @param options - Options
29
+ * @param options.verify - Verify transaction before broadcast, throw error if not
30
+ * valid
31
+ * @returns Transaction
32
+ */
33
+ export async function send(tx, options) {
34
+ const {
35
+ contractId,
36
+ authFun = undefined
37
+ } = options.innerTx === true ? {
38
+ contractId: null
39
+ } : await getAccount(await options.onAccount.address(options), options);
40
+ const signed = contractId != null // TODO: not required arguments become required depending on account type, can ga be extracted?
41
+ ? await signUsingGA(tx, {
42
+ authData: {},
43
+ ...options,
44
+ authFun: authFun
45
+ }) : await options.onAccount.signTransaction(tx, options);
46
+ return options.innerTx === true ? {
47
+ hash: buildTxHash(signed),
48
+ rawTx: signed
49
+ } : await sendTransaction(signed, options);
50
+ }
51
+ export async function signUsingGA(tx, _ref) {
52
+ let {
53
+ authData,
54
+ authFun,
55
+ ...options
56
+ } = _ref;
57
+ return await createMetaTx(tx, authData, authFun, options);
58
+ }
59
+ /**
60
+ * Send coins to another account
61
+ * @param amount - Amount to spend
62
+ * @param recipientIdOrName - Address or name of recipient account
63
+ * @param options - Options
64
+ * @returns Transaction
65
+ */
66
+
67
+ export async function spend(amount, recipientIdOrName, options) {
68
+ return await send(await _buildTx(TX_TYPE.spend, { ...options,
69
+ senderId: await options.onAccount.address(options),
70
+ recipientId: await resolveName(recipientIdOrName, 'account_pubkey', options),
71
+ amount
72
+ }), options);
73
+ }
74
+ // TODO: Rename to spendFraction
75
+
76
+ /**
77
+ * Send a fraction of coin balance to another account
78
+ * @param fraction - Fraction of balance to spend (between 0 and 1)
79
+ * @param recipientIdOrName - Address or name of recipient account
80
+ * @param options - Options
81
+ * @returns Transaction
82
+ */
83
+ export async function transferFunds(fraction, recipientIdOrName, options) {
84
+ if (fraction < 0 || fraction > 1) {
85
+ throw new ArgumentError('fraction', 'a number between 0 and 1', fraction);
86
+ }
87
+
88
+ const recipientId = await resolveName(recipientIdOrName, 'account_pubkey', options);
89
+ const senderId = await options.onAccount.address(options);
90
+ const balance = new BigNumber(await getBalance.bind(options.onAccount)(senderId, options));
91
+ const desiredAmount = balance.times(fraction).integerValue(BigNumber.ROUND_HALF_UP);
92
+ const {
93
+ tx: {
94
+ fee
95
+ }
96
+ } = unpackTx(await _buildTx(TX_TYPE.spend, { ...options,
97
+ senderId,
98
+ recipientId,
99
+ amount: desiredAmount
100
+ }), TX_TYPE.spend); // Reducing of the amount may reduce transaction fee, so this is not completely accurate
101
+
102
+ const amount = desiredAmount.plus(fee).gt(balance) ? balance.minus(fee) : desiredAmount;
103
+ return await send(await _buildTx(TX_TYPE.spend, { ...options,
104
+ senderId,
105
+ recipientId,
106
+ amount
107
+ }), options);
108
+ }
109
+
110
+ /**
111
+ * Submit transaction of another account paying for it (fee and gas)
112
+ * @param transaction - tx_<base64>-encoded transaction
113
+ * @param options - Options
114
+ * @returns Object Transaction
115
+ */
116
+ export async function payForTransaction(transaction, options) {
117
+ return await send(await _buildTx(TX_TYPE.payingFor, { ...options,
118
+ payerId: await options.onAccount.address(options),
119
+ tx: transaction
120
+ }), options);
121
+ }
122
+ //# sourceMappingURL=spend.mjs.map