@aeternity/aepp-sdk 13.2.2 → 13.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (494) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/bin/aesophia_cli +0 -0
  4. package/bin/aesophia_cli_8 +0 -0
  5. package/dist/aepp-sdk.browser-script.js +1 -1
  6. package/dist/aepp-sdk.browser-script.js.map +1 -1
  7. package/dist/aepp-sdk.browser.js +1 -1
  8. package/dist/aepp-sdk.browser.js.map +1 -1
  9. package/dist/aepp-sdk.js +9171 -7086
  10. package/dist/aepp-sdk.js.map +1 -1
  11. package/es/AeSdk.d.ts +3 -0
  12. package/es/AeSdk.mjs +12 -12
  13. package/es/AeSdk.mjs.map +1 -1
  14. package/es/AeSdkAepp.d.ts +0 -1
  15. package/es/AeSdkAepp.mjs +12 -16
  16. package/es/AeSdkAepp.mjs.map +1 -1
  17. package/es/AeSdkBase.d.ts +61 -6
  18. package/es/AeSdkBase.mjs +150 -69
  19. package/es/AeSdkBase.mjs.map +1 -1
  20. package/es/AeSdkMethods.d.ts +19 -7
  21. package/es/AeSdkMethods.mjs +39 -38
  22. package/es/AeSdkMethods.mjs.map +1 -1
  23. package/es/AeSdkWallet.mjs +86 -55
  24. package/es/AeSdkWallet.mjs.map +1 -1
  25. package/es/Middleware.mjs +31 -27
  26. package/es/Middleware.mjs.map +1 -1
  27. package/es/MiddlewareSubscriber.mjs +5 -14
  28. package/es/MiddlewareSubscriber.mjs.map +1 -1
  29. package/es/Node.d.ts +10 -2
  30. package/es/Node.mjs +53 -54
  31. package/es/Node.mjs.map +1 -1
  32. package/es/account/Base.d.ts +39 -3
  33. package/es/account/Base.mjs +35 -1
  34. package/es/account/Base.mjs.map +1 -1
  35. package/es/account/Generalized.d.ts +2 -0
  36. package/es/account/Generalized.mjs +15 -6
  37. package/es/account/Generalized.mjs.map +1 -1
  38. package/es/account/Ledger.d.ts +2 -0
  39. package/es/account/Ledger.mjs +14 -5
  40. package/es/account/Ledger.mjs.map +1 -1
  41. package/es/account/LedgerFactory.mjs +4 -6
  42. package/es/account/LedgerFactory.mjs.map +1 -1
  43. package/es/account/Memory.d.ts +15 -4
  44. package/es/account/Memory.mjs +96 -31
  45. package/es/account/Memory.mjs.map +1 -1
  46. package/es/account/Rpc.d.ts +16 -5
  47. package/es/account/Rpc.mjs +94 -21
  48. package/es/account/Rpc.mjs.map +1 -1
  49. package/es/aens.d.ts +17 -44
  50. package/es/aens.mjs +32 -71
  51. package/es/aens.mjs.map +1 -1
  52. package/es/aepp-wallet-communication/connection/Browser.mjs +3 -4
  53. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
  54. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +3 -0
  55. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +7 -5
  56. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
  57. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +8 -9
  58. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
  59. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +7 -7
  60. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
  61. package/es/aepp-wallet-communication/rpc/types.d.ts +14 -0
  62. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
  63. package/es/aepp-wallet-communication/schema.d.ts +2 -0
  64. package/es/aepp-wallet-communication/schema.mjs +2 -0
  65. package/es/aepp-wallet-communication/schema.mjs.map +1 -1
  66. package/es/aepp-wallet-communication/wallet-detector.mjs +4 -5
  67. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
  68. package/es/apis/compiler/compiler.mjs.map +1 -1
  69. package/es/apis/compiler/models/index.d.ts +1 -0
  70. package/es/apis/compiler/models/index.mjs.map +1 -1
  71. package/es/apis/compiler/models/mappers.mjs +13 -0
  72. package/es/apis/compiler/models/mappers.mjs.map +1 -1
  73. package/es/apis/compiler/models/parameters.mjs.map +1 -1
  74. package/es/apis/middleware/middleware.d.ts +23 -5
  75. package/es/apis/middleware/middleware.mjs +114 -18
  76. package/es/apis/middleware/middleware.mjs.map +1 -1
  77. package/es/apis/middleware/models/index.d.ts +164 -15
  78. package/es/apis/middleware/models/index.mjs +53 -3
  79. package/es/apis/middleware/models/index.mjs.map +1 -1
  80. package/es/apis/middleware/models/mappers.d.ts +8 -1
  81. package/es/apis/middleware/models/mappers.mjs +376 -3
  82. package/es/apis/middleware/models/mappers.mjs.map +1 -1
  83. package/es/apis/middleware/models/parameters.d.ts +6 -3
  84. package/es/apis/middleware/models/parameters.mjs +38 -11
  85. package/es/apis/middleware/models/parameters.mjs.map +1 -1
  86. package/es/apis/node/models/index.d.ts +66 -2
  87. package/es/apis/node/models/index.mjs.map +1 -1
  88. package/es/apis/node/models/mappers.d.ts +5 -1
  89. package/es/apis/node/models/mappers.mjs +229 -7
  90. package/es/apis/node/models/mappers.mjs.map +1 -1
  91. package/es/apis/node/models/parameters.d.ts +2 -2
  92. package/es/apis/node/models/parameters.mjs +2 -2
  93. package/es/apis/node/models/parameters.mjs.map +1 -1
  94. package/es/apis/node/node.d.ts +24 -3
  95. package/es/apis/node/node.mjs +135 -3
  96. package/es/apis/node/node.mjs.map +1 -1
  97. package/es/chain.d.ts +14 -44
  98. package/es/chain.mjs +125 -219
  99. package/es/chain.mjs.map +1 -1
  100. package/es/channel/Base.d.ts +3 -47
  101. package/es/channel/Base.mjs +21 -54
  102. package/es/channel/Base.mjs.map +1 -1
  103. package/es/channel/Contract.d.ts +16 -25
  104. package/es/channel/Contract.mjs +39 -63
  105. package/es/channel/Contract.mjs.map +1 -1
  106. package/es/channel/Spend.d.ts +0 -8
  107. package/es/channel/Spend.mjs +17 -29
  108. package/es/channel/Spend.mjs.map +1 -1
  109. package/es/channel/handlers.mjs +1 -1
  110. package/es/channel/handlers.mjs.map +1 -1
  111. package/es/channel/internal.d.ts +104 -5
  112. package/es/channel/internal.mjs +26 -34
  113. package/es/channel/internal.mjs.map +1 -1
  114. package/es/contract/Contract.d.ts +9 -1
  115. package/es/contract/Contract.mjs +67 -73
  116. package/es/contract/Contract.mjs.map +1 -1
  117. package/es/contract/compiler/Base.d.ts +14 -8
  118. package/es/contract/compiler/Base.mjs.map +1 -1
  119. package/es/contract/compiler/Cli.d.ts +5 -9
  120. package/es/contract/compiler/Cli.mjs +45 -23
  121. package/es/contract/compiler/Cli.mjs.map +1 -1
  122. package/es/contract/compiler/Cli8.d.ts +13 -0
  123. package/es/contract/compiler/Cli8.mjs +22 -0
  124. package/es/contract/compiler/Cli8.mjs.map +1 -0
  125. package/es/contract/compiler/Http.d.ts +3 -9
  126. package/es/contract/compiler/Http.mjs +28 -16
  127. package/es/contract/compiler/Http.mjs.map +1 -1
  128. package/es/contract/compiler/HttpNode.d.ts +2 -5
  129. package/es/contract/compiler/HttpNode.mjs.map +1 -1
  130. package/es/contract/delegation-signature.d.ts +2 -1
  131. package/es/contract/delegation-signature.mjs +18 -14
  132. package/es/contract/delegation-signature.mjs.map +1 -1
  133. package/es/contract/ga.d.ts +1 -2
  134. package/es/contract/ga.mjs +23 -25
  135. package/es/contract/ga.mjs.map +1 -1
  136. package/es/deprecated.d.ts +38 -0
  137. package/es/deprecated.mjs +45 -0
  138. package/es/deprecated.mjs.map +1 -1
  139. package/es/index-browser.d.ts +10 -5
  140. package/es/index-browser.mjs +9 -5
  141. package/es/index-browser.mjs.map +1 -1
  142. package/es/index.d.ts +1 -0
  143. package/es/index.mjs +1 -0
  144. package/es/index.mjs.map +1 -1
  145. package/es/oracle.d.ts +6 -37
  146. package/es/oracle.mjs +32 -66
  147. package/es/oracle.mjs.map +1 -1
  148. package/es/send-transaction.d.ts +53 -0
  149. package/es/send-transaction.mjs +109 -0
  150. package/es/send-transaction.mjs.map +1 -0
  151. package/es/spend.d.ts +4 -3
  152. package/es/spend.mjs +6 -1
  153. package/es/spend.mjs.map +1 -1
  154. package/es/tx/builder/common.d.ts +29 -0
  155. package/es/tx/builder/common.mjs +42 -0
  156. package/es/tx/builder/common.mjs.map +1 -0
  157. package/es/tx/builder/constants.d.ts +4 -4
  158. package/es/tx/builder/constants.mjs +6 -15
  159. package/es/tx/builder/constants.mjs.map +1 -1
  160. package/es/tx/builder/delegation/index.d.ts +20 -0
  161. package/es/tx/builder/delegation/index.mjs +24 -0
  162. package/es/tx/builder/delegation/index.mjs.map +1 -0
  163. package/es/tx/builder/delegation/schema.d.ts +130 -0
  164. package/es/tx/builder/delegation/schema.generated.d.ts +141 -0
  165. package/es/tx/builder/delegation/schema.generated.mjs +2 -0
  166. package/es/tx/builder/delegation/schema.generated.mjs.map +1 -0
  167. package/es/tx/builder/delegation/schema.mjs +54 -0
  168. package/es/tx/builder/delegation/schema.mjs.map +1 -0
  169. package/es/tx/builder/field-types/abi-version.mjs +8 -11
  170. package/es/tx/builder/field-types/abi-version.mjs.map +1 -1
  171. package/es/tx/builder/field-types/address.mjs +1 -4
  172. package/es/tx/builder/field-types/address.mjs.map +1 -1
  173. package/es/tx/builder/field-types/coin-amount.d.ts +2 -2
  174. package/es/tx/builder/field-types/coin-amount.mjs +6 -6
  175. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
  176. package/es/tx/builder/field-types/ct-version.mjs +3 -4
  177. package/es/tx/builder/field-types/ct-version.mjs.map +1 -1
  178. package/es/tx/builder/field-types/entry.mjs +7 -13
  179. package/es/tx/builder/field-types/entry.mjs.map +1 -1
  180. package/es/tx/builder/field-types/fee.d.ts +19 -11
  181. package/es/tx/builder/field-types/fee.mjs +56 -38
  182. package/es/tx/builder/field-types/fee.mjs.map +1 -1
  183. package/es/tx/builder/field-types/gas-limit.mjs +13 -15
  184. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
  185. package/es/tx/builder/field-types/gas-price.d.ts +10 -2
  186. package/es/tx/builder/field-types/gas-price.mjs +52 -3
  187. package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
  188. package/es/tx/builder/field-types/index.d.ts +31 -29
  189. package/es/tx/builder/field-types/index.mjs +31 -29
  190. package/es/tx/builder/field-types/index.mjs.map +1 -1
  191. package/es/tx/builder/field-types/map.mjs +20 -31
  192. package/es/tx/builder/field-types/map.mjs.map +1 -1
  193. package/es/tx/builder/field-types/mptree.mjs +14 -29
  194. package/es/tx/builder/field-types/mptree.mjs.map +1 -1
  195. package/es/tx/builder/field-types/name-fee.d.ts +1 -1
  196. package/es/tx/builder/field-types/name-fee.mjs +1 -1
  197. package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
  198. package/es/tx/builder/field-types/nonce.d.ts +1 -0
  199. package/es/tx/builder/field-types/nonce.mjs +2 -0
  200. package/es/tx/builder/field-types/nonce.mjs.map +1 -1
  201. package/es/tx/builder/field-types/pointers.mjs +4 -7
  202. package/es/tx/builder/field-types/pointers.mjs.map +1 -1
  203. package/es/tx/builder/field-types/pointers2.d.ts +23 -0
  204. package/es/tx/builder/field-types/pointers2.mjs +65 -0
  205. package/es/tx/builder/field-types/pointers2.mjs.map +1 -0
  206. package/es/tx/builder/field-types/query-fee.d.ts +19 -0
  207. package/es/tx/builder/field-types/query-fee.mjs +20 -0
  208. package/es/tx/builder/field-types/query-fee.mjs.map +1 -0
  209. package/es/tx/builder/field-types/ttl.d.ts +9 -1
  210. package/es/tx/builder/field-types/ttl.mjs +19 -8
  211. package/es/tx/builder/field-types/ttl.mjs.map +1 -1
  212. package/es/tx/builder/field-types/with-default.d.ts +7 -0
  213. package/es/tx/builder/field-types/with-default.mjs +9 -0
  214. package/es/tx/builder/field-types/with-default.mjs.map +1 -0
  215. package/es/tx/builder/field-types/with-formatting.d.ts +7 -0
  216. package/es/tx/builder/field-types/with-formatting.mjs +9 -0
  217. package/es/tx/builder/field-types/with-formatting.mjs.map +1 -0
  218. package/es/tx/builder/field-types/wrapped.mjs +6 -8
  219. package/es/tx/builder/field-types/wrapped.mjs.map +1 -1
  220. package/es/tx/builder/helpers.d.ts +2 -2
  221. package/es/tx/builder/helpers.mjs +12 -21
  222. package/es/tx/builder/helpers.mjs.map +1 -1
  223. package/es/tx/builder/index.d.ts +17 -10
  224. package/es/tx/builder/index.mjs +39 -65
  225. package/es/tx/builder/index.mjs.map +1 -1
  226. package/es/tx/builder/schema.d.ts +478 -257
  227. package/es/tx/builder/schema.generated.d.ts +39 -3
  228. package/es/tx/builder/schema.generated.mjs.map +1 -1
  229. package/es/tx/builder/schema.mjs +48 -36
  230. package/es/tx/builder/schema.mjs.map +1 -1
  231. package/es/tx/execution-cost.d.ts +6 -5
  232. package/es/tx/execution-cost.mjs +16 -17
  233. package/es/tx/execution-cost.mjs.map +1 -1
  234. package/es/tx/transaction-signer.mjs +1 -4
  235. package/es/tx/transaction-signer.mjs.map +1 -1
  236. package/es/tx/validator.mjs +61 -42
  237. package/es/tx/validator.mjs.map +1 -1
  238. package/es/utils/amount-formatter.mjs +15 -22
  239. package/es/utils/amount-formatter.mjs.map +1 -1
  240. package/es/utils/autorest.d.ts +2 -3
  241. package/es/utils/autorest.mjs +40 -24
  242. package/es/utils/autorest.mjs.map +1 -1
  243. package/es/utils/bytes.mjs +1 -2
  244. package/es/utils/bytes.mjs.map +1 -1
  245. package/es/utils/crypto.d.ts +8 -4
  246. package/es/utils/crypto.mjs +17 -13
  247. package/es/utils/crypto.mjs.map +1 -1
  248. package/es/utils/errors.d.ts +6 -0
  249. package/es/utils/errors.mjs +12 -6
  250. package/es/utils/errors.mjs.map +1 -1
  251. package/es/utils/hd-wallet.d.ts +2 -0
  252. package/es/utils/hd-wallet.mjs +6 -5
  253. package/es/utils/hd-wallet.mjs.map +1 -1
  254. package/es/utils/json-big.mjs +2 -10
  255. package/es/utils/json-big.mjs.map +1 -1
  256. package/es/utils/jwt.d.ts +53 -0
  257. package/es/utils/jwt.mjs +120 -0
  258. package/es/utils/jwt.mjs.map +1 -0
  259. package/es/utils/keystore.d.ts +6 -2
  260. package/es/utils/keystore.mjs +8 -16
  261. package/es/utils/keystore.mjs.map +1 -1
  262. package/es/utils/typed-data.mjs +1 -0
  263. package/es/utils/typed-data.mjs.map +1 -1
  264. package/es/utils/wrap-proxy.d.ts +2 -0
  265. package/es/utils/wrap-proxy.mjs +15 -0
  266. package/es/utils/wrap-proxy.mjs.map +1 -0
  267. package/package.json +57 -51
  268. package/src/AeSdk.ts +3 -0
  269. package/src/AeSdkAepp.ts +0 -1
  270. package/src/AeSdkBase.ts +97 -10
  271. package/src/AeSdkMethods.ts +37 -33
  272. package/src/AeSdkWallet.ts +22 -3
  273. package/src/Middleware.ts +16 -8
  274. package/src/MiddlewareSubscriber.ts +1 -1
  275. package/src/Node.ts +37 -18
  276. package/src/account/Base.ts +62 -3
  277. package/src/account/Generalized.ts +10 -0
  278. package/src/account/Ledger.ts +10 -0
  279. package/src/account/Memory.ts +83 -9
  280. package/src/account/Rpc.ts +69 -6
  281. package/src/aens.ts +35 -56
  282. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +3 -0
  283. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +2 -2
  284. package/src/aepp-wallet-communication/rpc/RpcClient.ts +4 -2
  285. package/src/aepp-wallet-communication/rpc/types.ts +13 -0
  286. package/src/aepp-wallet-communication/schema.ts +2 -0
  287. package/src/apis/compiler/compiler.ts +93 -93
  288. package/src/apis/compiler/models/index.ts +1 -0
  289. package/src/apis/compiler/models/mappers.ts +178 -165
  290. package/src/apis/compiler/models/parameters.ts +18 -18
  291. package/src/apis/middleware/middleware.ts +462 -341
  292. package/src/apis/middleware/models/index.ts +258 -56
  293. package/src/apis/middleware/models/mappers.ts +2357 -1919
  294. package/src/apis/middleware/models/parameters.ts +172 -142
  295. package/src/apis/node/models/index.ts +79 -2
  296. package/src/apis/node/models/mappers.ts +1529 -1302
  297. package/src/apis/node/models/parameters.ts +51 -51
  298. package/src/apis/node/node.ts +420 -275
  299. package/src/chain.ts +42 -128
  300. package/src/channel/Base.ts +14 -47
  301. package/src/channel/Contract.ts +18 -26
  302. package/src/channel/Spend.ts +0 -8
  303. package/src/channel/internal.ts +115 -13
  304. package/src/contract/Contract.ts +26 -8
  305. package/src/contract/compiler/Base.ts +15 -8
  306. package/src/contract/compiler/Cli.ts +37 -21
  307. package/src/contract/compiler/Cli8.ts +17 -0
  308. package/src/contract/compiler/Http.ts +24 -14
  309. package/src/contract/compiler/HttpNode.ts +2 -2
  310. package/src/contract/delegation-signature.ts +11 -5
  311. package/src/contract/ga.ts +4 -3
  312. package/src/deprecated.ts +36 -0
  313. package/src/index-browser.ts +14 -7
  314. package/src/index.ts +1 -0
  315. package/src/oracle.ts +11 -54
  316. package/src/send-transaction.ts +136 -0
  317. package/src/spend.ts +25 -11
  318. package/src/tx/builder/common.ts +74 -0
  319. package/src/tx/builder/constants.ts +6 -9
  320. package/src/tx/builder/delegation/index.ts +28 -0
  321. package/src/tx/builder/delegation/schema.generated.ts +143 -0
  322. package/src/tx/builder/delegation/schema.ts +61 -0
  323. package/src/tx/builder/field-types/coin-amount.ts +3 -2
  324. package/src/tx/builder/field-types/entry.ts +1 -4
  325. package/src/tx/builder/field-types/fee.ts +71 -43
  326. package/src/tx/builder/field-types/gas-limit.ts +4 -4
  327. package/src/tx/builder/field-types/gas-price.ts +70 -14
  328. package/src/tx/builder/field-types/index.ts +31 -59
  329. package/src/tx/builder/field-types/name-fee.ts +1 -1
  330. package/src/tx/builder/field-types/nonce.ts +7 -1
  331. package/src/tx/builder/field-types/pointers2.ts +62 -0
  332. package/src/tx/builder/field-types/query-fee.ts +25 -0
  333. package/src/tx/builder/field-types/ttl.ts +13 -3
  334. package/src/tx/builder/field-types/with-default.ts +18 -0
  335. package/src/tx/builder/field-types/with-formatting.ts +18 -0
  336. package/src/tx/builder/helpers.ts +2 -2
  337. package/src/tx/builder/index.ts +42 -59
  338. package/src/tx/builder/schema.generated.ts +39 -3
  339. package/src/tx/builder/schema.ts +55 -29
  340. package/src/tx/execution-cost.ts +6 -5
  341. package/src/tx/validator.ts +31 -5
  342. package/src/utils/autorest.ts +36 -27
  343. package/src/utils/crypto.ts +23 -13
  344. package/src/utils/errors.ts +10 -0
  345. package/src/utils/hd-wallet.ts +2 -0
  346. package/src/utils/jwt.ts +126 -0
  347. package/src/utils/keystore.ts +6 -2
  348. package/src/utils/wrap-proxy.ts +24 -0
  349. package/types-legacy/ts4.2/AeSdk.d.ts +3 -0
  350. package/types-legacy/ts4.2/AeSdkAepp.d.ts +0 -1
  351. package/types-legacy/ts4.2/AeSdkBase.d.ts +61 -6
  352. package/types-legacy/ts4.2/AeSdkMethods.d.ts +19 -7
  353. package/types-legacy/ts4.2/Node.d.ts +14 -1
  354. package/types-legacy/ts4.2/account/Base.d.ts +39 -3
  355. package/types-legacy/ts4.2/account/Generalized.d.ts +2 -0
  356. package/types-legacy/ts4.2/account/Ledger.d.ts +2 -0
  357. package/types-legacy/ts4.2/account/Memory.d.ts +15 -4
  358. package/types-legacy/ts4.2/account/Rpc.d.ts +16 -5
  359. package/types-legacy/ts4.2/aens.d.ts +17 -44
  360. package/types-legacy/ts4.2/aepp-wallet-communication/connection/BrowserRuntime.d.ts +3 -0
  361. package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +14 -0
  362. package/types-legacy/ts4.2/aepp-wallet-communication/schema.d.ts +2 -0
  363. package/types-legacy/ts4.2/apis/compiler/models/index.d.ts +1 -0
  364. package/types-legacy/ts4.2/apis/middleware/middleware.d.ts +23 -5
  365. package/types-legacy/ts4.2/apis/middleware/models/index.d.ts +164 -15
  366. package/types-legacy/ts4.2/apis/middleware/models/mappers.d.ts +8 -1
  367. package/types-legacy/ts4.2/apis/middleware/models/parameters.d.ts +6 -3
  368. package/types-legacy/ts4.2/apis/node/models/index.d.ts +66 -2
  369. package/types-legacy/ts4.2/apis/node/models/mappers.d.ts +5 -1
  370. package/types-legacy/ts4.2/apis/node/models/parameters.d.ts +2 -2
  371. package/types-legacy/ts4.2/apis/node/node.d.ts +24 -3
  372. package/types-legacy/ts4.2/chain.d.ts +14 -44
  373. package/types-legacy/ts4.2/channel/Base.d.ts +3 -47
  374. package/types-legacy/ts4.2/channel/Contract.d.ts +16 -25
  375. package/types-legacy/ts4.2/channel/Spend.d.ts +0 -8
  376. package/types-legacy/ts4.2/channel/internal.d.ts +104 -5
  377. package/types-legacy/ts4.2/contract/Contract.d.ts +9 -1
  378. package/types-legacy/ts4.2/contract/compiler/Base.d.ts +14 -8
  379. package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +5 -9
  380. package/types-legacy/ts4.2/contract/compiler/Cli8.d.ts +13 -0
  381. package/types-legacy/ts4.2/contract/compiler/Http.d.ts +3 -9
  382. package/types-legacy/ts4.2/contract/compiler/HttpNode.d.ts +2 -5
  383. package/types-legacy/ts4.2/contract/delegation-signature.d.ts +2 -1
  384. package/types-legacy/ts4.2/contract/ga.d.ts +1 -2
  385. package/types-legacy/ts4.2/deprecated.d.ts +38 -0
  386. package/types-legacy/ts4.2/index-browser.d.ts +10 -5
  387. package/types-legacy/ts4.2/index.d.ts +1 -0
  388. package/types-legacy/ts4.2/oracle.d.ts +6 -37
  389. package/types-legacy/ts4.2/send-transaction.d.ts +53 -0
  390. package/types-legacy/ts4.2/spend.d.ts +4 -3
  391. package/types-legacy/ts4.2/tx/builder/common.d.ts +32 -0
  392. package/types-legacy/ts4.2/tx/builder/constants.d.ts +4 -4
  393. package/types-legacy/ts4.2/tx/builder/delegation/index.d.ts +20 -0
  394. package/types-legacy/ts4.2/tx/builder/delegation/schema.d.ts +136 -0
  395. package/types-legacy/ts4.2/tx/builder/delegation/schema.generated.d.ts +141 -0
  396. package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +2 -2
  397. package/types-legacy/ts4.2/tx/builder/field-types/fee.d.ts +19 -11
  398. package/types-legacy/ts4.2/tx/builder/field-types/gas-price.d.ts +10 -2
  399. package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +31 -29
  400. package/types-legacy/ts4.2/tx/builder/field-types/name-fee.d.ts +1 -1
  401. package/types-legacy/ts4.2/tx/builder/field-types/nonce.d.ts +1 -0
  402. package/types-legacy/ts4.2/tx/builder/field-types/pointers2.d.ts +26 -0
  403. package/types-legacy/ts4.2/tx/builder/field-types/query-fee.d.ts +19 -0
  404. package/types-legacy/ts4.2/tx/builder/field-types/ttl.d.ts +9 -1
  405. package/types-legacy/ts4.2/tx/builder/field-types/with-default.d.ts +7 -0
  406. package/types-legacy/ts4.2/tx/builder/field-types/with-formatting.d.ts +7 -0
  407. package/types-legacy/ts4.2/tx/builder/helpers.d.ts +2 -2
  408. package/types-legacy/ts4.2/tx/builder/index.d.ts +17 -10
  409. package/types-legacy/ts4.2/tx/builder/schema.d.ts +482 -257
  410. package/types-legacy/ts4.2/tx/builder/schema.generated.d.ts +39 -3
  411. package/types-legacy/ts4.2/tx/execution-cost.d.ts +6 -5
  412. package/types-legacy/ts4.2/utils/autorest.d.ts +2 -3
  413. package/types-legacy/ts4.2/utils/crypto.d.ts +8 -4
  414. package/types-legacy/ts4.2/utils/errors.d.ts +6 -0
  415. package/types-legacy/ts4.2/utils/hd-wallet.d.ts +2 -0
  416. package/types-legacy/ts4.2/utils/jwt.d.ts +53 -0
  417. package/types-legacy/ts4.2/utils/keystore.d.ts +6 -2
  418. package/types-legacy/ts4.2/utils/wrap-proxy.d.ts +2 -0
  419. package/types-legacy/ts4.5/AeSdk.d.ts +3 -0
  420. package/types-legacy/ts4.5/AeSdkAepp.d.ts +0 -1
  421. package/types-legacy/ts4.5/AeSdkBase.d.ts +61 -6
  422. package/types-legacy/ts4.5/AeSdkMethods.d.ts +19 -7
  423. package/types-legacy/ts4.5/Node.d.ts +14 -1
  424. package/types-legacy/ts4.5/account/Base.d.ts +39 -3
  425. package/types-legacy/ts4.5/account/Generalized.d.ts +2 -0
  426. package/types-legacy/ts4.5/account/Ledger.d.ts +2 -0
  427. package/types-legacy/ts4.5/account/Memory.d.ts +15 -4
  428. package/types-legacy/ts4.5/account/Rpc.d.ts +16 -5
  429. package/types-legacy/ts4.5/aens.d.ts +17 -44
  430. package/types-legacy/ts4.5/aepp-wallet-communication/connection/BrowserRuntime.d.ts +3 -0
  431. package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +14 -0
  432. package/types-legacy/ts4.5/aepp-wallet-communication/schema.d.ts +2 -0
  433. package/types-legacy/ts4.5/apis/compiler/models/index.d.ts +1 -0
  434. package/types-legacy/ts4.5/apis/middleware/middleware.d.ts +23 -5
  435. package/types-legacy/ts4.5/apis/middleware/models/index.d.ts +164 -15
  436. package/types-legacy/ts4.5/apis/middleware/models/mappers.d.ts +8 -1
  437. package/types-legacy/ts4.5/apis/middleware/models/parameters.d.ts +6 -3
  438. package/types-legacy/ts4.5/apis/node/models/index.d.ts +66 -2
  439. package/types-legacy/ts4.5/apis/node/models/mappers.d.ts +5 -1
  440. package/types-legacy/ts4.5/apis/node/models/parameters.d.ts +2 -2
  441. package/types-legacy/ts4.5/apis/node/node.d.ts +24 -3
  442. package/types-legacy/ts4.5/chain.d.ts +14 -44
  443. package/types-legacy/ts4.5/channel/Base.d.ts +3 -47
  444. package/types-legacy/ts4.5/channel/Contract.d.ts +16 -25
  445. package/types-legacy/ts4.5/channel/Spend.d.ts +0 -8
  446. package/types-legacy/ts4.5/channel/internal.d.ts +104 -5
  447. package/types-legacy/ts4.5/contract/Contract.d.ts +9 -1
  448. package/types-legacy/ts4.5/contract/compiler/Base.d.ts +14 -8
  449. package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +5 -9
  450. package/types-legacy/ts4.5/contract/compiler/Cli8.d.ts +13 -0
  451. package/types-legacy/ts4.5/contract/compiler/Http.d.ts +3 -9
  452. package/types-legacy/ts4.5/contract/compiler/HttpNode.d.ts +2 -5
  453. package/types-legacy/ts4.5/contract/delegation-signature.d.ts +2 -1
  454. package/types-legacy/ts4.5/contract/ga.d.ts +1 -2
  455. package/types-legacy/ts4.5/deprecated.d.ts +38 -0
  456. package/types-legacy/ts4.5/index-browser.d.ts +10 -5
  457. package/types-legacy/ts4.5/index.d.ts +1 -0
  458. package/types-legacy/ts4.5/oracle.d.ts +6 -37
  459. package/types-legacy/ts4.5/send-transaction.d.ts +53 -0
  460. package/types-legacy/ts4.5/spend.d.ts +4 -3
  461. package/types-legacy/ts4.5/tx/builder/common.d.ts +32 -0
  462. package/types-legacy/ts4.5/tx/builder/constants.d.ts +4 -4
  463. package/types-legacy/ts4.5/tx/builder/delegation/index.d.ts +20 -0
  464. package/types-legacy/ts4.5/tx/builder/delegation/schema.d.ts +136 -0
  465. package/types-legacy/ts4.5/tx/builder/delegation/schema.generated.d.ts +141 -0
  466. package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +2 -2
  467. package/types-legacy/ts4.5/tx/builder/field-types/fee.d.ts +19 -11
  468. package/types-legacy/ts4.5/tx/builder/field-types/gas-price.d.ts +10 -2
  469. package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +31 -29
  470. package/types-legacy/ts4.5/tx/builder/field-types/name-fee.d.ts +1 -1
  471. package/types-legacy/ts4.5/tx/builder/field-types/nonce.d.ts +1 -0
  472. package/types-legacy/ts4.5/tx/builder/field-types/pointers2.d.ts +26 -0
  473. package/types-legacy/ts4.5/tx/builder/field-types/query-fee.d.ts +19 -0
  474. package/types-legacy/ts4.5/tx/builder/field-types/ttl.d.ts +9 -1
  475. package/types-legacy/ts4.5/tx/builder/field-types/with-default.d.ts +7 -0
  476. package/types-legacy/ts4.5/tx/builder/field-types/with-formatting.d.ts +7 -0
  477. package/types-legacy/ts4.5/tx/builder/helpers.d.ts +2 -2
  478. package/types-legacy/ts4.5/tx/builder/index.d.ts +17 -10
  479. package/types-legacy/ts4.5/tx/builder/schema.d.ts +482 -257
  480. package/types-legacy/ts4.5/tx/builder/schema.generated.d.ts +39 -3
  481. package/types-legacy/ts4.5/tx/execution-cost.d.ts +6 -5
  482. package/types-legacy/ts4.5/utils/autorest.d.ts +2 -3
  483. package/types-legacy/ts4.5/utils/crypto.d.ts +8 -4
  484. package/types-legacy/ts4.5/utils/errors.d.ts +6 -0
  485. package/types-legacy/ts4.5/utils/hd-wallet.d.ts +2 -0
  486. package/types-legacy/ts4.5/utils/jwt.d.ts +53 -0
  487. package/types-legacy/ts4.5/utils/keystore.d.ts +6 -2
  488. package/types-legacy/ts4.5/utils/wrap-proxy.d.ts +2 -0
  489. package/es/tx/builder/field-types/deposit.d.ts +0 -15
  490. package/es/tx/builder/field-types/deposit.mjs +0 -18
  491. package/es/tx/builder/field-types/deposit.mjs.map +0 -1
  492. package/src/tx/builder/field-types/deposit.ts +0 -23
  493. package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +0 -15
  494. package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +0 -15
@@ -1 +1 @@
1
- {"version":3,"file":"keystore.mjs","names":["nacl","v4","uuid","_aeternityArgon","hash","argon2id","getAddressFromPriv","InvalidPasswordError","DERIVED_KEY_FUNCTIONS","pass","salt","params","memlimit_kib","memoryCost","opslimit","timeCost","hashLength","type","CRYPTO_FUNCTIONS","encrypt","secretbox","decrypt","res","open","arguments","CRYPTO_DEFAULTS","secret_type","symmetric_alg","kdf","kdf_params","parallelism","plaintext","key","nonce","algo","length","undefined","ciphertext","deriveKey","password","kdfParams","recover","_ref","crypto","_Buffer","from","cipher_params","toString","dump","name","privateKey","randomBytes","options","opt","derivedKey","payload","version","public_key","id"],"sources":["../../src/utils/keystore.ts"],"sourcesContent":["import nacl from 'tweetnacl';\nimport { v4 as uuid } from '@aeternity/uuid';\nimport { hash, argon2id } from '@aeternity/argon2';\nimport { getAddressFromPriv } from './crypto';\nimport { InvalidPasswordError } from './errors';\n\nconst DERIVED_KEY_FUNCTIONS = {\n async argon2id(\n pass: string | Uint8Array,\n salt: string | Uint8Array,\n params: Partial<Keystore['crypto']['kdf_params']>,\n ): Promise<Uint8Array> {\n const { memlimit_kib: memoryCost, opslimit: timeCost } = params;\n\n return hash(pass, {\n hashLength: 32,\n salt,\n timeCost,\n memoryCost,\n type: argon2id,\n });\n },\n};\n\nconst CRYPTO_FUNCTIONS = {\n 'xsalsa20-poly1305': {\n encrypt: nacl.secretbox,\n decrypt(...args: Parameters<typeof nacl.secretbox.open>): Uint8Array {\n const res = nacl.secretbox.open(...args);\n if (res == null) throw new InvalidPasswordError();\n return res;\n },\n },\n};\n\nexport interface Keystore {\n name: string;\n version: 1;\n public_key: string;\n id: string;\n crypto: {\n secret_type: 'ed25519';\n symmetric_alg: keyof typeof CRYPTO_FUNCTIONS;\n ciphertext: string;\n cipher_params: {\n nonce: string;\n };\n kdf: keyof typeof DERIVED_KEY_FUNCTIONS;\n kdf_params: {\n memlimit_kib: number;\n opslimit: number;\n parallelism: number;\n salt: string;\n };\n };\n}\n\nconst CRYPTO_DEFAULTS = {\n secret_type: 'ed25519',\n symmetric_alg: 'xsalsa20-poly1305',\n kdf: 'argon2id',\n kdf_params: {\n memlimit_kib: 65536,\n opslimit: 3,\n parallelism: 1,\n },\n} as const;\n\n/**\n * Symmetric private key encryption using secret (derived) key.\n * @category keystore\n * @param plaintext - Data to be encrypted.\n * @param key - Secret key.\n * @param nonce - Randomly generated nonce.\n * @param algo - Encryption algorithm.\n * @returns Encrypted data.\n */\nfunction encrypt(\n plaintext: Uint8Array,\n key: Uint8Array,\n nonce: Uint8Array,\n algo: keyof typeof CRYPTO_FUNCTIONS = CRYPTO_DEFAULTS.symmetric_alg,\n): Uint8Array {\n return CRYPTO_FUNCTIONS[algo].encrypt(plaintext, nonce, key);\n}\n\n/**\n * Symmetric private key decryption using secret (derived) key.\n * @category keystore\n * @param ciphertext - Data to be decrypted.\n * @param key - Secret key.\n * @param nonce - Nonce from key-object.\n * @param algo - Encryption algorithm.\n * @returns Decrypted data.\n */\nfunction decrypt(\n ciphertext: Uint8Array,\n key: Uint8Array,\n nonce: Uint8Array,\n algo: keyof typeof CRYPTO_FUNCTIONS = CRYPTO_DEFAULTS.symmetric_alg,\n): Uint8Array {\n return CRYPTO_FUNCTIONS[algo].decrypt(ciphertext, nonce, key);\n}\n\n/**\n * Derive secret key from password with key derivation function.\n * @category keystore\n * @param password - User-supplied password.\n * @param nonce - Randomly generated nonce.\n * @param kdf - Key derivation function.\n * @param kdfParams - KDF parameters.\n * @returns Secret key derived from password.\n */\nasync function deriveKey(\n password: string | Uint8Array,\n nonce: string | Uint8Array,\n kdf: Keystore['crypto']['kdf'],\n kdfParams: Omit<Keystore['crypto']['kdf_params'], 'salt'>,\n): Promise<Uint8Array> {\n return DERIVED_KEY_FUNCTIONS[kdf](password, nonce, kdfParams);\n}\n\n/**\n * Recover plaintext private key from secret-storage key object.\n * @category keystore\n * @param password - Keystore object password.\n * @param keystore - Keystore object.\n * @returns Plaintext private key.\n */\nexport async function recover(\n password: string | Uint8Array,\n { crypto }: Keystore,\n): Promise<string> {\n const salt = Buffer.from(crypto.kdf_params.salt, 'hex');\n return Buffer.from(decrypt(\n Buffer.from(crypto.ciphertext, 'hex'),\n await deriveKey(password, salt, crypto.kdf, crypto.kdf_params),\n Buffer.from(crypto.cipher_params.nonce, 'hex'),\n crypto.symmetric_alg,\n )).toString('hex');\n}\n\n/**\n * Export private key to keystore secret-storage format.\n * @category keystore\n * @param name - Key name.\n * @param password - User-supplied password.\n * @param privateKey - Private key as hex-string or a Buffer.\n * @param nonce - Randomly generated 24byte nonce.\n * @param salt - Randomly generated 16byte salt.\n * @param options - Encryption parameters.\n * @param options.kdf - Key derivation function.\n * @param options.kdf_params - KDF parameters.\n */\nexport async function dump(\n name: string,\n password: string | Uint8Array,\n privateKey: string | Uint8Array,\n nonce: Uint8Array = nacl.randomBytes(24),\n salt: Uint8Array = nacl.randomBytes(16),\n options?: Partial<Keystore['crypto']>,\n): Promise<Keystore> {\n const opt = { ...CRYPTO_DEFAULTS, ...options };\n const derivedKey = await deriveKey(password, salt, opt.kdf, opt.kdf_params);\n const payload = typeof privateKey === 'string' ? Buffer.from(privateKey, 'hex') : privateKey;\n return {\n name,\n version: 1,\n public_key: getAddressFromPriv(payload),\n id: uuid(),\n crypto: {\n secret_type: opt.secret_type,\n symmetric_alg: opt.symmetric_alg,\n ciphertext: Buffer.from(\n encrypt(payload, derivedKey, nonce, opt.symmetric_alg),\n ).toString('hex'),\n cipher_params: { nonce: Buffer.from(nonce).toString('hex') },\n kdf: opt.kdf,\n kdf_params: {\n ...opt.kdf_params,\n salt: Buffer.from(salt).toString('hex'),\n },\n },\n };\n}\n"],"mappings":";;;;AAAA,OAAOA,IAAI,MAAM,WAAW;AAC5B,SAASC,EAAE,IAAIC,IAAI,QAAQ,iBAAiB;AAC5C,OAAAC,eAAA,MAA+B,mBAAmB;AAAC;EAAAC,IAAA;EAAAC;AAAA,IAAAF,eAAA;AAAA,SAC1CG,kBAAkB;AAAA,SAClBC,oBAAoB;AAE7B,MAAMC,qBAAqB,GAAG;EAC5B,MAAMH,QAAQA,CACZI,IAAyB,EACzBC,IAAyB,EACzBC,MAAiD,EAC5B;IACrB,MAAM;MAAEC,YAAY,EAAEC,UAAU;MAAEC,QAAQ,EAAEC;IAAS,CAAC,GAAGJ,MAAM;IAE/D,OAAOP,IAAI,CAACK,IAAI,EAAE;MAChBO,UAAU,EAAE,EAAE;MACdN,IAAI;MACJK,QAAQ;MACRF,UAAU;MACVI,IAAI,EAAEZ;IACR,CAAC,CAAC;EACJ;AACF,CAAC;AAED,MAAMa,gBAAgB,GAAG;EACvB,mBAAmB,EAAE;IACnBC,OAAO,EAAEnB,IAAI,CAACoB,SAAS;IACvBC,OAAOA,CAAA,EAA8D;MACnE,MAAMC,GAAG,GAAGtB,IAAI,CAACoB,SAAS,CAACG,IAAI,CAAC,GAAAC,SAAO,CAAC;MACxC,IAAIF,GAAG,IAAI,IAAI,EAAE,MAAM,IAAIf,oBAAoB,CAAC,CAAC;MACjD,OAAOe,GAAG;IACZ;EACF;AACF,CAAC;AAwBD,MAAMG,eAAe,GAAG;EACtBC,WAAW,EAAE,SAAS;EACtBC,aAAa,EAAE,mBAAmB;EAClCC,GAAG,EAAE,UAAU;EACfC,UAAU,EAAE;IACVjB,YAAY,EAAE,KAAK;IACnB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CAAC;IACvCG,EAAE,EAAExD,IAAI,CAAC,CAAC;IACVyC,MAAM,EAAE;MACNjB,WAAW,EAAE2B,GAAG,CAAC3B,WAAW;MAC5BC,aAAa,EAAE0B,GAAG,CAAC1B,aAAa;MAChCU,UAAU,EAAEO,OAAA,CAAOC,IAAI,CACrB1B,OAAO,CAACoC,OAAO,EAAED,UAAU,EAAErB,KAAK,EAAEoB,GAAG,CAAC1B,aAAa,CACvD,CAAC,CAACoB,QAAQ,CAAC,KAAK,CAAC;MACjBD,aAAa,EAAE;QAAEb,KAAK,EAAEW,OAAA,CAAOC,IAAI,CAACZ,KAAK,CAAC,CAACc,QAAQ,CAAC,KAAK;MAAE,CAAC;MAC5DnB,GAAG,EAAEyB,GAAG,CAACzB,GAAG;MACZC,UAAU,EAAE;QACV,GAAGwB,GAAG,CAACxB,UAAU;QACjBnB,IAAI,EAAEkC,OAAA,CAAOC,IAAI,CAACnC,IAAI,CAAC,CAACqC,QAAQ,CAAC,KAAK;MACxC;IACF;EACF,CAAC;AACH"}
1
+ {"version":3,"file":"keystore.mjs","names":["nacl","v4","uuid","_aeternityArgon","hash","argon2id","getAddressFromPriv","InvalidPasswordError","DERIVED_KEY_FUNCTIONS","pass","salt","params","memlimit_kib","memoryCost","opslimit","timeCost","hashLength","type","CRYPTO_FUNCTIONS","encrypt","secretbox","decrypt","args","res","open","CRYPTO_DEFAULTS","secret_type","symmetric_alg","kdf","kdf_params","parallelism","plaintext","key","nonce","algo","ciphertext","deriveKey","password","kdfParams","recover","crypto","_Buffer","from","cipher_params","toString","dump","name","privateKey","randomBytes","options","opt","derivedKey","payload","version","public_key","id"],"sources":["../../src/utils/keystore.ts"],"sourcesContent":["import nacl from 'tweetnacl';\nimport { v4 as uuid } from '@aeternity/uuid';\nimport { hash, argon2id } from '@aeternity/argon2';\nimport { getAddressFromPriv } from './crypto';\nimport { InvalidPasswordError } from './errors';\n\nconst DERIVED_KEY_FUNCTIONS = {\n async argon2id(\n pass: string | Uint8Array,\n salt: string | Uint8Array,\n params: Partial<Keystore['crypto']['kdf_params']>,\n ): Promise<Uint8Array> {\n const { memlimit_kib: memoryCost, opslimit: timeCost } = params;\n\n return hash(pass, {\n hashLength: 32,\n salt,\n timeCost,\n memoryCost,\n type: argon2id,\n });\n },\n};\n\nconst CRYPTO_FUNCTIONS = {\n 'xsalsa20-poly1305': {\n encrypt: nacl.secretbox,\n decrypt(...args: Parameters<typeof nacl.secretbox.open>): Uint8Array {\n const res = nacl.secretbox.open(...args);\n if (res == null) throw new InvalidPasswordError();\n return res;\n },\n },\n};\n\nexport interface Keystore {\n name: string;\n version: 1;\n public_key: string;\n id: string;\n crypto: {\n secret_type: 'ed25519';\n symmetric_alg: keyof typeof CRYPTO_FUNCTIONS;\n ciphertext: string;\n cipher_params: {\n nonce: string;\n };\n /**\n * Key derivation function name.\n */\n kdf: keyof typeof DERIVED_KEY_FUNCTIONS;\n /**\n * Key derivation function parameters.\n */\n kdf_params: {\n memlimit_kib: number;\n opslimit: number;\n parallelism: number;\n salt: string;\n };\n };\n}\n\nconst CRYPTO_DEFAULTS = {\n secret_type: 'ed25519',\n symmetric_alg: 'xsalsa20-poly1305',\n kdf: 'argon2id',\n kdf_params: {\n memlimit_kib: 65536,\n opslimit: 3,\n parallelism: 1,\n },\n} as const;\n\n/**\n * Symmetric private key encryption using secret (derived) key.\n * @category keystore\n * @param plaintext - Data to be encrypted.\n * @param key - Secret key.\n * @param nonce - Randomly generated nonce.\n * @param algo - Encryption algorithm.\n * @returns Encrypted data.\n */\nfunction encrypt(\n plaintext: Uint8Array,\n key: Uint8Array,\n nonce: Uint8Array,\n algo: keyof typeof CRYPTO_FUNCTIONS = CRYPTO_DEFAULTS.symmetric_alg,\n): Uint8Array {\n return CRYPTO_FUNCTIONS[algo].encrypt(plaintext, nonce, key);\n}\n\n/**\n * Symmetric private key decryption using secret (derived) key.\n * @category keystore\n * @param ciphertext - Data to be decrypted.\n * @param key - Secret key.\n * @param nonce - Nonce from key-object.\n * @param algo - Encryption algorithm.\n * @returns Decrypted data.\n */\nfunction decrypt(\n ciphertext: Uint8Array,\n key: Uint8Array,\n nonce: Uint8Array,\n algo: keyof typeof CRYPTO_FUNCTIONS = CRYPTO_DEFAULTS.symmetric_alg,\n): Uint8Array {\n return CRYPTO_FUNCTIONS[algo].decrypt(ciphertext, nonce, key);\n}\n\n/**\n * Derive secret key from password with key derivation function.\n * @category keystore\n * @param password - User-supplied password.\n * @param nonce - Randomly generated nonce.\n * @param kdf - Key derivation function.\n * @param kdfParams - KDF parameters.\n * @returns Secret key derived from password.\n */\nasync function deriveKey(\n password: string | Uint8Array,\n nonce: string | Uint8Array,\n kdf: Keystore['crypto']['kdf'],\n kdfParams: Omit<Keystore['crypto']['kdf_params'], 'salt'>,\n): Promise<Uint8Array> {\n return DERIVED_KEY_FUNCTIONS[kdf](password, nonce, kdfParams);\n}\n\n/**\n * Recover plaintext private key from secret-storage key object.\n * @category keystore\n * @param password - Keystore object password.\n * @param keystore - Keystore object.\n * @returns Plaintext private key.\n */\nexport async function recover(\n password: string | Uint8Array,\n { crypto }: Keystore,\n): Promise<string> {\n const salt = Buffer.from(crypto.kdf_params.salt, 'hex');\n return Buffer.from(decrypt(\n Buffer.from(crypto.ciphertext, 'hex'),\n await deriveKey(password, salt, crypto.kdf, crypto.kdf_params),\n Buffer.from(crypto.cipher_params.nonce, 'hex'),\n crypto.symmetric_alg,\n )).toString('hex');\n}\n\n/**\n * Export private key to keystore secret-storage format.\n * @category keystore\n * @param name - Key name.\n * @param password - User-supplied password.\n * @param privateKey - Private key as hex-string or a Buffer.\n * @param nonce - Randomly generated 24byte nonce.\n * @param salt - Randomly generated 16byte salt.\n * @param options - Encryption parameters.\n */\nexport async function dump(\n name: string,\n password: string | Uint8Array,\n privateKey: string | Uint8Array,\n nonce: Uint8Array = nacl.randomBytes(24),\n salt: Uint8Array = nacl.randomBytes(16),\n options?: Partial<Keystore['crypto']>,\n): Promise<Keystore> {\n const opt = { ...CRYPTO_DEFAULTS, ...options };\n const derivedKey = await deriveKey(password, salt, opt.kdf, opt.kdf_params);\n const payload = typeof privateKey === 'string' ? Buffer.from(privateKey, 'hex') : privateKey;\n return {\n name,\n version: 1,\n public_key: getAddressFromPriv(payload),\n id: uuid(),\n crypto: {\n secret_type: opt.secret_type,\n symmetric_alg: opt.symmetric_alg,\n ciphertext: Buffer.from(\n encrypt(payload, derivedKey, nonce, opt.symmetric_alg),\n ).toString('hex'),\n cipher_params: { nonce: Buffer.from(nonce).toString('hex') },\n kdf: opt.kdf,\n kdf_params: {\n ...opt.kdf_params,\n salt: Buffer.from(salt).toString('hex'),\n },\n },\n };\n}\n"],"mappings":";;;;AAAA,OAAOA,IAAI,MAAM,WAAW;AAC5B,SAASC,EAAE,IAAIC,IAAI,QAAQ,iBAAiB;AAC5C,OAAAC,eAAA,MAA+B,mBAAmB;AAAC;EAAAC,IAAA;EAAAC;AAAA,IAAAF,eAAA;AAAA,SAC1CG,kBAAkB;AAAA,SAClBC,oBAAoB;AAE7B,MAAMC,qBAAqB,GAAG;EAC5B,MAAMH,QAAQA,CACZI,IAAyB,EACzBC,IAAyB,EACzBC,MAAiD,EAC5B;IACrB,MAAM;MAAEC,YAAY,EAAEC,UAAU;MAAEC,QAAQ,EAAEC;IAAS,CAAC,GAAGJ,MAAM;IAE/D,OAAOP,IAAI,CAACK,IAAI,EAAE;MAChBO,UAAU,EAAE,EAAE;MACdN,IAAI;MACJK,QAAQ;MACRF,UAAU;MACVI,IAAI,EAAEZ;IACR,CAAC,CAAC;EACJ;AACF,CAAC;AAED,MAAMa,gBAAgB,GAAG;EACvB,mBAAmB,EAAE;IACnBC,OAAO,EAAEnB,IAAI,CAACoB,SAAS;IACvBC,OAAOA,CAAC,GAAGC,IAA4C,EAAc;MACnE,MAAMC,GAAG,GAAGvB,IAAI,CAACoB,SAAS,CAACI,IAAI,CAAC,GAAGF,IAAI,CAAC;MACxC,IAAIC,GAAG,IAAI,IAAI,EAAE,MAAM,IAAIhB,oBAAoB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OAAO,CAACiC,OAAO,EAAED,UAAU,EAAElB,KAAK,EAAEiB,GAAG,CAACvB,aAAa,CACvD,CAAC,CAACiB,QAAQ,CAAC,KAAK,CAAC;MACjBD,aAAa,EAAE;QAAEV,KAAK,EAAEQ,OAAA,CAAOC,IAAI,CAACT,KAAK,CAAC,CAACW,QAAQ,CAAC,KAAK;MAAE,CAAC;MAC5DhB,GAAG,EAAEsB,GAAG,CAACtB,GAAG;MACZC,UAAU,EAAE;QACV,GAAGqB,GAAG,CAACrB,UAAU;QACjBnB,IAAI,EAAE+B,OAAA,CAAOC,IAAI,CAAChC,IAAI,CAAC,CAACkC,QAAQ,CAAC,KAAK;MACxC;IACF;EACF,CAAC;AACH"}
@@ -17,6 +17,7 @@ export function hashJson(data) {
17
17
 
18
18
  // TODO: move this type to calldata library https://github.com/aeternity/aepp-calldata-js/issues/215
19
19
  // based on https://github.com/aeternity/aepp-calldata-js/blob/82b5a98f9b308482627da8d7484d213e9cf87151/src/AciTypeResolver.js#L129
20
+
20
21
  /**
21
22
  * Hashes domain object, can be used to inline domain hash to contract source code
22
23
  */
@@ -1 +1 @@
1
- {"version":3,"file":"typed-data.mjs","names":["_aeternityAeppCalldata","TypeResolver","ContractByteArrayEncoder","canonicalize","decode","hash","messagePrefixLength","concatBuffers","hashJson","data","_canonicalize","hashDomain","domain","domainAci","record","name","type","option","domainType","resolveType","fateValue","encodeWithType","hashTypedData","aci","Uint8Array"],"sources":["../../src/utils/typed-data.ts"],"sourcesContent":["import { TypeResolver, ContractByteArrayEncoder } from '@aeternity/aepp-calldata';\nimport canonicalize from 'canonicalize';\nimport { Encoded, decode } from './encoder';\nimport { hash, messagePrefixLength } from './crypto';\nimport { concatBuffers } from './other';\n\n/**\n * Hashes arbitrary object, can be used to inline the aci hash to contract source code\n */\nexport function hashJson(data: unknown): Buffer {\n return hash(canonicalize(data) ?? '');\n}\n\n// TODO: move this type to calldata library https://github.com/aeternity/aepp-calldata-js/issues/215\n// based on https://github.com/aeternity/aepp-calldata-js/blob/82b5a98f9b308482627da8d7484d213e9cf87151/src/AciTypeResolver.js#L129\nexport type AciValue = 'void' | 'unit' | 'int' | 'bool' | 'string' | 'bits' | 'hash' | 'signature'\n| 'address' | 'contract_pubkey' | 'Chain.ttl' | 'Chain.ga_meta_tx' | 'Chain.paying_for_tx'\n| 'Chain.base_tx' | 'AENS.pointee' | 'AENS.name' | 'MCL_BLS12_381.fr' | 'MCL_BLS12_381.fp'\n| { 'Set.set': readonly [AciValue] }\n| { bytes: number }\n| { list: readonly [AciValue] }\n| { map: readonly [AciValue, AciValue] }\n| { tuple: readonly AciValue[] }\n| { record: ReadonlyArray<{ name: string; type: AciValue }> }\n| { variant: ReadonlyArray<{ [key: string]: readonly AciValue[] }> }\n| { option: readonly [AciValue] }\n| { oracle: readonly [AciValue, AciValue] }\n| { oracle_query: readonly [AciValue, AciValue] };\n\nexport interface Domain {\n name?: string;\n version?: number;\n networkId?: string;\n contractAddress?: Encoded.ContractAddress;\n}\n\n/**\n * Hashes domain object, can be used to inline domain hash to contract source code\n */\nexport function hashDomain(domain: Domain): Buffer {\n const domainAci = {\n record: [{\n name: 'name',\n type: { option: ['string'] },\n }, {\n name: 'version',\n type: { option: ['int'] },\n }, {\n name: 'networkId',\n type: { option: ['string'] },\n }, {\n name: 'contractAddress',\n type: { option: ['contract_pubkey'] },\n }],\n } as const;\n const domainType = new TypeResolver().resolveType(domainAci, {});\n const fateValue = new ContractByteArrayEncoder().encodeWithType(domain, domainType);\n return hash(decode(fateValue));\n}\n\nexport function hashTypedData(\n data: Encoded.ContractBytearray,\n aci: AciValue,\n domain: Domain,\n): Buffer {\n return hash(concatBuffers([\n messagePrefixLength, new Uint8Array([0]), hashDomain(domain), hashJson(aci), hash(decode(data)),\n ]));\n}\n"],"mappings":"AAAA,OAAAA,sBAAA,MAAuD,0BAA0B;AAAC;EAAAC,YAAA;EAAAC;AAAA,IAAAF,sBAAA;AAClF,OAAOG,YAAY,MAAM,cAAc;AAAC,SACt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AU,CAACC,MAAM,CAAC,EAAEJ,QAAQ,CAACe,GAAG,CAAC,EAAElB,IAAI,CAACD,MAAM,CAACK,IAAI,CAAC,CAAC,CAChG,CAAC,CAAC;AACL"}
1
+ {"version":3,"file":"typed-data.mjs","names":["_aeternityAeppCalldata","TypeResolver","ContractByteArrayEncoder","canonicalize","decode","hash","messagePrefixLength","concatBuffers","hashJson","data","_canonicalize","hashDomain","domain","domainAci","record","name","type","option","domainType","resolveType","fateValue","encodeWithType","hashTypedData","aci","Uint8Array"],"sources":["../../src/utils/typed-data.ts"],"sourcesContent":["import { TypeResolver, ContractByteArrayEncoder } from '@aeternity/aepp-calldata';\nimport canonicalize from 'canonicalize';\nimport { Encoded, decode } from './encoder';\nimport { hash, messagePrefixLength } from './crypto';\nimport { concatBuffers } from './other';\n\n/**\n * Hashes arbitrary object, can be used to inline the aci hash to contract source code\n */\nexport function hashJson(data: unknown): Buffer {\n return hash(canonicalize(data) ?? '');\n}\n\n// TODO: move this type to calldata library https://github.com/aeternity/aepp-calldata-js/issues/215\n// based on https://github.com/aeternity/aepp-calldata-js/blob/82b5a98f9b308482627da8d7484d213e9cf87151/src/AciTypeResolver.js#L129\nexport type AciValue = 'void' | 'unit' | 'int' | 'bool' | 'string' | 'bits' | 'hash' | 'signature'\n| 'address' | 'contract_pubkey' | 'Chain.ttl' | 'Chain.ga_meta_tx' | 'Chain.paying_for_tx'\n| 'Chain.base_tx' | 'AENS.pointee' | 'AENS.name' | 'MCL_BLS12_381.fr' | 'MCL_BLS12_381.fp'\n| { 'Set.set': readonly [AciValue] }\n| { bytes: number }\n| { list: readonly [AciValue] }\n| { map: readonly [AciValue, AciValue] }\n| { tuple: readonly AciValue[] }\n| { record: ReadonlyArray<{ name: string; type: AciValue }> }\n| { variant: ReadonlyArray<{ [key: string]: readonly AciValue[] }> }\n| { option: readonly [AciValue] }\n| { oracle: readonly [AciValue, AciValue] }\n| { oracle_query: readonly [AciValue, AciValue] };\n\nexport interface Domain {\n name?: string;\n version?: number;\n networkId?: string;\n contractAddress?: Encoded.ContractAddress;\n}\n\n/**\n * Hashes domain object, can be used to inline domain hash to contract source code\n */\nexport function hashDomain(domain: Domain): Buffer {\n const domainAci = {\n record: [{\n name: 'name',\n type: { option: ['string'] },\n }, {\n name: 'version',\n type: { option: ['int'] },\n }, {\n name: 'networkId',\n type: { option: ['string'] },\n }, {\n name: 'contractAddress',\n type: { option: ['contract_pubkey'] },\n }],\n } as const;\n const domainType = new TypeResolver().resolveType(domainAci, {});\n const fateValue = new ContractByteArrayEncoder().encodeWithType(domain, domainType);\n return hash(decode(fateValue));\n}\n\nexport function hashTypedData(\n data: Encoded.ContractBytearray,\n aci: AciValue,\n domain: Domain,\n): Buffer {\n return hash(concatBuffers([\n messagePrefixLength, new Uint8Array([0]), hashDomain(domain), hashJson(aci), hash(decode(data)),\n ]));\n}\n"],"mappings":"AAAA,OAAAA,sBAAA,MAAuD,0BAA0B;AAAC;EAAAC,YAAA;EAAAC;AAAA,IAAAF,sBAAA;AAClF,OAAOG,YAAY,MAAM,cAAc;AAAC,SACtBC,MAAM;AAAA,SACfC,IAAI,EAAEC,mBAAmB;AAAA,SACzBC,aAAa;AAEtB;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAACC,IAAa,EAAU;EAAA,IAAAC,aAAA;EAC9C,OAAOL,IAAI,EAAAK,aAAA,GAACP,YAAY,CAACM,IAAI,CAAC,cAAAC,aAAA,cAAAA,aAAA,GAAI,EAAE,CAAC;AACvC;;AAEA;AACA;;AAsBA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACC,MAAc,EAAU;EACjD,MAAMC,SAAS,GAAG;IAChBC,MAAM,EAAE,CAAC;MACPC,IAAI,EAAE,MAAM;MACZC,IAAI,EAAE;QAAEC,MAAM,EAAE,CAAC,QAAQ;MAAE;IAC7B,CAAC,EAAE;MACDF,IAAI,EAAE,SAAS;MACfC,IAAI,EAAE;QAAEC,MAAM,EAAE,CAAC,KAAK;MAAE;IAC1B,CAAC,EAAE;MACDF,IAAI,EAAE,WAAW;MACjBC,IAAI,EAAE;QAAEC,MAAM,EAAE,CAAC,QAAQ;MAAE;IAC7B,CAAC,EAAE;MACDF,IAAI,EAAE,iBAAiB;MACvBC,IAAI,EAAE;QAAEC,MAAM,EAAE,CAAC,iBAAiB;MAAE;IACtC,CAAC;EACH,CAAU;EACV,MAAMC,UAAU,GAAG,IAAIjB,YAAY,CAAC,CAAC,CAACkB,WAAW,CAACN,SAAS,EAAE,CAAC,CAAC,CAAC;EAChE,MAAMO,SAAS,GAAG,IAAIlB,wBAAwB,CAAC,CAAC,CAACmB,cAAc,CAACT,MAAM,EAAEM,UAAU,CAAC;EACnF,OAAOb,IAAI,CAACD,MAAM,CAACgB,SAAS,CAAC,CAAC;AAChC;AAEA,OAAO,SAASE,aAAaA,CAC3Bb,IAA+B,EAC/Bc,GAAa,EACbX,MAAc,EACN;EACR,OAAOP,IAAI,CAACE,aAAa,CAAC,CACxBD,mBAAmB,EAAE,IAAIkB,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,EAAEb,UAAU,CAACC,MAAM,CAAC,EAAEJ,QAAQ,CAACe,GAAG,CAAC,EAAElB,IAAI,CAACD,MAAM,CAACK,IAAI,CAAC,CAAC,CAChG,CAAC,CAAC;AACL"}
@@ -0,0 +1,2 @@
1
+ export declare function wrapWithProxy<Value extends object | undefined>(valueCb: () => Value): NonNullable<Value>;
2
+ export declare function unwrapProxy<Value extends object>(value: Value): Value;
@@ -0,0 +1,15 @@
1
+ import { ArgumentError } from "./errors.mjs";
2
+ export function wrapWithProxy(valueCb) {
3
+ return new Proxy({}, Object.fromEntries(['apply', 'construct', 'defineProperty', 'deleteProperty', 'getOwnPropertyDescriptor', 'getPrototypeOf', 'isExtensible', 'ownKeys', 'preventExtensions', 'set', 'setPrototypeOf', 'get', 'has'].map(name => [name, (t, ...args) => {
4
+ const target = valueCb();
5
+ if (target == null) throw new ArgumentError('wrapped value', 'defined', target);
6
+ if (name === 'get' && args[0] === '_wrappedValue') return target;
7
+ const res = Reflect[name](target, ...args);
8
+ return typeof res === 'function' && name === 'get' ? res.bind(target) : res;
9
+ }])));
10
+ }
11
+ export function unwrapProxy(value) {
12
+ var _wrappedValue;
13
+ return (_wrappedValue = value._wrappedValue) !== null && _wrappedValue !== void 0 ? _wrappedValue : value;
14
+ }
15
+ //# sourceMappingURL=wrap-proxy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrap-proxy.mjs","names":["ArgumentError","wrapWithProxy","valueCb","Proxy","Object","fromEntries","map","name","t","args","target","res","Reflect","bind","unwrapProxy","value","_wrappedValue"],"sources":["../../src/utils/wrap-proxy.ts"],"sourcesContent":["import { ArgumentError } from './errors';\n\nexport function wrapWithProxy<Value extends object | undefined>(\n valueCb: () => Value,\n): NonNullable<Value> {\n return new Proxy(\n {},\n Object.fromEntries(([\n 'apply', 'construct', 'defineProperty', 'deleteProperty', 'getOwnPropertyDescriptor',\n 'getPrototypeOf', 'isExtensible', 'ownKeys', 'preventExtensions', 'set', 'setPrototypeOf',\n 'get', 'has',\n ] as const).map((name) => [name, (t: {}, ...args: unknown[]) => {\n const target = valueCb();\n if (target == null) throw new ArgumentError('wrapped value', 'defined', target);\n if (name === 'get' && args[0] === '_wrappedValue') return target;\n const res = (Reflect[name] as any)(target, ...args);\n return typeof res === 'function' && name === 'get' ? res.bind(target) : res;\n }])),\n ) as NonNullable<Value>;\n}\n\nexport function unwrapProxy<Value extends object>(value: Value): Value {\n return (value as { _wrappedValue?: Value })._wrappedValue ?? value;\n}\n"],"mappings":"SAASA,aAAa;AAEtB,OAAO,SAASC,aAAaA,CAC3BC,OAAoB,EACA;EACpB,OAAO,IAAIC,KAAK,CACd,CAAC,CAAC,EACFC,MAAM,CAACC,WAAW,CAAE,CAClB,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,0BAA0B,EACpF,gBAAgB,EAAE,cAAc,EAAE,SAAS,EAAE,mBAAmB,EAAE,KAAK,EAAE,gBAAgB,EACzF,KAAK,EAAE,KAAK,CACb,CAAWC,GAAG,CAAEC,IAAI,IAAK,CAACA,IAAI,EAAE,CAACC,CAAK,EAAE,GAAGC,IAAe,KAAK;IAC9D,MAAMC,MAAM,GAAGR,OAAO,CAAC,CAAC;IACxB,IAAIQ,MAAM,IAAI,IAAI,EAAE,MAAM,IAAIV,aAAa,CAAC,eAAe,EAAE,SAAS,EAAEU,MAAM,CAAC;IAC/E,IAAIH,IAAI,KAAK,KAAK,IAAIE,IAAI,CAAC,CAAC,CAAC,KAAK,eAAe,EAAE,OAAOC,MAAM;IAChE,MAAMC,GAAG,GAAIC,OAAO,CAACL,IAAI,CAAC,CAASG,MAAM,EAAE,GAAGD,IAAI,CAAC;IACnD,OAAO,OAAOE,GAAG,KAAK,UAAU,IAAIJ,IAAI,KAAK,KAAK,GAAGI,GAAG,CAACE,IAAI,CAACH,MAAM,CAAC,GAAGC,GAAG;EAC7E,CAAC,CAAC,CAAC,CACL,CAAC;AACH;AAEA,OAAO,SAASG,WAAWA,CAAuBC,KAAY,EAAS;EAAA,IAAAC,aAAA;EACrE,QAAAA,aAAA,GAAQD,KAAK,CAA+BC,aAAa,cAAAA,aAAA,cAAAA,aAAA,GAAID,KAAK;AACpE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeternity/aepp-sdk",
3
- "version": "13.2.2",
3
+ "version": "13.3.1",
4
4
  "description": "SDK for the æternity blockchain",
5
5
  "main": "dist/aepp-sdk.js",
6
6
  "types": "es/index.d.ts",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "sideEffects": false,
45
45
  "scripts": {
46
- "build:assets": "node tooling/fetch-aesophia-cli.mjs",
46
+ "build:assets": "node tooling/fetch-aesophia-cli.mjs && node tooling/fetch-aesophia-cli-8.mjs",
47
47
  "build:types": "tsc && node tooling/downlevel/run.mjs",
48
48
  "build:es": "babel src --config-file ./babel.esm.config.js --out-dir es --extensions .js,.ts --out-file-extension .mjs --source-maps true",
49
49
  "build:api:node": "autorest tooling/autorest/node.yaml",
@@ -75,23 +75,23 @@
75
75
  "SDK"
76
76
  ],
77
77
  "dependencies": {
78
- "@aeternity/aepp-calldata": "^1.5.1",
78
+ "@aeternity/aepp-calldata": "^1.7.0",
79
79
  "@aeternity/argon2": "^0.0.1",
80
80
  "@aeternity/uuid": "^0.0.1",
81
- "@azure/core-client": "1.6.0",
82
- "@azure/core-rest-pipeline": "^1.11.0",
83
- "@babel/runtime-corejs3": "^7.22.6",
84
- "@ledgerhq/hw-transport": "^6.28.6",
85
- "@types/aes-js": "^3.1.1",
86
- "@types/json-bigint": "^1.0.1",
87
- "@types/node": "~18.11.9",
88
- "@types/sha.js": "^2.4.1",
89
- "@types/uuid": "^9.0.2",
90
- "@types/webextension-polyfill": "^0.10.1",
91
- "@types/websocket": "^1.0.5",
92
- "@types/ws": "^8.5.5",
81
+ "@azure/core-client": "^1.8.0",
82
+ "@azure/core-rest-pipeline": "^1.14.0",
83
+ "@babel/runtime-corejs3": "^7.24.0",
84
+ "@ledgerhq/hw-transport": "^6.30.4",
85
+ "@types/aes-js": "^3.1.4",
86
+ "@types/json-bigint": "^1.0.4",
87
+ "@types/node": "~18.13",
88
+ "@types/sha.js": "^2.4.4",
89
+ "@types/uuid": "^9.0.8",
90
+ "@types/webextension-polyfill": "^0.10.7",
91
+ "@types/websocket": "^1.0.10",
92
+ "@types/ws": "^8.5.10",
93
93
  "aes-js": "^3.1.2",
94
- "bignumber.js": "^9.1.1",
94
+ "bignumber.js": "^9.1.2",
95
95
  "bip32-path": "^0.4.2",
96
96
  "blakejs": "^1.2.1",
97
97
  "bs58": "^5.0.0",
@@ -107,58 +107,58 @@
107
107
  "tweetnacl-auth": "^1.0.1",
108
108
  "varuint-bitcoin": "^1.1.2",
109
109
  "websocket": "^1.0.34",
110
- "ws": "^8.13.0"
110
+ "ws": "^8.16.0"
111
111
  },
112
112
  "repository": {
113
113
  "type": "git",
114
114
  "url": "https://github.com/aeternity/aepp-sdk-js"
115
115
  },
116
116
  "devDependencies": {
117
- "@babel/cli": "^7.22.9",
118
- "@babel/core": "^7.22.9",
119
- "@babel/node": "^7.22.6",
120
- "@babel/plugin-transform-runtime": "^7.22.9",
121
- "@babel/preset-env": "^7.22.9",
122
- "@babel/preset-typescript": "^7.22.5",
123
- "@babel/register": "^7.22.5",
124
- "@commitlint/cli": "^17.6.7",
125
- "@commitlint/config-conventional": "^17.6.7",
126
- "@ledgerhq/hw-transport-mocker": "^6.27.17",
127
- "@ledgerhq/hw-transport-node-hid-singleton": "^6.28.16",
128
- "@ledgerhq/hw-transport-webusb": "^6.27.17",
129
- "@types/chai": "^4.3.5",
130
- "@types/chai-as-promised": "^7.1.5",
131
- "@types/mocha": "^10.0.1",
132
- "@types/node-hid": "^1.3.1",
133
- "@types/sinon": "^10.0.15",
134
- "@typescript-eslint/eslint-plugin": "^6.2.0",
135
- "@typescript-eslint/parser": "^6.2.0",
136
- "autorest": "^3.6.3",
117
+ "@babel/cli": "^7.23.9",
118
+ "@babel/core": "^7.24.0",
119
+ "@babel/node": "^7.23.9",
120
+ "@babel/plugin-transform-runtime": "^7.24.0",
121
+ "@babel/preset-env": "^7.24.0",
122
+ "@babel/preset-typescript": "^7.23.3",
123
+ "@babel/register": "^7.23.7",
124
+ "@commitlint/cli": "^19.0.3",
125
+ "@commitlint/config-conventional": "^19.0.3",
126
+ "@ledgerhq/hw-transport-mocker": "^6.28.4",
127
+ "@ledgerhq/hw-transport-node-hid-singleton": "^6.30.4",
128
+ "@ledgerhq/hw-transport-webusb": "^6.28.4",
129
+ "@types/chai": "^4.3.12",
130
+ "@types/chai-as-promised": "^7.1.8",
131
+ "@types/mocha": "^10.0.6",
132
+ "@types/node-hid": "^1.3.4",
133
+ "@types/sinon": "^17.0.3",
134
+ "@typescript-eslint/eslint-plugin": "^7.1.1",
135
+ "@typescript-eslint/parser": "^7.1.1",
136
+ "autorest": "^3.7.1",
137
137
  "babel-loader": "^9.1.3",
138
138
  "babel-plugin-add-import-extension": "^1.6.0",
139
139
  "babel-plugin-import-globals": "^2.0.0",
140
140
  "babel-plugin-transform-default-named-imports": "^1.2.2",
141
- "babel-plugin-transform-import-meta": "^2.2.0",
142
- "chai": "^4.3.7",
141
+ "babel-plugin-transform-import-meta": "^2.2.1",
142
+ "chai": "^4.4.1",
143
143
  "chai-as-promised": "^7.1.1",
144
144
  "downlevel-dts": "github:aeternity/downlevel-dts",
145
- "eslint": "^8.45.0",
145
+ "eslint": "^8.57.0",
146
146
  "eslint-config-airbnb-base": "^15.0.0",
147
- "eslint-config-airbnb-typescript": "^17.1.0",
147
+ "eslint-config-airbnb-typescript": "^18.0.0",
148
148
  "eslint-plugin-rulesdir": "^0.2.2",
149
149
  "eslint-plugin-tsdoc": "^0.2.17",
150
- "html-webpack-plugin": "^5.5.3",
151
- "mocha": "^10.2.0",
150
+ "html-webpack-plugin": "^5.6.0",
151
+ "mocha": "^10.3.0",
152
152
  "nyc": "^15.1.0",
153
- "sinon": "^15.2.0",
153
+ "sinon": "^17.0.1",
154
154
  "source-map": "^0.7.4",
155
155
  "standard-version": "^9.5.0",
156
- "ts-node": "^10.9.1",
157
- "typedoc": "^0.24.8",
158
- "typedoc-plugin-missing-exports": "^2.0.0",
159
- "typescript": "^5.1.6",
160
- "webpack": "^5.88.2",
161
- "webpack-bundle-analyzer": "^4.9.0",
156
+ "ts-node": "^10.9.2",
157
+ "typedoc": "^0.25.11",
158
+ "typedoc-plugin-missing-exports": "^2.2.0",
159
+ "typescript": "^5.3.3",
160
+ "webpack": "^5.90.3",
161
+ "webpack-bundle-analyzer": "^4.10.1",
162
162
  "webpack-cli": "^5.1.4"
163
163
  },
164
164
  "files": [
@@ -189,5 +189,11 @@
189
189
  "engines": {
190
190
  "node": ">=14.19.0"
191
191
  },
192
- "packageManager": "npm@8.19.3"
192
+ "packageManager": "npm@8.19.3",
193
+ "contributors": [
194
+ "Till Kolter <till.kolter@gmail.com>",
195
+ "Alexander Kahl <ak@sodosopa.io>",
196
+ "Nazar Duchak <omelko39@gmail.com>",
197
+ "Denis Davidyuk <denis_davidyuk@hotmail.com>"
198
+ ]
193
199
  }
package/src/AeSdk.ts CHANGED
@@ -9,6 +9,9 @@ export default class AeSdk extends AeSdkBase {
9
9
 
10
10
  selectedAddress?: Encoded.AccountAddress;
11
11
 
12
+ /**
13
+ * @param options - Options
14
+ */
12
15
  constructor(
13
16
  { accounts, ...options }: { accounts?: AccountBase[] }
14
17
  & ConstructorParameters<typeof AeSdkBase>[0] = {},
package/src/AeSdkAepp.ts CHANGED
@@ -88,7 +88,6 @@ export default class AeSdkAepp extends AeSdkBase {
88
88
  * @param options - Options
89
89
  * @param options.connectNode - Request wallet to bind node
90
90
  * @param options.name - Node name
91
- * @param options.select - Select this node as current
92
91
  */
93
92
  async connectToWallet(
94
93
  connection: BrowserConnection,
package/src/AeSdkBase.ts CHANGED
@@ -4,8 +4,9 @@ import {
4
4
  CompilerError, DuplicateNodeError, NodeNotFoundError, NotImplementedError, TypeError,
5
5
  } from './utils/errors';
6
6
  import { Encoded } from './utils/encoder';
7
+ import { wrapWithProxy } from './utils/wrap-proxy';
7
8
  import CompilerBase from './contract/compiler/Base';
8
- import AeSdkMethods, { OnAccount, getValueOrErrorProxy, AeSdkMethodsOptions } from './AeSdkMethods';
9
+ import AeSdkMethods, { OnAccount, AeSdkMethodsOptions, WrappedOptions } from './AeSdkMethods';
9
10
  import { AensName } from './tx/builder/constants';
10
11
 
11
12
  type NodeInfo = Awaited<ReturnType<Node['getNodeInfo']>> & { name: string };
@@ -21,6 +22,8 @@ export default class AeSdkBase extends AeSdkMethods {
21
22
 
22
23
  selectedNodeName?: string;
23
24
 
25
+ readonly #wrappedOptions: WrappedOptions;
26
+
24
27
  /**
25
28
  * @param options - Options
26
29
  * @param options.nodes - Array of nodes
@@ -33,6 +36,12 @@ export default class AeSdkBase extends AeSdkMethods {
33
36
  super(options);
34
37
 
35
38
  nodes.forEach(({ name, instance }, i) => this.addNode(name, instance, i === 0));
39
+
40
+ this.#wrappedOptions = {
41
+ onNode: wrapWithProxy(() => this.api),
42
+ onCompiler: wrapWithProxy(() => this.compilerApi),
43
+ onAccount: wrapWithProxy(() => this._resolveAccount()),
44
+ };
36
45
  }
37
46
 
38
47
  // TODO: consider dropping this getter, because:
@@ -147,6 +156,11 @@ export default class AeSdkBase extends AeSdkMethods {
147
156
  return this._resolveAccount().address;
148
157
  }
149
158
 
159
+ /**
160
+ * Sign data blob
161
+ * @param data - Data to sign
162
+ * @param options - Options
163
+ */
150
164
  async sign(
151
165
  data: string | Uint8Array,
152
166
  { onAccount, ...options }: { onAccount?: OnAccount } = {},
@@ -154,6 +168,11 @@ export default class AeSdkBase extends AeSdkMethods {
154
168
  return this._resolveAccount(onAccount).sign(data, options);
155
169
  }
156
170
 
171
+ /**
172
+ * Sign encoded transaction
173
+ * @param tx - Transaction to sign
174
+ * @param options - Options
175
+ */
157
176
  async signTransaction(
158
177
  tx: Encoded.Transaction,
159
178
  { onAccount, ...options }: { onAccount?: OnAccount } & Parameters<AccountBase['signTransaction']>[1] = {},
@@ -162,6 +181,11 @@ export default class AeSdkBase extends AeSdkMethods {
162
181
  return this._resolveAccount(onAccount).signTransaction(tx, { networkId, ...options });
163
182
  }
164
183
 
184
+ /**
185
+ * Sign message
186
+ * @param message - Message to sign
187
+ * @param options - Options
188
+ */
165
189
  async signMessage(
166
190
  message: string,
167
191
  { onAccount, ...options }: { onAccount?: OnAccount } & Parameters<AccountBase['signMessage']>[1] = {},
@@ -169,6 +193,12 @@ export default class AeSdkBase extends AeSdkMethods {
169
193
  return this._resolveAccount(onAccount).signMessage(message, options);
170
194
  }
171
195
 
196
+ /**
197
+ * Sign typed data
198
+ * @param data - Encoded data to sign
199
+ * @param aci - Type of data to sign
200
+ * @param options - Options
201
+ */
172
202
  async signTypedData(
173
203
  data: Encoded.ContractBytearray,
174
204
  aci: Parameters<AccountBase['signTypedData']>[1],
@@ -177,6 +207,11 @@ export default class AeSdkBase extends AeSdkMethods {
177
207
  return this._resolveAccount(onAccount).signTypedData(data, aci, options);
178
208
  }
179
209
 
210
+ /**
211
+ * @deprecated use AeSdkBase:signDelegation in Ceres
212
+ * @param contractAddress - Contract address
213
+ * @param options - Options
214
+ */
180
215
  async signDelegationToContract(
181
216
  contractAddress: Encoded.ContractAddress,
182
217
  { onAccount, ...options }: { onAccount?: OnAccount }
@@ -184,10 +219,18 @@ export default class AeSdkBase extends AeSdkMethods {
184
219
  ): Promise<Encoded.Signature> {
185
220
  options.networkId ??= this.selectedNodeName !== null
186
221
  ? await this.api.getNetworkId() : undefined;
222
+ options.consensusProtocolVersion ??= this.selectedNodeName !== null
223
+ ? (await this.api.getNodeInfo()).consensusProtocolVersion : undefined;
187
224
  return this._resolveAccount(onAccount)
188
225
  .signDelegationToContract(contractAddress, options);
189
226
  }
190
227
 
228
+ /**
229
+ * @deprecated use AeSdkBase:signDelegation in Ceres
230
+ * @param contractAddress - Contract address
231
+ * @param name - AENS name
232
+ * @param options - Options
233
+ */
191
234
  async signNameDelegationToContract(
192
235
  contractAddress: Encoded.ContractAddress,
193
236
  name: AensName,
@@ -196,10 +239,36 @@ export default class AeSdkBase extends AeSdkMethods {
196
239
  ): Promise<Encoded.Signature> {
197
240
  options.networkId ??= this.selectedNodeName !== null
198
241
  ? await this.api.getNetworkId() : undefined;
242
+ options.consensusProtocolVersion ??= this.selectedNodeName !== null
243
+ ? (await this.api.getNodeInfo()).consensusProtocolVersion : undefined;
199
244
  return this._resolveAccount(onAccount)
200
245
  .signNameDelegationToContract(contractAddress, name, options);
201
246
  }
202
247
 
248
+ /**
249
+ * @deprecated use AeSdkBase:signDelegation in Ceres
250
+ * @param contractAddress - Contract address
251
+ * @param options - Options
252
+ */
253
+ async signAllNamesDelegationToContract(
254
+ contractAddress: Encoded.ContractAddress,
255
+ { onAccount, ...options }: { onAccount?: OnAccount }
256
+ & Parameters<AccountBase['signAllNamesDelegationToContract']>[1] = {},
257
+ ): Promise<Encoded.Signature> {
258
+ options.networkId ??= this.selectedNodeName !== null
259
+ ? await this.api.getNetworkId() : undefined;
260
+ options.consensusProtocolVersion ??= this.selectedNodeName !== null
261
+ ? (await this.api.getNodeInfo()).consensusProtocolVersion : undefined;
262
+ return this._resolveAccount(onAccount)
263
+ .signAllNamesDelegationToContract(contractAddress, options);
264
+ }
265
+
266
+ /**
267
+ * @deprecated use AeSdkBase:signDelegation in Ceres
268
+ * @param contractAddress - Contract address
269
+ * @param oracleQueryId - Oracle query id
270
+ * @param options - Options
271
+ */
203
272
  async signOracleQueryDelegationToContract(
204
273
  contractAddress: Encoded.ContractAddress,
205
274
  oracleQueryId: Encoded.OracleQueryId,
@@ -208,21 +277,39 @@ export default class AeSdkBase extends AeSdkMethods {
208
277
  ): Promise<Encoded.Signature> {
209
278
  options.networkId ??= this.selectedNodeName !== null
210
279
  ? await this.api.getNetworkId() : undefined;
280
+ options.consensusProtocolVersion ??= this.selectedNodeName !== null
281
+ ? (await this.api.getNodeInfo()).consensusProtocolVersion : undefined;
211
282
  return this._resolveAccount(onAccount)
212
283
  .signOracleQueryDelegationToContract(contractAddress, oracleQueryId, options);
213
284
  }
214
285
 
215
- override _getOptions(callOptions: AeSdkMethodsOptions = {}): {
216
- onNode: Node;
217
- onAccount: AccountBase;
218
- onCompiler: CompilerBase;
219
- } {
286
+ /**
287
+ * Sign delegation, works only in Ceres
288
+ * @param delegation - Delegation to sign
289
+ * @param options - Options
290
+ */
291
+ async signDelegation(
292
+ delegation: Encoded.Bytearray,
293
+ { onAccount, ...options }: { onAccount?: OnAccount }
294
+ & Parameters<AccountBase['signDelegation']>[1] = {},
295
+ ): Promise<Encoded.Signature> {
296
+ options.networkId ??= this.selectedNodeName !== null
297
+ ? await this.api.getNetworkId() : undefined;
298
+ return this._resolveAccount(onAccount).signDelegation(delegation, options);
299
+ }
300
+
301
+ /**
302
+ * The same as AeSdkMethods:getContext, but it would resolve ak_-prefixed address in
303
+ * `mergeWith.onAccount` to AccountBase.
304
+ */
305
+ override getContext(mergeWith: AeSdkMethodsOptions = {}): AeSdkMethodsOptions & WrappedOptions {
220
306
  return {
221
307
  ...this._options,
222
- onNode: getValueOrErrorProxy(() => this.api),
223
- onCompiler: getValueOrErrorProxy(() => this.compilerApi),
224
- ...callOptions,
225
- onAccount: getValueOrErrorProxy(() => this._resolveAccount(callOptions.onAccount)),
308
+ ...this.#wrappedOptions,
309
+ ...mergeWith,
310
+ ...mergeWith.onAccount != null && {
311
+ onAccount: this._resolveAccount(mergeWith.onAccount),
312
+ },
226
313
  };
227
314
  }
228
315
  }
@@ -1,4 +1,5 @@
1
1
  import * as chainMethods from './chain';
2
+ import { sendTransaction } from './send-transaction';
2
3
  import * as aensMethods from './aens';
3
4
  import * as spendMethods from './spend';
4
5
  import * as oracleMethods from './oracle';
@@ -7,6 +8,7 @@ import createDelegationSignature from './contract/delegation-signature';
7
8
  import * as contractGaMethods from './contract/ga';
8
9
  import { buildTxAsync } from './tx/builder';
9
10
  import { mapObject, UnionToIntersection } from './utils/other';
11
+ import { wrapWithProxy } from './utils/wrap-proxy';
10
12
  import Node from './Node';
11
13
  import { TxParamsAsync } from './tx/builder/schema.generated';
12
14
  import AccountBase from './account/Base';
@@ -15,29 +17,9 @@ import CompilerBase from './contract/compiler/Base';
15
17
 
16
18
  export type OnAccount = Encoded.AccountAddress | AccountBase | undefined;
17
19
 
18
- export function getValueOrErrorProxy<Value extends object | undefined>(
19
- valueCb: () => Value,
20
- ): NonNullable<Value> {
21
- return new Proxy(
22
- {},
23
- Object.fromEntries(([
24
- 'apply', 'construct', 'defineProperty', 'deleteProperty', 'getOwnPropertyDescriptor',
25
- 'getPrototypeOf', 'isExtensible', 'ownKeys', 'preventExtensions', 'set', 'setPrototypeOf',
26
- 'get', 'has',
27
- ] as const).map((name) => [name, (t: {}, ...args: unknown[]) => {
28
- const target = valueCb() as object; // to get a native exception in case it missed
29
- const res = (Reflect[name] as any)(target, ...args);
30
- return typeof res === 'function' && name === 'get'
31
- ? res.bind(target) // otherwise it fails with attempted to get private field on non-instance
32
- : res;
33
- }])),
34
- ) as NonNullable<Value>;
35
- }
36
-
37
- const { InvalidTxError: _2, ...chainMethodsOther } = chainMethods;
38
-
39
20
  const methods = {
40
- ...chainMethodsOther,
21
+ ...chainMethods,
22
+ sendTransaction,
41
23
  ...aensMethods,
42
24
  ...spendMethods,
43
25
  ...oracleMethods,
@@ -57,6 +39,12 @@ export interface AeSdkMethodsOptions
57
39
  extends Partial<UnionToIntersection<MethodsOptions[keyof MethodsOptions]>> {
58
40
  }
59
41
 
42
+ export interface WrappedOptions {
43
+ onAccount: AccountBase;
44
+ onCompiler: CompilerBase;
45
+ onNode: Node;
46
+ }
47
+
60
48
  /**
61
49
  * AeSdkMethods is the composition of:
62
50
  * - chain methods
@@ -73,33 +61,43 @@ export interface AeSdkMethodsOptions
73
61
  class AeSdkMethods {
74
62
  _options: AeSdkMethodsOptions = {};
75
63
 
64
+ readonly #wrappedOptions: WrappedOptions;
65
+
76
66
  /**
77
67
  * @param options - Options
78
68
  */
79
69
  constructor(options: AeSdkMethodsOptions = {}) {
80
70
  Object.assign(this._options, options);
71
+ this.#wrappedOptions = {
72
+ onAccount: wrapWithProxy(() => this._options.onAccount),
73
+ onNode: wrapWithProxy(() => this._options.onNode),
74
+ onCompiler: wrapWithProxy(() => this._options.onCompiler),
75
+ };
81
76
  }
82
77
 
83
- _getOptions(
84
- callOptions: AeSdkMethodsOptions = {},
85
- ): AeSdkMethodsOptions & { onAccount: AccountBase; onCompiler: CompilerBase; onNode: Node } {
78
+ /**
79
+ * Returns sdk instance options with references to current account, node, compiler.
80
+ * Used to create an instance (Contract, Oracle) bound to AeSdk state.
81
+ * @param mergeWith - Merge context with these extra options
82
+ * @returns Context object
83
+ */
84
+ getContext(mergeWith: AeSdkMethodsOptions = {}): AeSdkMethodsOptions & WrappedOptions {
86
85
  return {
87
86
  ...this._options,
88
- onAccount: getValueOrErrorProxy(() => this._options.onAccount),
89
- onNode: getValueOrErrorProxy(() => this._options.onNode),
90
- onCompiler: getValueOrErrorProxy(() => this._options.onCompiler),
91
- ...callOptions,
87
+ ...this.#wrappedOptions,
88
+ ...mergeWith,
92
89
  };
93
90
  }
94
91
 
92
+ // TODO: omit onNode from options, because it is already in context
95
93
  async buildTx(options: TxParamsAsync): Promise<Encoded.Transaction> {
96
- return buildTxAsync({ ...this._getOptions(), ...options });
94
+ return buildTxAsync({ ...this.getContext(), ...options });
97
95
  }
98
96
 
99
97
  async initializeContract<Methods extends ContractMethodsBase>(
100
98
  options?: Omit<Parameters<typeof Contract.initialize>[0], 'onNode'> & { onNode?: Node },
101
99
  ): Promise<Contract<Methods>> {
102
- return Contract.initialize<Methods>(this._getOptions(options as AeSdkMethodsOptions));
100
+ return Contract.initialize<Methods>(this.getContext(options as AeSdkMethodsOptions));
103
101
  }
104
102
  }
105
103
 
@@ -110,7 +108,13 @@ type RequiredKeys<T> = {
110
108
  type OptionalIfNotRequired<T extends [any]> = RequiredKeys<T[0]> extends never ? T | [] : T;
111
109
 
112
110
  type ReplaceOnAccount<Options> = Options extends { onAccount: any }
113
- ? Omit<Options, 'onAccount'> & { onAccount: OnAccount } : Options;
111
+ ? Omit<Options, 'onAccount'> & {
112
+ /**
113
+ * Make operation on specific account by providing address (to use account from sdk) or instance
114
+ * of AccountBase (like MemoryAccount)
115
+ */
116
+ onAccount: OnAccount;
117
+ } : Options;
114
118
 
115
119
  type MakeOptional<Options> = OptionalIfNotRequired<[
116
120
  Omit<Options, 'onNode' | 'onCompiler' | 'onAccount'> & Partial<ReplaceOnAccount<Options>>,
@@ -133,7 +137,7 @@ Object.assign(AeSdkMethods.prototype, mapObject<Function, Function>(
133
137
  function methodWrapper(this: AeSdkMethods, ...args: any[]) {
134
138
  args.length = handler.length;
135
139
  const options = args[args.length - 1];
136
- args[args.length - 1] = this._getOptions(options);
140
+ args[args.length - 1] = this.getContext(options);
137
141
  return handler(...args);
138
142
  },
139
143
  ],