@aeternity/aepp-sdk 11.0.0 → 12.1.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 (442) hide show
  1. package/LICENSE +1 -1
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -22
  4. package/dist/aepp-sdk.browser-script.js.map +1 -1
  5. package/dist/aepp-sdk.browser.js +2 -1
  6. package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
  7. package/dist/aepp-sdk.browser.js.map +1 -1
  8. package/dist/aepp-sdk.js +20764 -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 +70 -0
  14. package/es/AeSdkAepp.mjs +176 -0
  15. package/es/AeSdkAepp.mjs.map +1 -0
  16. package/es/AeSdkBase.d.ts +213 -0
  17. package/es/AeSdkBase.mjs +314 -0
  18. package/es/AeSdkBase.mjs.map +1 -0
  19. package/es/AeSdkWallet.d.ts +104 -0
  20. package/es/AeSdkWallet.mjs +326 -0
  21. package/es/AeSdkWallet.mjs.map +1 -0
  22. package/es/Node.d.ts +41 -0
  23. package/es/Node.mjs +147 -0
  24. package/es/Node.mjs.map +1 -0
  25. package/es/account/Base.d.ts +68 -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 +26 -0
  29. package/es/account/Memory.mjs +103 -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 +80 -0
  33. package/es/account/Rpc.mjs.map +1 -0
  34. package/es/aens.d.ts +222 -0
  35. package/es/aens.mjs +338 -0
  36. package/es/aens.mjs.map +1 -0
  37. package/es/aepp-wallet-communication/connection/Browser.d.ts +33 -0
  38. package/es/aepp-wallet-communication/connection/Browser.mjs +73 -0
  39. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
  40. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +18 -0
  41. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +58 -0
  42. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
  43. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +36 -0
  44. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +146 -0
  45. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
  46. package/es/aepp-wallet-communication/connection-proxy.d.ts +11 -0
  47. package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +16 -11
  48. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
  49. package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +34 -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 +105 -46
  56. package/es/aepp-wallet-communication/schema.mjs +251 -0
  57. package/es/aepp-wallet-communication/schema.mjs.map +1 -0
  58. package/es/aepp-wallet-communication/wallet-detector.d.ts +25 -0
  59. package/es/aepp-wallet-communication/wallet-detector.mjs +62 -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 +1065 -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 +4166 -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 +248 -0
  92. package/es/chain.mjs +560 -0
  93. package/es/chain.mjs.map +1 -0
  94. package/es/channel/handlers.d.ts +34 -0
  95. package/es/channel/handlers.mjs +164 -131
  96. package/es/channel/handlers.mjs.map +1 -1
  97. package/es/channel/index.d.ts +625 -0
  98. package/es/channel/index.mjs +897 -902
  99. package/es/channel/index.mjs.map +1 -1
  100. package/es/channel/internal.d.ts +101 -0
  101. package/es/channel/internal.mjs +138 -88
  102. package/es/channel/internal.mjs.map +1 -1
  103. package/es/contract/Compiler.d.ts +18 -0
  104. package/es/contract/Compiler.mjs +68 -0
  105. package/es/contract/Compiler.mjs.map +1 -0
  106. package/es/contract/aci.d.ts +127 -0
  107. package/es/contract/aci.mjs +225 -193
  108. package/es/contract/aci.mjs.map +1 -1
  109. package/es/contract/ga.d.ts +69 -0
  110. package/es/contract/ga.mjs +195 -0
  111. package/es/contract/ga.mjs.map +1 -0
  112. package/es/contract/methods.d.ts +71 -0
  113. package/es/contract/methods.mjs +104 -0
  114. package/es/contract/methods.mjs.map +1 -0
  115. package/es/deprecated/index.d.ts +143 -0
  116. package/es/deprecated/index.mjs +162 -0
  117. package/es/deprecated/index.mjs.map +1 -0
  118. package/es/deprecated/methods.d.ts +18 -0
  119. package/es/deprecated/methods.mjs +26 -0
  120. package/es/deprecated/methods.mjs.map +1 -0
  121. package/es/index.d.ts +35 -0
  122. package/es/index.mjs +35 -40
  123. package/es/index.mjs.map +1 -1
  124. package/es/oracle.d.ts +161 -0
  125. package/es/oracle.mjs +306 -0
  126. package/es/oracle.mjs.map +1 -0
  127. package/es/spend.d.ts +62 -0
  128. package/es/spend.mjs +111 -0
  129. package/es/spend.mjs.map +1 -0
  130. package/es/tx/builder/address.d.ts +25 -0
  131. package/es/tx/builder/address.mjs +45 -0
  132. package/es/tx/builder/address.mjs.map +1 -0
  133. package/es/tx/builder/constants.d.ts +70 -0
  134. package/es/tx/builder/constants.mjs +122 -0
  135. package/es/tx/builder/constants.mjs.map +1 -0
  136. package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
  137. package/es/tx/builder/field-types/coin-amount.mjs +26 -0
  138. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
  139. package/es/tx/builder/field-types/deposit.d.ts +15 -0
  140. package/es/tx/builder/field-types/deposit.mjs +19 -0
  141. package/es/tx/builder/field-types/deposit.mjs.map +1 -0
  142. package/es/tx/builder/field-types/fee.d.ts +25 -0
  143. package/es/tx/builder/field-types/fee.mjs +150 -0
  144. package/es/tx/builder/field-types/fee.mjs.map +1 -0
  145. package/es/tx/builder/field-types/field.d.ts +6 -0
  146. package/es/tx/builder/field-types/field.mjs +15 -0
  147. package/es/tx/builder/field-types/field.mjs.map +1 -0
  148. package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
  149. package/es/tx/builder/field-types/gas-limit.mjs +33 -0
  150. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
  151. package/es/tx/builder/field-types/gas-price.d.ts +8 -0
  152. package/es/tx/builder/field-types/gas-price.mjs +18 -0
  153. package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
  154. package/es/tx/builder/field-types/index.d.ts +70 -0
  155. package/es/tx/builder/field-types/index.mjs +25 -0
  156. package/es/tx/builder/field-types/index.mjs.map +1 -0
  157. package/es/tx/builder/field-types/name-fee.d.ts +20 -0
  158. package/es/tx/builder/field-types/name-fee.mjs +24 -0
  159. package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
  160. package/es/tx/builder/field-types/name-id.d.ts +14 -0
  161. package/es/tx/builder/field-types/name-id.mjs +19 -0
  162. package/es/tx/builder/field-types/name-id.mjs.map +1 -0
  163. package/es/tx/builder/field-types/name.d.ts +13 -0
  164. package/es/tx/builder/field-types/name.mjs +18 -0
  165. package/es/tx/builder/field-types/name.mjs.map +1 -0
  166. package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
  167. package/es/tx/builder/field-types/short-u-int.mjs +12 -0
  168. package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
  169. package/es/tx/builder/field-types/u-int.d.ts +8 -0
  170. package/es/tx/builder/field-types/u-int.mjs +14 -0
  171. package/es/tx/builder/field-types/u-int.mjs.map +1 -0
  172. package/es/tx/builder/helpers.d.ts +125 -0
  173. package/es/tx/builder/helpers.mjs +94 -240
  174. package/es/tx/builder/helpers.mjs.map +1 -1
  175. package/es/tx/builder/index.d.ts +88 -0
  176. package/es/tx/builder/index.mjs +167 -358
  177. package/es/tx/builder/index.mjs.map +1 -1
  178. package/es/tx/builder/schema.d.ts +1201 -0
  179. package/es/tx/builder/schema.mjs +175 -664
  180. package/es/tx/builder/schema.mjs.map +1 -1
  181. package/es/tx/index.d.ts +64 -0
  182. package/es/tx/index.mjs +151 -265
  183. package/es/tx/index.mjs.map +1 -1
  184. package/es/tx/validator.d.ts +20 -0
  185. package/es/tx/validator.mjs +104 -124
  186. package/es/tx/validator.mjs.map +1 -1
  187. package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
  188. package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
  189. package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
  190. package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
  191. package/es/typings/bip32-path/index.d.mjs +2 -0
  192. package/es/typings/bip32-path/index.d.mjs.map +1 -0
  193. package/es/typings/blakejs/index.d.mjs.map +1 -1
  194. package/es/typings/sha-js/index.d.mjs +2 -0
  195. package/es/typings/sha-js/index.d.mjs.map +1 -0
  196. package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
  197. package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
  198. package/es/utils/amount-formatter.d.ts +42 -0
  199. package/es/utils/amount-formatter.mjs +36 -49
  200. package/es/utils/amount-formatter.mjs.map +1 -1
  201. package/es/utils/autorest.d.ts +6 -0
  202. package/es/utils/autorest.mjs +97 -0
  203. package/es/utils/autorest.mjs.map +1 -0
  204. package/es/utils/bignumber.d.ts +13 -0
  205. package/es/utils/bignumber.mjs +11 -8
  206. package/es/utils/bignumber.mjs.map +1 -1
  207. package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
  208. package/es/utils/bytes.mjs +11 -15
  209. package/es/utils/bytes.mjs.map +1 -1
  210. package/es/utils/crypto.d.ts +88 -0
  211. package/es/utils/crypto.mjs +64 -108
  212. package/es/utils/crypto.mjs.map +1 -1
  213. package/es/utils/encoder-types.d.ts +61 -0
  214. package/es/utils/encoder-types.mjs +36 -0
  215. package/es/utils/encoder-types.mjs.map +1 -0
  216. package/es/utils/encoder.d.ts +25 -0
  217. package/es/utils/encoder.mjs +118 -0
  218. package/es/utils/encoder.mjs.map +1 -0
  219. package/es/{errors.d.ts → utils/errors.d.ts} +246 -59
  220. package/es/utils/errors.mjs +313 -136
  221. package/es/utils/errors.mjs.map +1 -1
  222. package/es/utils/hd-wallet.d.ts +50 -0
  223. package/es/utils/hd-wallet.mjs +86 -45
  224. package/es/utils/hd-wallet.mjs.map +1 -1
  225. package/es/utils/json-big.d.ts +5 -0
  226. package/es/utils/json-big.mjs +12 -16
  227. package/es/utils/json-big.mjs.map +1 -1
  228. package/es/utils/keystore.d.ts +51 -0
  229. package/es/utils/keystore.mjs +101 -194
  230. package/es/utils/keystore.mjs.map +1 -1
  231. package/es/{mptree.d.ts → utils/mptree.d.ts} +6 -9
  232. package/es/utils/mptree.mjs +22 -18
  233. package/es/utils/mptree.mjs.map +1 -1
  234. package/es/utils/other.d.ts +20 -0
  235. package/es/utils/other.mjs +32 -35
  236. package/es/utils/other.mjs.map +1 -1
  237. package/es/utils/semver-satisfies.d.ts +1 -0
  238. package/es/utils/semver-satisfies.mjs +2 -2
  239. package/es/utils/semver-satisfies.mjs.map +1 -1
  240. package/es/utils/string.d.ts +24 -0
  241. package/es/utils/string.mjs +8 -10
  242. package/es/utils/string.mjs.map +1 -1
  243. package/package.json +56 -42
  244. package/src/AeSdk.ts +68 -0
  245. package/src/AeSdkAepp.ts +176 -0
  246. package/src/AeSdkBase.ts +338 -0
  247. package/src/AeSdkWallet.ts +348 -0
  248. package/src/Node.ts +173 -0
  249. package/src/account/Base.ts +124 -0
  250. package/src/account/Memory.ts +98 -0
  251. package/src/account/Rpc.ts +69 -0
  252. package/src/aens.ts +407 -0
  253. package/src/aepp-wallet-communication/connection/Browser.ts +71 -0
  254. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +59 -0
  255. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +122 -0
  256. package/{es/utils/crypto-ts.mjs → src/aepp-wallet-communication/connection-proxy.ts} +18 -18
  257. package/src/aepp-wallet-communication/rpc/RpcClient.ts +143 -0
  258. package/src/aepp-wallet-communication/rpc/types.ts +66 -0
  259. package/src/aepp-wallet-communication/schema.ts +224 -0
  260. package/src/aepp-wallet-communication/wallet-detector.ts +72 -0
  261. package/src/apis/compiler/code-model-v4.yaml +2649 -0
  262. package/src/apis/compiler/compiler.ts +585 -0
  263. package/src/apis/compiler/index.ts +2 -0
  264. package/src/apis/compiler/models/index.ts +301 -0
  265. package/src/apis/compiler/models/mappers.ts +583 -0
  266. package/src/apis/compiler/models/parameters.ts +93 -0
  267. package/src/apis/node/code-model-v4.yaml +10080 -0
  268. package/src/apis/node/index.ts +2 -0
  269. package/src/apis/node/models/index.ts +1257 -0
  270. package/src/apis/node/models/mappers.ts +4280 -0
  271. package/src/apis/node/models/parameters.ts +188 -0
  272. package/src/apis/node/node.ts +1299 -0
  273. package/src/chain.ts +502 -0
  274. package/src/channel/handlers.ts +817 -0
  275. package/src/channel/index.ts +1025 -0
  276. package/src/channel/internal.ts +361 -0
  277. package/src/contract/Compiler.ts +67 -0
  278. package/src/contract/aci.ts +538 -0
  279. package/src/contract/ga.ts +199 -0
  280. package/src/contract/methods.ts +123 -0
  281. package/src/deprecated/index.ts +170 -0
  282. package/src/deprecated/methods.ts +25 -0
  283. package/src/index.ts +56 -0
  284. package/src/oracle.ts +364 -0
  285. package/src/spend.ts +164 -0
  286. package/src/tx/builder/address.ts +50 -0
  287. package/src/tx/builder/constants.ts +126 -0
  288. package/src/tx/builder/field-types/coin-amount.ts +27 -0
  289. package/src/tx/builder/field-types/deposit.ts +21 -0
  290. package/src/tx/builder/field-types/fee.ts +143 -0
  291. package/src/tx/builder/field-types/field.ts +9 -0
  292. package/src/tx/builder/field-types/gas-limit.ts +41 -0
  293. package/src/tx/builder/field-types/gas-price.ts +16 -0
  294. package/src/tx/builder/field-types/index.ts +45 -0
  295. package/src/tx/builder/field-types/name-fee.ts +32 -0
  296. package/src/tx/builder/field-types/name-id.ts +20 -0
  297. package/src/tx/builder/field-types/name.ts +18 -0
  298. package/src/tx/builder/field-types/short-u-int.ts +11 -0
  299. package/src/tx/builder/field-types/u-int.ts +16 -0
  300. package/src/tx/builder/helpers.ts +248 -0
  301. package/src/tx/builder/index.ts +400 -0
  302. package/src/tx/builder/schema.ts +727 -0
  303. package/src/tx/index.ts +192 -0
  304. package/src/tx/validator.ts +230 -0
  305. package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
  306. package/src/typings/@aeternity__uuid/index.d.ts +5 -0
  307. package/src/typings/bip32-path/index.d.ts +33 -0
  308. package/src/typings/blakejs/index.d.ts +4 -32
  309. package/src/typings/sha-js/index.d.ts +5 -0
  310. package/src/typings/tweetnacl-auth/index.d.ts +14 -0
  311. package/src/utils/amount-formatter.ts +56 -69
  312. package/src/utils/autorest.ts +93 -0
  313. package/src/utils/bignumber.ts +11 -12
  314. package/src/utils/bytes.ts +29 -31
  315. package/src/utils/crypto.ts +205 -0
  316. package/src/utils/encoder-types.ts +63 -0
  317. package/src/utils/encoder.ts +146 -0
  318. package/src/utils/errors.ts +482 -366
  319. package/src/utils/hd-wallet.ts +166 -0
  320. package/src/utils/json-big.ts +27 -0
  321. package/src/utils/keystore.ts +182 -0
  322. package/src/utils/mptree.ts +64 -61
  323. package/src/utils/other.ts +34 -41
  324. package/src/utils/semver-satisfies.ts +15 -11
  325. package/src/utils/string.ts +18 -20
  326. package/es/account/base.mjs +0 -179
  327. package/es/account/base.mjs.map +0 -1
  328. package/es/account/memory.mjs +0 -99
  329. package/es/account/memory.mjs.map +0 -1
  330. package/es/account/multiple.mjs +0 -179
  331. package/es/account/multiple.mjs.map +0 -1
  332. package/es/ae/aens.mjs +0 -404
  333. package/es/ae/aens.mjs.map +0 -1
  334. package/es/ae/aepp.mjs +0 -45
  335. package/es/ae/aepp.mjs.map +0 -1
  336. package/es/ae/contract.mjs +0 -159
  337. package/es/ae/contract.mjs.map +0 -1
  338. package/es/ae/index.mjs +0 -207
  339. package/es/ae/index.mjs.map +0 -1
  340. package/es/ae/oracle.mjs +0 -339
  341. package/es/ae/oracle.mjs.map +0 -1
  342. package/es/ae/universal.mjs +0 -45
  343. package/es/ae/universal.mjs.map +0 -1
  344. package/es/ae/wallet.mjs +0 -50
  345. package/es/ae/wallet.mjs.map +0 -1
  346. package/es/amount-formatter.d.ts +0 -58
  347. package/es/bignumber.d.ts +0 -18
  348. package/es/chain/index.mjs +0 -272
  349. package/es/chain/index.mjs.map +0 -1
  350. package/es/chain/node.mjs +0 -442
  351. package/es/chain/node.mjs.map +0 -1
  352. package/es/contract/compiler.mjs +0 -115
  353. package/es/contract/compiler.mjs.map +0 -1
  354. package/es/contract/ga/helpers.mjs +0 -30
  355. package/es/contract/ga/helpers.mjs.map +0 -1
  356. package/es/contract/ga/index.mjs +0 -178
  357. package/es/contract/ga/index.mjs.map +0 -1
  358. package/es/crypto-ts.d.ts +0 -9
  359. package/es/node-pool/index.mjs +0 -188
  360. package/es/node-pool/index.mjs.map +0 -1
  361. package/es/node.mjs +0 -133
  362. package/es/node.mjs.map +0 -1
  363. package/es/other.d.ts +0 -31
  364. package/es/semver-satisfies.d.ts +0 -1
  365. package/es/string.d.ts +0 -26
  366. package/es/tx/builder/field-types.mjs +0 -74
  367. package/es/tx/builder/field-types.mjs.map +0 -1
  368. package/es/tx/tx-object.mjs +0 -283
  369. package/es/tx/tx-object.mjs.map +0 -1
  370. package/es/tx/tx.mjs +0 -938
  371. package/es/tx/tx.mjs.map +0 -1
  372. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs +0 -132
  373. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +0 -1
  374. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +0 -183
  375. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +0 -1
  376. package/es/utils/aepp-wallet-communication/connection/index.mjs +0 -87
  377. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +0 -1
  378. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs +0 -98
  379. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +0 -1
  380. package/es/utils/aepp-wallet-communication/helpers.mjs +0 -92
  381. package/es/utils/aepp-wallet-communication/helpers.mjs.map +0 -1
  382. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +0 -375
  383. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +0 -1
  384. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +0 -275
  385. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +0 -1
  386. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +0 -541
  387. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +0 -1
  388. package/es/utils/aepp-wallet-communication/schema.mjs +0 -102
  389. package/es/utils/aepp-wallet-communication/schema.mjs.map +0 -1
  390. package/es/utils/aepp-wallet-communication/wallet-detector.mjs +0 -110
  391. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +0 -1
  392. package/es/utils/async-init.mjs +0 -64
  393. package/es/utils/async-init.mjs.map +0 -1
  394. package/es/utils/crypto-ts.mjs.map +0 -1
  395. package/es/utils/swagger.mjs +0 -164
  396. package/es/utils/swagger.mjs.map +0 -1
  397. package/src/account/base.js +0 -153
  398. package/src/account/memory.js +0 -83
  399. package/src/account/multiple.js +0 -162
  400. package/src/ae/aens.js +0 -361
  401. package/src/ae/aepp.js +0 -45
  402. package/src/ae/contract.js +0 -148
  403. package/src/ae/index.js +0 -168
  404. package/src/ae/oracle.js +0 -311
  405. package/src/ae/universal.js +0 -47
  406. package/src/ae/wallet.js +0 -50
  407. package/src/chain/index.js +0 -269
  408. package/src/chain/node.js +0 -320
  409. package/src/channel/handlers.js +0 -673
  410. package/src/channel/index.js +0 -898
  411. package/src/channel/internal.js +0 -237
  412. package/src/contract/aci.js +0 -376
  413. package/src/contract/compiler.js +0 -100
  414. package/src/contract/ga/helpers.js +0 -19
  415. package/src/contract/ga/index.js +0 -150
  416. package/src/index.js +0 -89
  417. package/src/node-pool/index.js +0 -172
  418. package/src/node.js +0 -116
  419. package/src/tx/builder/field-types.js +0 -61
  420. package/src/tx/builder/helpers.js +0 -380
  421. package/src/tx/builder/index.js +0 -465
  422. package/src/tx/builder/schema.js +0 -1197
  423. package/src/tx/index.js +0 -301
  424. package/src/tx/tx-object.js +0 -187
  425. package/src/tx/tx.js +0 -631
  426. package/src/tx/validator.js +0 -181
  427. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -119
  428. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -165
  429. package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
  430. package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -86
  431. package/src/utils/aepp-wallet-communication/helpers.js +0 -60
  432. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -294
  433. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -232
  434. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -401
  435. package/src/utils/aepp-wallet-communication/schema.ts +0 -80
  436. package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -92
  437. package/src/utils/async-init.js +0 -45
  438. package/src/utils/crypto.js +0 -229
  439. package/src/utils/hd-wallet.js +0 -100
  440. package/src/utils/json-big.js +0 -26
  441. package/src/utils/keystore.js +0 -219
  442. package/src/utils/swagger.js +0 -156
@@ -0,0 +1,166 @@
1
+ import nacl from 'tweetnacl';
2
+ import { full as hmac } from 'tweetnacl-auth';
3
+ import { fromString } from 'bip32-path';
4
+ import aesjs from 'aes-js';
5
+ import { sha256hash, encode, Encoding } from './encoder';
6
+ import { CryptographyError } from './errors';
7
+ import { bytesToHex } from './bytes';
8
+ import { concatBuffers } from './other';
9
+
10
+ const Ecb = aesjs.ModeOfOperation.ecb;
11
+
12
+ // TODO: at least don't export `encryptKey` and `decryptKey`
13
+ /**
14
+ * Encrypt given data using `password`
15
+ * @param password - Password to encrypt with
16
+ * @param binaryData - Data to encrypt
17
+ * @returns Encrypted data
18
+ * @deprecated use 'sha.js' and 'aes-js' packages directly instead
19
+ */
20
+ export function encryptKey(password: string, binaryData: Uint8Array): Uint8Array {
21
+ const hashedPasswordBytes = sha256hash(password);
22
+ const aesEcb = new Ecb(hashedPasswordBytes);
23
+ return aesEcb.encrypt(binaryData);
24
+ }
25
+
26
+ /**
27
+ * Decrypt given data using `password`
28
+ * @param password - Password to decrypt with
29
+ * @param encrypted - Data to decrypt
30
+ * @returns Decrypted data
31
+ * @deprecated use 'sha.js' and 'aes-js' packages directly instead
32
+ */
33
+ export function decryptKey(password: string, encrypted: Uint8Array): Uint8Array {
34
+ const encryptedBytes = Buffer.from(encrypted);
35
+ const hashedPasswordBytes = sha256hash(password);
36
+ const aesEcb = new Ecb(hashedPasswordBytes);
37
+ return aesEcb.decrypt(encryptedBytes);
38
+ }
39
+
40
+ /**
41
+ * @category exception
42
+ */
43
+ export class DerivationError extends CryptographyError {
44
+ constructor(message: string) {
45
+ super(message);
46
+ this.name = 'DerivationError';
47
+ }
48
+ }
49
+
50
+ const ED25519_CURVE = Buffer.from('ed25519 seed');
51
+ const HARDENED_OFFSET = 0x80000000;
52
+
53
+ interface KeyTreeNode {
54
+ secretKey: Uint8Array;
55
+ chainCode: Uint8Array;
56
+ }
57
+
58
+ interface HDWallet {
59
+ secretKey: string;
60
+ chainCode: string;
61
+ }
62
+
63
+ interface Account {
64
+ secretKey: string;
65
+ publicKey: string;
66
+ }
67
+
68
+ type Dec<N extends number> = [-1, 0, 1, 2, 3, 4][N];
69
+ type Bip32PathT<MaxLen extends number, H extends 'H' | 'h' | '\''> = MaxLen extends -1
70
+ ? `${number}${H}`
71
+ : Bip32PathT<Dec<MaxLen>, H> | `${Bip32PathT<Dec<MaxLen>, H>}/${number}${H}`;
72
+ type Bip32Path<MaxLen extends number> =
73
+ '' | Bip32PathT<MaxLen, 'H'> | Bip32PathT<MaxLen, 'h'> | Bip32PathT<MaxLen, '\''>;
74
+
75
+ export function deriveChild({ secretKey, chainCode }: KeyTreeNode, index: number): KeyTreeNode {
76
+ if (index < HARDENED_OFFSET) {
77
+ throw new DerivationError(`Segment ${index} is not hardened`);
78
+ }
79
+ const indexBuffer = Buffer.allocUnsafe(4);
80
+ indexBuffer.writeUInt32BE(index, 0);
81
+
82
+ const data = concatBuffers([Buffer.alloc(1, 0), secretKey, indexBuffer]);
83
+
84
+ const I = hmac(data, chainCode);
85
+ const IL = I.slice(0, 32);
86
+ const IR = I.slice(32);
87
+ return {
88
+ secretKey: IL,
89
+ chainCode: IR,
90
+ };
91
+ }
92
+
93
+ export function derivePathFromKey(path: Bip32Path<5>, key: KeyTreeNode): KeyTreeNode {
94
+ const segments = path === '' ? [] : fromString(path).toPathArray();
95
+ segments.forEach((segment, i) => {
96
+ if (segment < HARDENED_OFFSET) {
97
+ throw new DerivationError(`Segment #${i + 1} is not hardened`);
98
+ }
99
+ });
100
+
101
+ return segments.reduce((parentKey, segment) => deriveChild(parentKey, segment), key);
102
+ }
103
+
104
+ export function getMasterKeyFromSeed(seed: Uint8Array): KeyTreeNode {
105
+ const I = hmac(seed, ED25519_CURVE);
106
+ const IL = I.slice(0, 32);
107
+ const IR = I.slice(32);
108
+ return {
109
+ secretKey: IL,
110
+ chainCode: IR,
111
+ };
112
+ }
113
+
114
+ export function derivePathFromSeed(path: 'm' | `m/${Bip32Path<5>}`, seed: Uint8Array): KeyTreeNode {
115
+ if (!['m', 'm/'].includes(path.slice(0, 2))) {
116
+ throw new DerivationError('Root element is required');
117
+ }
118
+ const masterKey = getMasterKeyFromSeed(seed);
119
+ return derivePathFromKey(path.slice(2) as Bip32Path<5>, masterKey);
120
+ }
121
+
122
+ function formatAccount(keys: nacl.SignKeyPair): Account {
123
+ const { secretKey, publicKey } = keys;
124
+ return {
125
+ secretKey: bytesToHex(secretKey),
126
+ publicKey: encode(publicKey, Encoding.AccountAddress),
127
+ };
128
+ }
129
+
130
+ export function getKeyPair(secretKey: Uint8Array): nacl.SignKeyPair {
131
+ return nacl.sign.keyPair.fromSeed(secretKey);
132
+ }
133
+
134
+ export function generateSaveHDWalletFromSeed(seed: Uint8Array, password: string): HDWallet {
135
+ const walletKey = derivePathFromSeed('m/44h/457h', seed);
136
+ return {
137
+ secretKey: bytesToHex(encryptKey(password, walletKey.secretKey)),
138
+ chainCode: bytesToHex(encryptKey(password, walletKey.chainCode)),
139
+ };
140
+ }
141
+
142
+ export function getSaveHDWalletAccounts(
143
+ saveHDWallet: HDWallet,
144
+ password: string,
145
+ accountCount: number,
146
+ ): Account[] {
147
+ const walletKey = {
148
+ secretKey: decryptKey(password, Buffer.from(saveHDWallet.secretKey, 'hex')),
149
+ chainCode: decryptKey(password, Buffer.from(saveHDWallet.chainCode, 'hex')),
150
+ };
151
+ return (new Array(accountCount)).fill(undefined)
152
+ .map((_, idx) => formatAccount(getKeyPair(derivePathFromKey(`${idx}h/0h/0h`, walletKey).secretKey)));
153
+ }
154
+
155
+ export const getHdWalletAccountFromSeed = (
156
+ seed: Uint8Array,
157
+ accountIdx: number,
158
+ ): Account & { idx: number } => {
159
+ const walletKey = derivePathFromSeed('m/44h/457h', seed);
160
+ const derived = derivePathFromKey(`${accountIdx}h/0h/0h`, walletKey);
161
+ const keyPair = getKeyPair(derived.secretKey);
162
+ return {
163
+ ...formatAccount(keyPair),
164
+ idx: accountIdx,
165
+ };
166
+ };
@@ -0,0 +1,27 @@
1
+ import JsonBig from 'json-bigint';
2
+ import BigNumber from 'bignumber.js';
3
+ import { mapObject } from './other';
4
+
5
+ const jsonBig = JsonBig({ storeAsString: true });
6
+
7
+ const convertValuesToBigNumbers = (value: any): any => {
8
+ if (typeof value === 'object' && value !== null && value.constructor === Object) {
9
+ return mapObject(value, ([k, v]) => [k, convertValuesToBigNumbers(v)]);
10
+ }
11
+ if (Array.isArray(value)) {
12
+ return value.map((item) => convertValuesToBigNumbers(item));
13
+ }
14
+ if (typeof value === 'string' && new BigNumber(value).toString(10) === value) {
15
+ const bn = new BigNumber(value);
16
+ bn.toJSON = () => bn.toString(10);
17
+ return bn;
18
+ }
19
+ return value;
20
+ };
21
+
22
+ export default {
23
+ stringify: (...args: Parameters<typeof JsonBig['stringify']>): string => (
24
+ jsonBig.stringify(convertValuesToBigNumbers(args[0]), ...args.slice(1))
25
+ ),
26
+ parse: jsonBig.parse,
27
+ };
@@ -0,0 +1,182 @@
1
+ import nacl from 'tweetnacl';
2
+ import { v4 as uuid } from '@aeternity/uuid';
3
+ // js extension is required for mjs build
4
+ // eslint-disable-next-line import/extensions
5
+ import { ArgonType, hash } from '@aeternity/argon2-browser/dist/argon2-bundled.min.js';
6
+ import { getAddressFromPriv } from './crypto';
7
+ import { bytesToHex, hexToBytes } from './bytes';
8
+ import { InvalidPasswordError } from './errors';
9
+
10
+ const DERIVED_KEY_FUNCTIONS = {
11
+ async argon2id(
12
+ pass: string | Uint8Array,
13
+ salt: string | Uint8Array,
14
+ params: Partial<Keystore['crypto']['kdf_params']>,
15
+ ): Promise<Uint8Array> {
16
+ const { memlimit_kib: mem, opslimit: time } = params;
17
+
18
+ return (await hash({
19
+ hashLen: 32,
20
+ pass,
21
+ salt,
22
+ time,
23
+ mem,
24
+ type: ArgonType.Argon2id,
25
+ })).hash;
26
+ },
27
+ };
28
+
29
+ const CRYPTO_FUNCTIONS = {
30
+ 'xsalsa20-poly1305': {
31
+ encrypt: nacl.secretbox,
32
+ decrypt(...args: Parameters<typeof nacl.secretbox.open>): Uint8Array {
33
+ const res = nacl.secretbox.open(...args);
34
+ if (res == null) throw new InvalidPasswordError();
35
+ return res;
36
+ },
37
+ },
38
+ };
39
+
40
+ export interface Keystore {
41
+ name: string;
42
+ version: 1;
43
+ public_key: string;
44
+ id: string;
45
+ crypto: {
46
+ secret_type: 'ed25519';
47
+ symmetric_alg: keyof typeof CRYPTO_FUNCTIONS;
48
+ ciphertext: string;
49
+ cipher_params: {
50
+ nonce: string;
51
+ };
52
+ kdf: keyof typeof DERIVED_KEY_FUNCTIONS;
53
+ kdf_params: {
54
+ memlimit_kib: number;
55
+ opslimit: number;
56
+ parallelism: number;
57
+ salt: string;
58
+ };
59
+ };
60
+ }
61
+
62
+ const CRYPTO_DEFAULTS = {
63
+ secret_type: 'ed25519',
64
+ symmetric_alg: 'xsalsa20-poly1305',
65
+ kdf: 'argon2id',
66
+ kdf_params: {
67
+ memlimit_kib: 65536,
68
+ opslimit: 3,
69
+ parallelism: 1,
70
+ },
71
+ } as const;
72
+
73
+ /**
74
+ * Symmetric private key encryption using secret (derived) key.
75
+ * @param plaintext - Data to be encrypted.
76
+ * @param key - Secret key.
77
+ * @param nonce - Randomly generated nonce.
78
+ * @param algo - Encryption algorithm.
79
+ * @returns Encrypted data.
80
+ */
81
+ function encrypt(
82
+ plaintext: Uint8Array,
83
+ key: Uint8Array,
84
+ nonce: Uint8Array,
85
+ algo: keyof typeof CRYPTO_FUNCTIONS = CRYPTO_DEFAULTS.symmetric_alg,
86
+ ): Uint8Array {
87
+ return CRYPTO_FUNCTIONS[algo].encrypt(plaintext, nonce, key);
88
+ }
89
+
90
+ /**
91
+ * Symmetric private key decryption using secret (derived) key.
92
+ * @param ciphertext - Data to be decrypted.
93
+ * @param key - Secret key.
94
+ * @param nonce - Nonce from key-object.
95
+ * @param algo - Encryption algorithm.
96
+ * @returns Decrypted data.
97
+ */
98
+ function decrypt(
99
+ ciphertext: Uint8Array,
100
+ key: Uint8Array,
101
+ nonce: Uint8Array,
102
+ algo: keyof typeof CRYPTO_FUNCTIONS = CRYPTO_DEFAULTS.symmetric_alg,
103
+ ): Uint8Array {
104
+ return CRYPTO_FUNCTIONS[algo].decrypt(ciphertext, nonce, key);
105
+ }
106
+
107
+ /**
108
+ * Derive secret key from password with key derivation function.
109
+ * @param password - User-supplied password.
110
+ * @param nonce - Randomly generated nonce.
111
+ * @param kdf - Key derivation function.
112
+ * @param kdfParams - KDF parameters.
113
+ * @returns Secret key derived from password.
114
+ */
115
+ async function deriveKey(
116
+ password: string | Uint8Array,
117
+ nonce: string | Uint8Array,
118
+ kdf: Keystore['crypto']['kdf'],
119
+ kdfParams: Omit<Keystore['crypto']['kdf_params'], 'salt'>,
120
+ ): Promise<Uint8Array> {
121
+ return DERIVED_KEY_FUNCTIONS[kdf](password, nonce, kdfParams);
122
+ }
123
+
124
+ /**
125
+ * Recover plaintext private key from secret-storage key object.
126
+ * @param password - Keystore object password.
127
+ * @param keystore - Keystore object.
128
+ * @returns Plaintext private key.
129
+ */
130
+ export async function recover(
131
+ password: string | Uint8Array,
132
+ { crypto }: Keystore,
133
+ ): Promise<string> {
134
+ const salt = hexToBytes(crypto.kdf_params.salt);
135
+ return bytesToHex(decrypt(
136
+ hexToBytes(crypto.ciphertext),
137
+ await deriveKey(password, salt, crypto.kdf, crypto.kdf_params),
138
+ hexToBytes(crypto.cipher_params.nonce),
139
+ crypto.symmetric_alg,
140
+ ));
141
+ }
142
+
143
+ /**
144
+ * Export private key to keystore secret-storage format.
145
+ * @param name - Key name.
146
+ * @param password - User-supplied password.
147
+ * @param privateKey - Private key as hex-string or a Buffer.
148
+ * @param nonce - Randomly generated 24byte nonce.
149
+ * @param salt - Randomly generated 16byte salt.
150
+ * @param options - Encryption parameters.
151
+ * @param options.kdf - Key derivation function.
152
+ * @param options.kdf_params - KDF parameters.
153
+ */
154
+ export async function dump(
155
+ name: string,
156
+ password: string | Uint8Array,
157
+ privateKey: string | Uint8Array,
158
+ nonce: Uint8Array = nacl.randomBytes(24),
159
+ salt: Uint8Array = nacl.randomBytes(16),
160
+ options?: Partial<Keystore['crypto']>,
161
+ ): Promise<Keystore> {
162
+ const opt = { ...CRYPTO_DEFAULTS, ...options };
163
+ const derivedKey = await deriveKey(password, salt, opt.kdf, opt.kdf_params);
164
+ const payload = typeof privateKey === 'string' ? hexToBytes(privateKey) : privateKey;
165
+ return {
166
+ name,
167
+ version: 1,
168
+ public_key: getAddressFromPriv(payload),
169
+ id: uuid(),
170
+ crypto: {
171
+ secret_type: opt.secret_type,
172
+ symmetric_alg: opt.symmetric_alg,
173
+ ciphertext: bytesToHex(encrypt(payload, derivedKey, nonce, opt.symmetric_alg)),
174
+ cipher_params: { nonce: bytesToHex(nonce) },
175
+ kdf: opt.kdf,
176
+ kdf_params: {
177
+ ...opt.kdf_params,
178
+ salt: bytesToHex(salt),
179
+ },
180
+ },
181
+ };
182
+ }
@@ -15,127 +15,130 @@
15
15
  * PERFORMANCE OF THIS SOFTWARE.
16
16
  */
17
17
 
18
- import { encode as rlpEncode } from 'rlp'
19
- import type { Input } from 'rlp'
20
- import { hash } from './crypto-ts'
18
+ /* eslint-disable default-case */
19
+ import { encode as rlpEncode } from 'rlp';
20
+ import type { Input } from 'rlp';
21
+ import { hash } from './crypto';
21
22
  import {
22
23
  MerkleTreeHashMismatchError,
23
24
  MissingNodeInTreeError,
24
25
  UnknownPathNibbleError,
25
- UnknownNodeLengthError
26
- } from './errors'
26
+ UnknownNodeLengthError,
27
+ } from './errors';
27
28
 
28
29
  enum NodeType {
29
30
  Branch,
30
31
  Extension,
31
- Leaf
32
+ Leaf,
32
33
  }
33
34
 
34
- export type MPTreeBinary = [Buffer, Array<[Buffer, Buffer[]]>]
35
+ export type MPTreeBinary = [Buffer, Array<[Buffer, Buffer[]]>];
35
36
 
36
37
  export default class MPTree {
37
- private readonly rootHash: string
38
- private readonly nodes: { [key: string]: Buffer[] }
38
+ private readonly rootHash: string;
39
39
 
40
- private static nodeHash (node: Input): string {
41
- return Buffer.from(hash(rlpEncode(node))).toString('hex')
40
+ private readonly nodes: { [key: string]: Buffer[] };
41
+
42
+ private static nodeHash(node: Input): string {
43
+ return Buffer.from(hash(rlpEncode(node))).toString('hex');
42
44
  }
43
45
 
44
46
  /**
45
47
  * Deserialize Merkle Patricia Tree
46
- * @rtype (binary: Array) => MPTree
47
- * @param {Array} binary - Binary
48
- * @return {MPTree} Merkle Patricia Tree
48
+ * @param binary - Binary
49
+ * @returns Merkle Patricia Tree
49
50
  */
50
- constructor (binary: MPTreeBinary) {
51
- this.rootHash = binary[0].toString('hex')
51
+ constructor(binary: MPTreeBinary) {
52
+ this.rootHash = binary[0].toString('hex');
52
53
  this.nodes = Object.fromEntries(
53
- binary[1].map((node) => [node[0].toString('hex'), node[1]])
54
- )
54
+ binary[1].map((node) => [node[0].toString('hex'), node[1]]),
55
+ );
55
56
 
56
- if (this.nodes[this.rootHash] === undefined) throw new MissingNodeInTreeError('Can\'t find a node by root hash')
57
+ if (this.nodes[this.rootHash] === undefined) throw new MissingNodeInTreeError('Can\'t find a node by root hash');
57
58
  Object.entries(this.nodes).forEach(([key, node]) => {
58
- if (MPTree.nodeHash(node) !== key) throw new MerkleTreeHashMismatchError()
59
- const { type, payload } = MPTree.parseNode(node)
59
+ if (MPTree.nodeHash(node) !== key) throw new MerkleTreeHashMismatchError();
60
+ const { type, payload } = MPTree.parseNode(node);
60
61
  switch (type) {
61
62
  case NodeType.Branch:
62
63
  payload
63
64
  .slice(0, 16)
64
- .filter(n => n.length)
65
+ .filter((n) => n.length)
65
66
  .forEach((n) => {
66
67
  if (this.nodes[n.toString('hex')] === undefined) {
67
- throw new MissingNodeInTreeError('Can\'t find a node by hash in branch node')
68
+ throw new MissingNodeInTreeError('Can\'t find a node by hash in branch node');
68
69
  }
69
- })
70
- break
70
+ });
71
+ break;
71
72
  case NodeType.Extension:
72
73
  if (this.nodes[payload[0].toString('hex')] === undefined) {
73
- throw new MissingNodeInTreeError('Can\'t find a node by hash in extension node')
74
+ throw new MissingNodeInTreeError('Can\'t find a node by hash in extension node');
74
75
  }
75
76
  }
76
- })
77
+ });
77
78
  }
78
79
 
79
- isEqual (tree: MPTree): boolean {
80
- return this.rootHash === tree.rootHash
80
+ isEqual(tree: MPTree): boolean {
81
+ return this.rootHash === tree.rootHash;
81
82
  }
82
83
 
83
- private static parseNode (node: Buffer[]): { type: NodeType, payload: Buffer[], path: string | null } {
84
+ private static parseNode(node: Buffer[]): {
85
+ type: NodeType;
86
+ payload: Buffer[];
87
+ path: string | null;
88
+ } {
84
89
  switch (node.length) {
85
90
  case 17:
86
- return { type: NodeType.Branch, payload: node, path: null }
91
+ return { type: NodeType.Branch, payload: node, path: null };
87
92
  case 2: {
88
- const path = node[0].toString('hex')
89
- const nibble = parseInt(path[0], 16)
90
- if (nibble > 3) throw new UnknownPathNibbleError(nibble)
91
- const type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf
92
- const slice = [0, 2].includes(nibble) ? 2 : 1
93
- return { type, payload: [node[1]], path: path.slice(slice) }
93
+ const nibble = node[0][0] >> 4; // eslint-disable-line no-bitwise
94
+ if (nibble > 3) throw new UnknownPathNibbleError(nibble);
95
+ const type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf;
96
+ const slice = [0, 2].includes(nibble) ? 2 : 1;
97
+ return { type, payload: [node[1]], path: node[0].toString('hex').slice(slice) };
94
98
  }
95
99
  default:
96
- throw new UnknownNodeLengthError(node.length)
100
+ throw new UnknownNodeLengthError(node.length);
97
101
  }
98
102
  }
99
103
 
100
104
  /**
101
105
  * Serialize Merkle Patricia Tree
102
- * @rtype () => Array
103
- * @return {Array} Binary
106
+ * @returns Binary
104
107
  */
105
- serialize (): MPTreeBinary {
108
+ serialize(): MPTreeBinary {
106
109
  return [
107
110
  Buffer.from(this.rootHash, 'hex'),
108
111
  Object.entries(this.nodes).map(([mptHash, value]) => ([
109
112
  Buffer.from(mptHash, 'hex'),
110
- value
111
- ]))
112
- ]
113
+ value,
114
+ ])),
115
+ ];
113
116
  }
114
117
 
115
118
  /**
116
119
  * Retrieve value from Merkle Patricia Tree
117
- * @rtype (key: String) => Buffer
118
- * @param {String} key - The key of the element to retrieve
119
- * @return {Buffer} Value associated to the specified key
120
+ * @param _key - The key of the element to retrieve
121
+ * @returns Value associated to the specified key
120
122
  */
121
- get (key: string): Buffer | undefined {
122
- let searchFrom = this.rootHash
123
- while (true) {
124
- const { type, payload, path } = MPTree.parseNode(this.nodes[searchFrom])
123
+ get(_key: string): Buffer | undefined {
124
+ let searchFrom = this.rootHash;
125
+ let key = _key;
126
+ while (true) { // eslint-disable-line no-constant-condition
127
+ const { type, payload, path } = MPTree.parseNode(this.nodes[searchFrom]);
125
128
  switch (type) {
126
129
  case NodeType.Branch:
127
- if (key.length === 0) return payload[16]
128
- searchFrom = payload[parseInt(key[0], 16)].toString('hex')
129
- key = key.substr(1)
130
- break
130
+ if (key.length === 0) return payload[16];
131
+ searchFrom = payload[+`0x${key[0]}`].toString('hex');
132
+ key = key.substring(1);
133
+ break;
131
134
  case NodeType.Extension:
132
- if (key.substr(0, path?.length) !== path) return undefined
133
- searchFrom = payload[0].toString('hex')
134
- key = key.substr(path.length)
135
- break
135
+ if (key.substring(0, path?.length) !== path) return undefined;
136
+ searchFrom = payload[0].toString('hex');
137
+ key = key.substring(path.length);
138
+ break;
136
139
  case NodeType.Leaf:
137
- if (path !== key) return undefined
138
- return payload[0]
140
+ if (path !== key) return undefined;
141
+ return payload[0];
139
142
  }
140
143
  }
141
144
  }
@@ -1,51 +1,44 @@
1
- import { snakeToPascal, pascalToSnake } from './string'
1
+ export const pause = async (duration: number): Promise<void> => new Promise((resolve) => {
2
+ setTimeout(resolve, duration);
3
+ });
2
4
 
3
- export const pause = async (duration: number): Promise<void> =>
4
- await new Promise(resolve => setTimeout(resolve, duration))
5
+ export const mapObject = <InputV, OutputV>(
6
+ object: { [k: string]: InputV },
7
+ fn: (
8
+ value: [string, InputV], index: number, array: Array<[string, InputV]>
9
+ ) => [number | string, OutputV],
10
+ ): { [k: string]: OutputV } => Object.fromEntries(Object.entries(object).map(fn));
5
11
 
6
- export const mapObject = (
7
- object: object,
8
- fn: (value: [string, any], index: number, array: Array<[string, any]>) => Array<[string, any]>
9
- ): object => Object.fromEntries(Object.entries(object).map(fn))
12
+ // remove after dropping webpack4 support
13
+ const isWebpack4Buffer = (() => {
14
+ try {
15
+ Buffer.concat([Uint8Array.from([])]);
16
+ return false;
17
+ } catch (error) {
18
+ return true;
19
+ }
20
+ })();
10
21
 
11
- export const filterObject = (
12
- object: object,
13
- fn: (value: [string, any], index: number, array: Array<[string, any]>) => boolean
14
- ): object => Object.fromEntries(Object.entries(object).filter(fn))
22
+ export const concatBuffers = isWebpack4Buffer
23
+ ? (list: readonly Uint8Array[], totalLength?: number): Buffer => (
24
+ Buffer.concat(list.map((el) => Buffer.from(el)), totalLength)
25
+ )
26
+ : Buffer.concat;
15
27
 
16
28
  /**
17
- * Key traversal metafunction
18
- * @static
19
- * @function
20
- * @rtype (fn: (s: String) => String) => (o: Object) => Object
21
- * @param {Function} fn - Key transformation function
22
- * @param {Object} object - Object to traverse
23
- * @return {Object} Transformed object
29
+ * Object key type guard
30
+ * @param key - Maybe object key
31
+ * @param object - Object
24
32
  */
25
- export const traverseKeys = (fn: Function, object: any): any => {
26
- if (typeof object !== 'object' || object === null) return object
27
- if (Array.isArray(object)) return object.map(i => traverseKeys(fn, i))
28
- return mapObject(object, ([key, value]: [string, any]) => [
29
- fn(key), traverseKeys(fn, value)
30
- ])
33
+ export function isKeyOfObject<T>(key: string | number | symbol, object: T): key is keyof T {
34
+ return key in object;
31
35
  }
32
36
 
33
37
  /**
34
- * snake_case key traversal
35
- * @static
36
- * @rtype (o: Object) => Object
37
- * @param {Object} object - Object to traverse
38
- * @return {Object} Transformed object
39
- * @see pascalToSnake
38
+ * Array item type guard
39
+ * @param item - Maybe array item
40
+ * @param array - Array
40
41
  */
41
- export const snakizeKeys = traverseKeys.bind(null, pascalToSnake)
42
-
43
- /**
44
- * PascalCase key traversal
45
- * @static
46
- * @rtype (o: Object) => Object
47
- * @param {Object} object - Object to traverse
48
- * @return {Object} Transformed object
49
- * @see snakeToPascal
50
- */
51
- export const pascalizeKeys = traverseKeys.bind(null, snakeToPascal)
42
+ export function isItemOfArray<T>(item: any, array: readonly T[]): item is T {
43
+ return array.includes(item);
44
+ }