@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
@@ -19,78 +19,61 @@ const {
19
19
  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
20
  * PERFORMANCE OF THIS SOFTWARE.
21
21
  */
22
+ import nacl from 'tweetnacl'; // js extension is required for mjs build, not importing the whole package to reduce bundle size
23
+ // eslint-disable-next-line import/extensions
22
24
 
23
- /**
24
- * Crypto module
25
- * @module @aeternity/aepp-sdk/es/utils/crypto
26
- * @example import { Crypto } from '@aeternity/aepp-sdk'
27
- */
28
- import nacl from 'tweetnacl';
29
- import aesjs from 'aes-js';
30
- import shajs from 'sha.js';
25
+ import _blakejsBlake2bJs from 'blakejs/blake2b.js';
26
+ const {
27
+ blake2b
28
+ } = _blakejsBlake2bJs;
29
+ import _varuintBitcoin from 'varuint-bitcoin';
30
+ const {
31
+ encode: varuintEncode
32
+ } = _varuintBitcoin;
31
33
  import { str2buf } from "./bytes.mjs";
32
- import { encode, decode } from "../tx/builder/helpers.mjs";
33
- import { hash } from "./crypto-ts.mjs";
34
- import { NotImplementedError } from "./errors.mjs";
35
- export * from "./crypto-ts.mjs";
36
- const Ecb = aesjs.ModeOfOperation.ecb;
34
+ import { concatBuffers } from "./other.mjs";
35
+ import { decode, encode, Encoding } from "./encoder.mjs";
37
36
  /**
38
37
  * Generate address from secret key
39
- * @rtype (secret: String) => tx: Promise[String]
40
- * @param {String} secret - Private key
41
- * @return {String} Public key
38
+ * @param secret - Private key
39
+ * @returns Public key encoded as address
42
40
  */
43
41
 
44
42
  export function getAddressFromPriv(secret) {
45
- const keys = nacl.sign.keyPair.fromSecretKey(str2buf(secret));
46
-
47
- const publicBuffer = _Buffer.from(keys.publicKey);
48
-
49
- return encode(publicBuffer, 'ak');
43
+ const secretBuffer = typeof secret === 'string' ? str2buf(secret) : secret;
44
+ const keys = nacl.sign.keyPair.fromSecretKey(secretBuffer);
45
+ return encode(keys.publicKey, Encoding.AccountAddress);
50
46
  }
51
47
  /**
52
48
  * Check if address is valid
53
- * @rtype (input: String) => valid: Boolean
54
- * @param {String} address - Address
55
- * @param {String} prefix Transaction prefix. Default: 'ak'
56
- * @return {Boolean} valid
49
+ * @param address - Address
50
+ * @param prefix - Transaction prefix. Default: 'ak'
51
+ * @returns is valid
57
52
  */
58
53
 
59
54
  export function isAddressValid(address) {
60
- let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'ak';
55
+ let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Encoding.AccountAddress;
61
56
 
62
57
  try {
63
- decode(address, prefix);
58
+ decode(address);
64
59
  return true;
65
60
  } catch (e) {
66
61
  return false;
67
62
  }
68
63
  }
69
- /**
70
- * Calculate SHA256 hash of `input`
71
- * @rtype (input: String) => hash: String
72
- * @param {String} input - Data to hash
73
- * @return {String} Hash
74
- */
75
-
76
- export function sha256hash(input) {
77
- return shajs('sha256').update(input).digest();
78
- }
79
64
  /**
80
65
  * Generate a random salt (positive integer)
81
- * @rtype () => salt: Number
82
- * @return {Number} random salt
66
+ * @returns random salt
83
67
  */
84
68
 
85
- export function salt() {
69
+ export function genSalt() {
86
70
  return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER));
87
71
  }
88
72
  /**
89
73
  * Converts a positive integer to the smallest possible
90
74
  * representation in a binary digit representation
91
- * @rtype (value: Number) => Buffer
92
- * @param {Number} value - Value to encode
93
- * @return {Buffer} - Encoded data
75
+ * @param value - Value to encode
76
+ * @returns Encoded number
94
77
  */
95
78
 
96
79
  export function encodeUnsigned(value) {
@@ -98,29 +81,35 @@ export function encodeUnsigned(value) {
98
81
 
99
82
  binary.writeUInt32BE(value);
100
83
  return binary.slice(binary.findIndex(i => i !== 0));
84
+ }
85
+ /**
86
+ * Calculate 256bits Blake2b hash of `input`
87
+ * @param input - Data to hash
88
+ * @returns Hash
89
+ */
90
+
91
+ export function hash(input) {
92
+ return _Buffer.from(blake2b(input, undefined, 32)); // 256 bits
101
93
  } // Todo Duplicated in tx builder. remove
102
94
 
103
95
  /**
104
96
  * Compute contract address
105
- * @rtype (owner: String, nonce: Number) => String
106
- * @param {String} owner - Address of contract owner
107
- * @param {Number} nonce - Round when contract was created
108
- * @return {String} - Contract address
97
+ * @category contract
98
+ * @param owner - Address of contract owner
99
+ * @param nonce - Round when contract was created
100
+ * @returns Contract address
109
101
  */
110
102
 
111
103
  export function encodeContractAddress(owner, nonce) {
112
- const publicKey = decode(owner, 'ak');
113
-
114
- const binary = _Buffer.concat([publicKey, encodeUnsigned(nonce)]);
115
-
116
- return encode(hash(binary), 'ct');
104
+ const publicKey = decode(owner);
105
+ const binary = concatBuffers([publicKey, encodeUnsigned(nonce)]);
106
+ return encode(hash(binary), Encoding.ContractAddress);
117
107
  } // KEY-PAIR HELPERS
118
108
 
119
109
  /**
120
110
  * Generate keyPair from secret key
121
- * @rtype (secret: Uint8Array) => KeyPair
122
- * @param {Uint8Array} secret - secret key
123
- * @return {Object} - Object with Private(privateKey) and Public(publicKey) keys
111
+ * @param secret - secret key
112
+ * @returns Object with Private(privateKey) and Public(publicKey) keys
124
113
  */
125
114
 
126
115
  export function generateKeyPairFromSecret(secret) {
@@ -128,14 +117,12 @@ export function generateKeyPairFromSecret(secret) {
128
117
  }
129
118
  /**
130
119
  * Generate a random ED25519 keypair
131
- * @rtype (raw: Boolean) => {publicKey: String | Buffer, secretKey: String | Buffer}
132
- * @param {Boolean} raw - Whether to return raw (binary) keys
133
- * @return {Object} Key pair
120
+ * @param raw - Whether to return raw (binary) keys
121
+ * @returns Key pair
134
122
  */
135
123
 
136
124
  export function generateKeyPair() {
137
125
  let raw = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
138
- // <node>/apps/aens/test/aens_test_utils.erl
139
126
  const keyPair = nacl.sign.keyPair();
140
127
 
141
128
  const publicBuffer = _Buffer.from(keyPair.publicKey);
@@ -147,48 +134,19 @@ export function generateKeyPair() {
147
134
  publicKey: publicBuffer,
148
135
  secretKey: secretBuffer
149
136
  };
150
- } else {
151
- return {
152
- publicKey: encode(publicBuffer, 'ak'),
153
- secretKey: secretBuffer.toString('hex')
154
- };
155
137
  }
156
- }
157
- /**
158
- * Encrypt given data using `password`
159
- * @rtype (password: String, binaryData: Buffer) => Uint8Array
160
- * @param {String} password - Password to encrypt with
161
- * @param {Buffer} binaryData - Data to encrypt
162
- * @return {Uint8Array} Encrypted data
163
- */
164
-
165
- export function encryptKey(password, binaryData) {
166
- const hashedPasswordBytes = sha256hash(password);
167
- const aesEcb = new Ecb(hashedPasswordBytes);
168
- return aesEcb.encrypt(binaryData);
169
- }
170
- /**
171
- * Decrypt given data using `password`
172
- * @rtype (password: String, encrypted: String) => Uint8Array
173
- * @param {String} password - Password to decrypt with
174
- * @param {String} encrypted - Data to decrypt
175
- * @return {Buffer} Decrypted data
176
- */
177
-
178
- export function decryptKey(password, encrypted) {
179
- const encryptedBytes = _Buffer.from(encrypted);
180
138
 
181
- const hashedPasswordBytes = sha256hash(password);
182
- const aesEcb = new Ecb(hashedPasswordBytes);
183
- return _Buffer.from(aesEcb.decrypt(encryptedBytes));
139
+ return {
140
+ publicKey: encode(publicBuffer, Encoding.AccountAddress),
141
+ secretKey: secretBuffer.toString('hex')
142
+ };
184
143
  } // SIGNATURES
185
144
 
186
145
  /**
187
146
  * Generate signature
188
- * @rtype (data: String|Buffer, privateKey: Buffer) => Buffer
189
- * @param {String|Buffer} data - Data to sign
190
- * @param {String|Buffer} privateKey - Key to sign with
191
- * @return {Buffer|Uint8Array} Signature
147
+ * @param data - Data to sign
148
+ * @param privateKey - Key to sign with
149
+ * @returns Signature
192
150
  */
193
151
 
194
152
  export function sign(data, privateKey) {
@@ -196,23 +154,22 @@ export function sign(data, privateKey) {
196
154
  }
197
155
  /**
198
156
  * Verify that signature was signed by public key
199
- * @rtype (str: String, signature: Buffer, publicKey: Buffer) => Boolean
200
- * @param {String|Buffer} str - Data to verify
201
- * @param {Buffer} signature - Signature to verify
202
- * @param {Buffer} publicKey - Key to verify against
203
- * @return {Boolean} Valid?
157
+ * @param data - Data to verify
158
+ * @param signature - Signature to verify
159
+ * @param publicKey - Key to verify against
160
+ * @returns Valid?
204
161
  */
205
162
 
206
- export function verify(str, signature, publicKey) {
207
- return nacl.sign.detached.verify(new Uint8Array(str), signature, publicKey);
163
+ export function verify(data, signature, publicKey) {
164
+ const publicKeyBuffer = typeof publicKey === 'string' ? str2buf(publicKey) : publicKey;
165
+ return nacl.sign.detached.verify(data, signature, publicKeyBuffer);
208
166
  }
209
167
  export function messageToHash(message) {
210
168
  const p = _Buffer.from('aeternity Signed Message:\n', 'utf8');
211
169
 
212
170
  const msg = _Buffer.from(message, 'utf8');
213
171
 
214
- if (msg.length >= 0xFD) throw new NotImplementedError('Message too long');
215
- return hash(_Buffer.concat([_Buffer.from([p.length]), p, _Buffer.from([msg.length]), msg]));
172
+ return hash(concatBuffers([varuintEncode(p.length), p, varuintEncode(msg.length), msg]));
216
173
  }
217
174
  export function signMessage(message, privateKey) {
218
175
  return sign(messageToHash(message), privateKey);
@@ -224,10 +181,9 @@ export function verifyMessage(str, signature, publicKey) {
224
181
  * Check key pair for validity
225
182
  *
226
183
  * Sign a message, and then verifying that signature
227
- * @rtype (privateKey: Buffer, publicKey: Buffer) => Boolean
228
- * @param {Buffer} privateKey - Private key to verify
229
- * @param {Buffer} publicKey - Public key to verify
230
- * @return {Boolean} Valid?
184
+ * @param privateKey - Private key to verify
185
+ * @param publicKey - Public key to verify
186
+ * @returns Valid?
231
187
  */
232
188
 
233
189
  export function isValidKeypair(privateKey, publicKey) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/crypto.js"],"names":["nacl","aesjs","shajs","str2buf","encode","decode","hash","NotImplementedError","Ecb","ModeOfOperation","ecb","getAddressFromPriv","secret","keys","sign","keyPair","fromSecretKey","publicBuffer","from","publicKey","isAddressValid","address","prefix","e","sha256hash","input","update","digest","salt","Math","floor","random","Number","MAX_SAFE_INTEGER","encodeUnsigned","value","binary","allocUnsafe","writeUInt32BE","slice","findIndex","i","encodeContractAddress","owner","nonce","concat","generateKeyPairFromSecret","generateKeyPair","raw","secretBuffer","secretKey","toString","encryptKey","password","binaryData","hashedPasswordBytes","aesEcb","encrypt","decryptKey","encrypted","encryptedBytes","decrypt","data","privateKey","detached","verify","str","signature","Uint8Array","messageToHash","message","p","msg","length","signMessage","verifyMessage","isValidKeypair"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AAEA,OAAOA,IAAP,MAAiB,WAAjB;AACA,OAAOC,KAAP,MAAkB,QAAlB;AACA,OAAOC,KAAP,MAAkB,QAAlB;SAESC,O;SACAC,M,EAAQC,M;SACRC,I;SACAC,mB;;AAIT,MAAMC,GAAG,GAAGP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CAAYoD,OAAZ,EAAqB,MAArB,CAAZ;;AACA,MAAIE,GAAG,CAACC,MAAJ,IAAc,IAAlB,EAAwB,MAAM,IAAIlE,mBAAJ,CAAwB,kBAAxB,CAAN;AACxB,SAAOD,IAAI,CAAC,QAAOuC,MAAP,CAAc,CAAC,QAAO3B,IAAP,CAAY,CAACqD,CAAC,CAACE,MAAH,CAAZ,CAAD,EAA0BF,CAA1B,EAA6B,QAAOrD,IAAP,CAAY,CAACsD,GAAG,CAACC,MAAL,CAAZ,CAA7B,EAAwDD,GAAxD,CAAd,CAAD,CAAX;AACD;AAED,OAAO,SAASE,WAAT,CAAsBJ,OAAtB,EAA+BP,UAA/B,EAA2C;AAChD,SAAOjD,IAAI,CAACuD,aAAa,CAACC,OAAD,CAAd,EAAyBP,UAAzB,CAAX;AACD;AAED,OAAO,SAASY,aAAT,CAAwBT,GAAxB,EAA6BC,SAA7B,EAAwChD,SAAxC,EAAmD;AACxD,SAAO8C,MAAM,CAACI,aAAa,CAACH,GAAD,CAAd,EAAqBC,SAArB,EAAgChD,SAAhC,CAAb;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASyD,cAAT,CAAyBb,UAAzB,EAAqC5C,SAArC,EAAgD;AACrD,QAAMmD,OAAO,GAAG,QAAOpD,IAAP,CAAY,YAAZ,CAAhB;;AACA,QAAMiD,SAAS,GAAGrD,IAAI,CAACwD,OAAD,EAAUP,UAAV,CAAtB;AACA,SAAOE,MAAM,CAACK,OAAD,EAAUH,SAAV,EAAqBhD,SAArB,CAAb;AACD","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Crypto module\n * @module @aeternity/aepp-sdk/es/utils/crypto\n * @example import { Crypto } from '@aeternity/aepp-sdk'\n */\n\nimport nacl from 'tweetnacl'\nimport aesjs from 'aes-js'\nimport shajs from 'sha.js'\n\nimport { str2buf } from './bytes'\nimport { encode, decode } from '../tx/builder/helpers'\nimport { hash } from './crypto-ts'\nimport { NotImplementedError } from './errors'\n\nexport * from './crypto-ts'\n\nconst Ecb = aesjs.ModeOfOperation.ecb\n\n/**\n * Generate address from secret key\n * @rtype (secret: String) => tx: Promise[String]\n * @param {String} secret - Private key\n * @return {String} Public key\n */\nexport function getAddressFromPriv (secret) {\n const keys = nacl.sign.keyPair.fromSecretKey(str2buf(secret))\n const publicBuffer = Buffer.from(keys.publicKey)\n return encode(publicBuffer, 'ak')\n}\n\n/**\n * Check if address is valid\n * @rtype (input: String) => valid: Boolean\n * @param {String} address - Address\n * @param {String} prefix Transaction prefix. Default: 'ak'\n * @return {Boolean} valid\n */\nexport function isAddressValid (address, prefix = 'ak') {\n try {\n decode(address, prefix)\n return true\n } catch (e) {\n return false\n }\n}\n\n/**\n * Calculate SHA256 hash of `input`\n * @rtype (input: String) => hash: String\n * @param {String} input - Data to hash\n * @return {String} Hash\n */\nexport function sha256hash (input) {\n return shajs('sha256').update(input).digest()\n}\n\n/**\n * Generate a random salt (positive integer)\n * @rtype () => salt: Number\n * @return {Number} random salt\n */\nexport function salt () {\n return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER))\n}\n\n/**\n * Converts a positive integer to the smallest possible\n * representation in a binary digit representation\n * @rtype (value: Number) => Buffer\n * @param {Number} value - Value to encode\n * @return {Buffer} - Encoded data\n */\nexport function encodeUnsigned (value) {\n const binary = Buffer.allocUnsafe(4)\n binary.writeUInt32BE(value)\n return binary.slice(binary.findIndex(i => i !== 0))\n}\n\n// Todo Duplicated in tx builder. remove\n/**\n * Compute contract address\n * @rtype (owner: String, nonce: Number) => String\n * @param {String} owner - Address of contract owner\n * @param {Number} nonce - Round when contract was created\n * @return {String} - Contract address\n */\nexport function encodeContractAddress (owner, nonce) {\n const publicKey = decode(owner, 'ak')\n const binary = Buffer.concat([publicKey, encodeUnsigned(nonce)])\n return encode(hash(binary), 'ct')\n}\n\n// KEY-PAIR HELPERS\n\n/**\n * Generate keyPair from secret key\n * @rtype (secret: Uint8Array) => KeyPair\n * @param {Uint8Array} secret - secret key\n * @return {Object} - Object with Private(privateKey) and Public(publicKey) keys\n */\nexport function generateKeyPairFromSecret (secret) {\n return nacl.sign.keyPair.fromSecretKey(secret)\n}\n\n/**\n * Generate a random ED25519 keypair\n * @rtype (raw: Boolean) => {publicKey: String | Buffer, secretKey: String | Buffer}\n * @param {Boolean} raw - Whether to return raw (binary) keys\n * @return {Object} Key pair\n */\nexport function generateKeyPair (raw = false) {\n // <node>/apps/aens/test/aens_test_utils.erl\n const keyPair = nacl.sign.keyPair()\n\n const publicBuffer = Buffer.from(keyPair.publicKey)\n const secretBuffer = Buffer.from(keyPair.secretKey)\n\n if (raw) {\n return {\n publicKey: publicBuffer,\n secretKey: secretBuffer\n }\n } else {\n return {\n publicKey: encode(publicBuffer, 'ak'),\n secretKey: secretBuffer.toString('hex')\n }\n }\n}\n\n/**\n * Encrypt given data using `password`\n * @rtype (password: String, binaryData: Buffer) => Uint8Array\n * @param {String} password - Password to encrypt with\n * @param {Buffer} binaryData - Data to encrypt\n * @return {Uint8Array} Encrypted data\n */\nexport function encryptKey (password, binaryData) {\n const hashedPasswordBytes = sha256hash(password)\n const aesEcb = new Ecb(hashedPasswordBytes)\n return aesEcb.encrypt(binaryData)\n}\n\n/**\n * Decrypt given data using `password`\n * @rtype (password: String, encrypted: String) => Uint8Array\n * @param {String} password - Password to decrypt with\n * @param {String} encrypted - Data to decrypt\n * @return {Buffer} Decrypted data\n */\nexport function decryptKey (password, encrypted) {\n const encryptedBytes = Buffer.from(encrypted)\n const hashedPasswordBytes = sha256hash(password)\n const aesEcb = new Ecb(hashedPasswordBytes)\n return Buffer.from(aesEcb.decrypt(encryptedBytes))\n}\n\n// SIGNATURES\n\n/**\n * Generate signature\n * @rtype (data: String|Buffer, privateKey: Buffer) => Buffer\n * @param {String|Buffer} data - Data to sign\n * @param {String|Buffer} privateKey - Key to sign with\n * @return {Buffer|Uint8Array} Signature\n */\nexport function sign (data, privateKey) {\n return nacl.sign.detached(Buffer.from(data), Buffer.from(privateKey))\n}\n\n/**\n * Verify that signature was signed by public key\n * @rtype (str: String, signature: Buffer, publicKey: Buffer) => Boolean\n * @param {String|Buffer} str - Data to verify\n * @param {Buffer} signature - Signature to verify\n * @param {Buffer} publicKey - Key to verify against\n * @return {Boolean} Valid?\n */\nexport function verify (str, signature, publicKey) {\n return nacl.sign.detached.verify(new Uint8Array(str), signature, publicKey)\n}\n\nexport function messageToHash (message) {\n const p = Buffer.from('aeternity Signed Message:\\n', 'utf8')\n const msg = Buffer.from(message, 'utf8')\n if (msg.length >= 0xFD) throw new NotImplementedError('Message too long')\n return hash(Buffer.concat([Buffer.from([p.length]), p, Buffer.from([msg.length]), msg]))\n}\n\nexport function signMessage (message, privateKey) {\n return sign(messageToHash(message), privateKey)\n}\n\nexport function verifyMessage (str, signature, publicKey) {\n return verify(messageToHash(str), signature, publicKey)\n}\n\n/**\n * Check key pair for validity\n *\n * Sign a message, and then verifying that signature\n * @rtype (privateKey: Buffer, publicKey: Buffer) => Boolean\n * @param {Buffer} privateKey - Private key to verify\n * @param {Buffer} publicKey - Public key to verify\n * @return {Boolean} Valid?\n */\nexport function isValidKeypair (privateKey, publicKey) {\n const message = Buffer.from('TheMessage')\n const signature = sign(message, privateKey)\n return verify(message, signature, publicKey)\n}\n"],"file":"crypto.mjs"}
1
+ {"version":3,"file":"crypto.mjs","names":["nacl","str2buf","concatBuffers","decode","encode","Encoding","getAddressFromPriv","secret","secretBuffer","keys","sign","keyPair","fromSecretKey","publicKey","AccountAddress","isAddressValid","address","prefix","e","genSalt","Math","floor","random","Number","MAX_SAFE_INTEGER","encodeUnsigned","value","binary","allocUnsafe","writeUInt32BE","slice","findIndex","i","hash","input","from","blake2b","undefined","encodeContractAddress","owner","nonce","ContractAddress","generateKeyPairFromSecret","generateKeyPair","raw","publicBuffer","secretKey","toString","data","privateKey","detached","verify","signature","publicKeyBuffer","messageToHash","message","p","msg","varuintEncode","length","signMessage","verifyMessage","str","isValidKeypair"],"sources":["../../src/utils/crypto.ts"],"sourcesContent":["/*\n * ISC License (ISC)\n * Copyright 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\nimport nacl, { SignKeyPair } from 'tweetnacl';\n// js extension is required for mjs build, not importing the whole package to reduce bundle size\n// eslint-disable-next-line import/extensions\nimport { blake2b } from 'blakejs/blake2b.js';\nimport { encode as varuintEncode } from 'varuint-bitcoin';\n\nimport { str2buf } from './bytes';\nimport { concatBuffers } from './other';\nimport {\n decode, encode, Encoded, Encoding,\n} from './encoder';\n\n/**\n * Generate address from secret key\n * @param secret - Private key\n * @returns Public key encoded as address\n */\nexport function getAddressFromPriv(secret: string | Uint8Array): Encoded.AccountAddress {\n const secretBuffer = typeof secret === 'string' ? str2buf(secret) : secret;\n const keys = nacl.sign.keyPair.fromSecretKey(secretBuffer);\n return encode(keys.publicKey, Encoding.AccountAddress);\n}\n\n/**\n * Check if address is valid\n * @param address - Address\n * @param prefix - Transaction prefix. Default: 'ak'\n * @returns is valid\n */\nexport function isAddressValid(\n address: string,\n prefix: Encoding = Encoding.AccountAddress,\n): boolean {\n try {\n decode(address as Encoded.Generic<typeof prefix>);\n return true;\n } catch (e) {\n return false;\n }\n}\n\n/**\n * Generate a random salt (positive integer)\n * @returns random salt\n */\nexport function genSalt(): number {\n return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER));\n}\n\n/**\n * Converts a positive integer to the smallest possible\n * representation in a binary digit representation\n * @param value - Value to encode\n * @returns Encoded number\n */\nexport function encodeUnsigned(value: number): Buffer {\n const binary = Buffer.allocUnsafe(4);\n binary.writeUInt32BE(value);\n return binary.slice(binary.findIndex((i) => i !== 0));\n}\n\n/**\n * Calculate 256bits Blake2b hash of `input`\n * @param input - Data to hash\n * @returns Hash\n */\nexport function hash(input: string | Uint8Array): Buffer {\n return Buffer.from(blake2b(input, undefined, 32)); // 256 bits\n}\n\n// Todo Duplicated in tx builder. remove\n/**\n * Compute contract address\n * @category contract\n * @param owner - Address of contract owner\n * @param nonce - Round when contract was created\n * @returns Contract address\n */\nexport function encodeContractAddress(\n owner: Encoded.AccountAddress,\n nonce: number,\n): Encoded.ContractAddress {\n const publicKey = decode(owner);\n const binary = concatBuffers([publicKey, encodeUnsigned(nonce)]);\n return encode(hash(binary), Encoding.ContractAddress);\n}\n\n// KEY-PAIR HELPERS\n\n/**\n * Generate keyPair from secret key\n * @param secret - secret key\n * @returns Object with Private(privateKey) and Public(publicKey) keys\n */\nexport function generateKeyPairFromSecret(secret: Uint8Array): SignKeyPair {\n return nacl.sign.keyPair.fromSecretKey(secret);\n}\n\n/**\n * Generate a random ED25519 keypair\n * @param raw - Whether to return raw (binary) keys\n * @returns Key pair\n */\nexport function generateKeyPair(raw: true): { publicKey: Buffer; secretKey: Buffer };\nexport function generateKeyPair(raw?: false): {\n publicKey: Encoded.AccountAddress; secretKey: string;\n};\nexport function generateKeyPair(raw = false): {\n publicKey: Encoded.AccountAddress | Buffer;\n secretKey: string | Buffer;\n} {\n const keyPair = nacl.sign.keyPair();\n const publicBuffer = Buffer.from(keyPair.publicKey);\n const secretBuffer = Buffer.from(keyPair.secretKey);\n\n if (raw) {\n return {\n publicKey: publicBuffer,\n secretKey: secretBuffer,\n };\n }\n return {\n publicKey: encode(publicBuffer, Encoding.AccountAddress),\n secretKey: secretBuffer.toString('hex'),\n };\n}\n\n// SIGNATURES\n\n/**\n * Generate signature\n * @param data - Data to sign\n * @param privateKey - Key to sign with\n * @returns Signature\n */\nexport function sign(data: string | Uint8Array, privateKey: string | Uint8Array): Uint8Array {\n return nacl.sign.detached(Buffer.from(data), Buffer.from(privateKey));\n}\n\n/**\n * Verify that signature was signed by public key\n * @param data - Data to verify\n * @param signature - Signature to verify\n * @param publicKey - Key to verify against\n * @returns Valid?\n */\nexport function verify(\n data: Uint8Array,\n signature: Uint8Array,\n publicKey: string | Uint8Array,\n): boolean {\n const publicKeyBuffer = typeof publicKey === 'string' ? str2buf(publicKey) : publicKey;\n return nacl.sign.detached.verify(data, signature, publicKeyBuffer);\n}\n\nexport function messageToHash(message: string): Buffer {\n const p = Buffer.from('aeternity Signed Message:\\n', 'utf8');\n const msg = Buffer.from(message, 'utf8');\n return hash(concatBuffers([varuintEncode(p.length), p, varuintEncode(msg.length), msg]));\n}\n\nexport function signMessage(message: string, privateKey: string | Buffer): Uint8Array {\n return sign(messageToHash(message), privateKey);\n}\n\nexport function verifyMessage(\n str: string,\n signature: Uint8Array,\n publicKey: string | Uint8Array,\n): boolean {\n return verify(messageToHash(str), signature, publicKey);\n}\n\n/**\n * Check key pair for validity\n *\n * Sign a message, and then verifying that signature\n * @param privateKey - Private key to verify\n * @param publicKey - Public key to verify\n * @returns Valid?\n */\nexport function isValidKeypair(\n privateKey: string | Uint8Array,\n publicKey: string | Uint8Array,\n): boolean {\n const message = Buffer.from('TheMessage');\n const signature = sign(message, privateKey);\n return verify(message, signature, publicKey);\n}\n"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,IAAP,MAAkC,WAAlC,C,CACA;AACA;;AACA,8BAAwB,oBAAxB;;;;AACA,4BAAwC,iBAAxC;;;;SAESC,O;SACAC,a;SAEPC,M,EAAQC,M,EAAiBC,Q;AAG3B;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,kBAAT,CAA4BC,MAA5B,EAAiF;EACtF,MAAMC,YAAY,GAAG,OAAOD,MAAP,KAAkB,QAAlB,GAA6BN,OAAO,CAACM,MAAD,CAApC,GAA+CA,MAApE;EACA,MAAME,IAAI,GAAGT,IAAI,CAACU,IAAL,CAAUC,OAAV,CAAkBC,aAAlB,CAAgCJ,YAAhC,CAAb;EACA,OAAOJ,MAAM,CAACK,IAAI,CAACI,SAAN,EAAiBR,QAAQ,CAACS,cAA1B,CAAb;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,cAAT,CACLC,OADK,EAGI;EAAA,IADTC,MACS,uEADUZ,QAAQ,CAACS,cACnB;;EACT,IAAI;IACFX,MAAM,CAACa,OAAD,CAAN;IACA,OAAO,IAAP;EACD,CAHD,CAGE,OAAOE,CAAP,EAAU;IACV,OAAO,KAAP;EACD;AACF;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASC,OAAT,GAA2B;EAChC,OAAOC,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AAa,CAACF,CAAC,CAACG,MAAH,CAAd,EAA0BH,CAA1B,EAA6BE,aAAa,CAACD,GAAG,CAACE,MAAL,CAA1C,EAAwDF,GAAxD,CAAD,CAAd,CAAX;AACD;AAED,OAAO,SAASG,WAAT,CAAqBL,OAArB,EAAsCN,UAAtC,EAA+E;EACpF,OAAOvC,IAAI,CAAC4C,aAAa,CAACC,OAAD,CAAd,EAAyBN,UAAzB,CAAX;AACD;AAED,OAAO,SAASY,aAAT,CACLC,GADK,EAELV,SAFK,EAGLvC,SAHK,EAII;EACT,OAAOsC,MAAM,CAACG,aAAa,CAACQ,GAAD,CAAd,EAAqBV,SAArB,EAAgCvC,SAAhC,CAAb;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASkD,cAAT,CACLd,UADK,EAELpC,SAFK,EAGI;EACT,MAAM0C,OAAO,GAAG,QAAOpB,IAAP,CAAY,YAAZ,CAAhB;;EACA,MAAMiB,SAAS,GAAG1C,IAAI,CAAC6C,OAAD,EAAUN,UAAV,CAAtB;EACA,OAAOE,MAAM,CAACI,OAAD,EAAUH,SAAV,EAAqBvC,SAArB,CAAb;AACD"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @category transaction builder
3
+ * @see {@link https://github.com/aeternity/protocol/blob/master/node/api/api_encoding.md}
4
+ * @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L205-L230}
5
+ */
6
+ export declare enum Encoding {
7
+ KeyBlockHash = "kh",
8
+ MicroBlockHash = "mh",
9
+ BlockPofHash = "bf",
10
+ BlockTxHash = "bx",
11
+ BlockStateHash = "bs",
12
+ Channel = "ch",
13
+ ContractAddress = "ct",
14
+ ContractBytearray = "cb",
15
+ ContractStoreKey = "ck",
16
+ ContractStoreValue = "cv",
17
+ Transaction = "tx",
18
+ TxHash = "th",
19
+ OracleAddress = "ok",
20
+ OracleQuery = "ov",
21
+ OracleQueryId = "oq",
22
+ OracleResponse = "or",
23
+ AccountAddress = "ak",
24
+ Signature = "sg",
25
+ Commitment = "cm",
26
+ PeerPubkey = "pp",
27
+ Name = "nm",
28
+ State = "st",
29
+ Poi = "pi",
30
+ StateTrees = "ss",
31
+ CallStateTree = "cs",
32
+ Bytearray = "ba"
33
+ }
34
+ export declare type KeyBlockHash = `${Encoding.KeyBlockHash}_${string}`;
35
+ export declare type MicroBlockHash = `${Encoding.MicroBlockHash}_${string}`;
36
+ export declare type BlockPofHash = `${Encoding.BlockPofHash}_${string}`;
37
+ export declare type BlockTxHash = `${Encoding.BlockTxHash}_${string}`;
38
+ export declare type BlockStateHash = `${Encoding.BlockStateHash}_${string}`;
39
+ export declare type Channel = `${Encoding.Channel}_${string}`;
40
+ export declare type ContractAddress = `${Encoding.ContractAddress}_${string}`;
41
+ export declare type ContractBytearray = `${Encoding.ContractBytearray}_${string}`;
42
+ export declare type ContractStoreKey = `${Encoding.ContractStoreKey}_${string}`;
43
+ export declare type ContractStoreValue = `${Encoding.ContractStoreValue}_${string}`;
44
+ export declare type Transaction = `${Encoding.Transaction}_${string}`;
45
+ export declare type TxHash = `${Encoding.TxHash}_${string}`;
46
+ export declare type OracleAddress = `${Encoding.OracleAddress}_${string}`;
47
+ export declare type OracleQuery = `${Encoding.OracleQuery}_${string}`;
48
+ export declare type OracleQueryId = `${Encoding.OracleQueryId}_${string}`;
49
+ export declare type OracleResponse = `${Encoding.OracleResponse}_${string}`;
50
+ export declare type AccountAddress = `${Encoding.AccountAddress}_${string}`;
51
+ export declare type Signature = `${Encoding.Signature}_${string}`;
52
+ export declare type Commitment = `${Encoding.Commitment}_${string}`;
53
+ export declare type PeerPubkey = `${Encoding.PeerPubkey}_${string}`;
54
+ export declare type Name = `${Encoding.Name}_${string}`;
55
+ export declare type State = `${Encoding.State}_${string}`;
56
+ export declare type Poi = `${Encoding.Poi}_${string}`;
57
+ export declare type StateTrees = `${Encoding.StateTrees}_${string}`;
58
+ export declare type CallStateTree = `${Encoding.CallStateTree}_${string}`;
59
+ export declare type Bytearray = `${Encoding.Bytearray}_${string}`;
60
+ export declare type Generic<Type extends Encoding> = `${Type}_${string}`;
61
+ export declare type Any = `${Encoding}_${string}`;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @category transaction builder
3
+ * @see {@link https://github.com/aeternity/protocol/blob/master/node/api/api_encoding.md}
4
+ * @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L205-L230}
5
+ */
6
+ export let Encoding;
7
+
8
+ (function (Encoding) {
9
+ Encoding["KeyBlockHash"] = "kh";
10
+ Encoding["MicroBlockHash"] = "mh";
11
+ Encoding["BlockPofHash"] = "bf";
12
+ Encoding["BlockTxHash"] = "bx";
13
+ Encoding["BlockStateHash"] = "bs";
14
+ Encoding["Channel"] = "ch";
15
+ Encoding["ContractAddress"] = "ct";
16
+ Encoding["ContractBytearray"] = "cb";
17
+ Encoding["ContractStoreKey"] = "ck";
18
+ Encoding["ContractStoreValue"] = "cv";
19
+ Encoding["Transaction"] = "tx";
20
+ Encoding["TxHash"] = "th";
21
+ Encoding["OracleAddress"] = "ok";
22
+ Encoding["OracleQuery"] = "ov";
23
+ Encoding["OracleQueryId"] = "oq";
24
+ Encoding["OracleResponse"] = "or";
25
+ Encoding["AccountAddress"] = "ak";
26
+ Encoding["Signature"] = "sg";
27
+ Encoding["Commitment"] = "cm";
28
+ Encoding["PeerPubkey"] = "pp";
29
+ Encoding["Name"] = "nm";
30
+ Encoding["State"] = "st";
31
+ Encoding["Poi"] = "pi";
32
+ Encoding["StateTrees"] = "ss";
33
+ Encoding["CallStateTree"] = "cs";
34
+ Encoding["Bytearray"] = "ba";
35
+ })(Encoding || (Encoding = {}));
36
+ //# sourceMappingURL=encoder-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoder-types.mjs","names":["Encoding"],"sources":["../../src/utils/encoder-types.ts"],"sourcesContent":["/**\n * @category transaction builder\n * @see {@link https://github.com/aeternity/protocol/blob/master/node/api/api_encoding.md}\n * @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L205-L230}\n */\nexport enum Encoding {\n KeyBlockHash = 'kh',\n MicroBlockHash = 'mh',\n BlockPofHash = 'bf',\n BlockTxHash = 'bx',\n BlockStateHash = 'bs',\n Channel = 'ch',\n ContractAddress = 'ct',\n ContractBytearray = 'cb',\n ContractStoreKey = 'ck',\n ContractStoreValue = 'cv',\n Transaction = 'tx',\n TxHash = 'th',\n OracleAddress = 'ok',\n OracleQuery = 'ov',\n OracleQueryId = 'oq',\n OracleResponse = 'or',\n AccountAddress = 'ak',\n Signature = 'sg',\n Commitment = 'cm',\n PeerPubkey = 'pp',\n Name = 'nm',\n State = 'st',\n Poi = 'pi',\n StateTrees = 'ss',\n CallStateTree = 'cs',\n Bytearray = 'ba',\n}\n\nexport type KeyBlockHash = `${Encoding.KeyBlockHash}_${string}`;\nexport type MicroBlockHash = `${Encoding.MicroBlockHash}_${string}`;\nexport type BlockPofHash = `${Encoding.BlockPofHash}_${string}`;\nexport type BlockTxHash = `${Encoding.BlockTxHash}_${string}`;\nexport type BlockStateHash = `${Encoding.BlockStateHash}_${string}`;\nexport type Channel = `${Encoding.Channel}_${string}`;\nexport type ContractAddress = `${Encoding.ContractAddress}_${string}`;\nexport type ContractBytearray = `${Encoding.ContractBytearray}_${string}`;\nexport type ContractStoreKey = `${Encoding.ContractStoreKey}_${string}`;\nexport type ContractStoreValue = `${Encoding.ContractStoreValue}_${string}`;\nexport type Transaction = `${Encoding.Transaction}_${string}`;\nexport type TxHash = `${Encoding.TxHash}_${string}`;\nexport type OracleAddress = `${Encoding.OracleAddress}_${string}`;\nexport type OracleQuery = `${Encoding.OracleQuery}_${string}`;\nexport type OracleQueryId = `${Encoding.OracleQueryId}_${string}`;\nexport type OracleResponse = `${Encoding.OracleResponse}_${string}`;\nexport type AccountAddress = `${Encoding.AccountAddress}_${string}`;\nexport type Signature = `${Encoding.Signature}_${string}`;\nexport type Commitment = `${Encoding.Commitment}_${string}`;\nexport type PeerPubkey = `${Encoding.PeerPubkey}_${string}`;\nexport type Name = `${Encoding.Name}_${string}`;\nexport type State = `${Encoding.State}_${string}`;\nexport type Poi = `${Encoding.Poi}_${string}`;\nexport type StateTrees = `${Encoding.StateTrees}_${string}`;\nexport type CallStateTree = `${Encoding.CallStateTree}_${string}`;\nexport type Bytearray = `${Encoding.Bytearray}_${string}`;\n\nexport type Generic<Type extends Encoding> = `${Type}_${string}`;\nexport type Any = `${Encoding}_${string}`;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,WAAYA,QAAZ;;WAAYA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;EAAAA,Q;GAAAA,Q,KAAAA,Q"}
@@ -0,0 +1,25 @@
1
+ /// <reference types="node" />
2
+ import * as Encoded from './encoder-types';
3
+ import { Encoding } from './encoder-types';
4
+ export { Encoded, Encoding };
5
+ /**
6
+ * Calculate SHA256 hash of `input`
7
+ * @param input - Data to hash
8
+ * @returns Hash
9
+ * @deprecated use `SubtleCrypto.digest` or `sha.js` package instead
10
+ */
11
+ export declare function sha256hash(input: Uint8Array | string): Buffer;
12
+ /**
13
+ * Decode data using the default encoding/decoding algorithm
14
+ * @param data - An Base58/64check encoded and prefixed string
15
+ * (ex tx_..., sg_..., ak_....)
16
+ * @returns Decoded data
17
+ */
18
+ export declare function decode(data: Encoded.Any): Buffer;
19
+ /**
20
+ * Encode data using the default encoding/decoding algorithm
21
+ * @param data - An decoded data
22
+ * @param type - Prefix of Transaction
23
+ * @returns Encoded string Base58check or Base64check data
24
+ */
25
+ export declare function encode<Type extends Encoding>(data: Uint8Array, type: Type): Encoded.Generic<Type>;
@@ -0,0 +1,118 @@
1
+ import _buffer from "buffer";
2
+ const {
3
+ Buffer: _Buffer
4
+ } = _buffer;
5
+ import _bs from 'bs58'; // js extension is required for mjs build, not importing the whole package to reduce bundle size
6
+ // eslint-disable-next-line import/extensions
7
+
8
+ const {
9
+ encode: bs58Encode,
10
+ decode: bs58Decode
11
+ } = _bs;
12
+ import Sha256 from 'sha.js/sha256.js';
13
+ import { DecodeError, ArgumentError, InvalidChecksumError, PayloadLengthError } from "./errors.mjs";
14
+ import { concatBuffers, isKeyOfObject } from "./other.mjs";
15
+ import * as Encoded from "./encoder-types.mjs";
16
+ import { Encoding } from "./encoder-types.mjs";
17
+ export { Encoded, Encoding };
18
+ /**
19
+ * Calculate SHA256 hash of `input`
20
+ * @param input - Data to hash
21
+ * @returns Hash
22
+ * @deprecated use `SubtleCrypto.digest` or `sha.js` package instead
23
+ */
24
+
25
+ export function sha256hash(input) {
26
+ return new Sha256().update(input).digest();
27
+ }
28
+ /**
29
+ * @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L177-L202}
30
+ */
31
+
32
+ const base64Types = [Encoding.ContractBytearray, Encoding.ContractStoreKey, Encoding.ContractStoreValue, Encoding.Transaction, Encoding.OracleQuery, Encoding.OracleResponse, Encoding.State, Encoding.Poi, Encoding.StateTrees, Encoding.CallStateTree, Encoding.Bytearray];
33
+ const base58Types = [Encoding.KeyBlockHash, Encoding.MicroBlockHash, Encoding.BlockPofHash, Encoding.BlockTxHash, Encoding.BlockStateHash, Encoding.Channel, Encoding.ContractAddress, Encoding.TxHash, Encoding.OracleAddress, Encoding.OracleQueryId, Encoding.AccountAddress, Encoding.Signature, Encoding.Commitment, Encoding.PeerPubkey, Encoding.Name];
34
+ /**
35
+ * @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L261-L286}
36
+ */
37
+
38
+ const byteSizeForType = {
39
+ [Encoding.KeyBlockHash]: 32,
40
+ [Encoding.MicroBlockHash]: 32,
41
+ [Encoding.BlockPofHash]: 32,
42
+ [Encoding.BlockTxHash]: 32,
43
+ [Encoding.BlockStateHash]: 32,
44
+ [Encoding.Channel]: 32,
45
+ [Encoding.ContractAddress]: 32,
46
+ [Encoding.TxHash]: 32,
47
+ [Encoding.OracleAddress]: 32,
48
+ [Encoding.OracleQueryId]: 32,
49
+ [Encoding.AccountAddress]: 32,
50
+ [Encoding.Signature]: 64,
51
+ [Encoding.Commitment]: 32,
52
+ [Encoding.PeerPubkey]: 32,
53
+ [Encoding.State]: 32
54
+ };
55
+
56
+ function ensureValidLength(data, type) {
57
+ if (!isKeyOfObject(type, byteSizeForType)) return;
58
+ const reqLen = byteSizeForType[type];
59
+ if (reqLen == null || data.length === reqLen) return;
60
+ throw new PayloadLengthError(`Payload should be ${reqLen} bytes, got ${data.length} instead`);
61
+ }
62
+
63
+ const getChecksum = payload => sha256hash(sha256hash(payload)).slice(0, 4);
64
+
65
+ const addChecksum = payload => concatBuffers([payload, getChecksum(payload)]);
66
+
67
+ function getPayload(buffer) {
68
+ const payload = buffer.slice(0, -4);
69
+ if (!getChecksum(payload).equals(buffer.slice(-4))) throw new InvalidChecksumError();
70
+ return payload;
71
+ }
72
+
73
+ const base64 = {
74
+ encode: buffer => addChecksum(buffer).toString('base64'),
75
+ decode: string => getPayload(_Buffer.from(string, 'base64'))
76
+ };
77
+ const base58 = {
78
+ encode: buffer => bs58Encode(addChecksum(buffer)),
79
+ decode: string => getPayload(_Buffer.from(bs58Decode(string)))
80
+ };
81
+
82
+ const parseType = maybeType => {
83
+ const base64Type = base64Types.find(t => t === maybeType);
84
+ if (base64Type != null) return [base64Type, base64];
85
+ const base58Type = base58Types.find(t => t === maybeType);
86
+ if (base58Type != null) return [base58Type, base58];
87
+ throw new ArgumentError('prefix', `one of ${[...base58Types, ...base64Types].join(', ')}`, maybeType);
88
+ };
89
+ /**
90
+ * Decode data using the default encoding/decoding algorithm
91
+ * @param data - An Base58/64check encoded and prefixed string
92
+ * (ex tx_..., sg_..., ak_....)
93
+ * @returns Decoded data
94
+ */
95
+
96
+
97
+ export function decode(data) {
98
+ const [prefix, encodedPayload, extra] = data.split('_');
99
+ if (encodedPayload == null) throw new DecodeError(`Encoded string missing payload: ${data}`);
100
+ if (extra != null) throw new DecodeError(`Encoded string have extra parts: ${data}`);
101
+ const [type, encoder] = parseType(prefix);
102
+ const payload = encoder.decode(encodedPayload);
103
+ ensureValidLength(payload, type);
104
+ return payload;
105
+ }
106
+ /**
107
+ * Encode data using the default encoding/decoding algorithm
108
+ * @param data - An decoded data
109
+ * @param type - Prefix of Transaction
110
+ * @returns Encoded string Base58check or Base64check data
111
+ */
112
+
113
+ export function encode(data, type) {
114
+ const [, encoder] = parseType(type);
115
+ ensureValidLength(data, type);
116
+ return `${type}_${encoder.encode(data)}`;
117
+ }
118
+ //# sourceMappingURL=encoder.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoder.mjs","names":["Sha256","DecodeError","ArgumentError","InvalidChecksumError","PayloadLengthError","concatBuffers","isKeyOfObject","Encoded","Encoding","sha256hash","input","update","digest","base64Types","ContractBytearray","ContractStoreKey","ContractStoreValue","Transaction","OracleQuery","OracleResponse","State","Poi","StateTrees","CallStateTree","Bytearray","base58Types","KeyBlockHash","MicroBlockHash","BlockPofHash","BlockTxHash","BlockStateHash","Channel","ContractAddress","TxHash","OracleAddress","OracleQueryId","AccountAddress","Signature","Commitment","PeerPubkey","Name","byteSizeForType","ensureValidLength","data","type","reqLen","length","getChecksum","payload","slice","addChecksum","getPayload","buffer","equals","base64","encode","toString","decode","string","from","base58","bs58Encode","bs58Decode","parseType","maybeType","base64Type","find","t","base58Type","join","prefix","encodedPayload","extra","split","encoder"],"sources":["../../src/utils/encoder.ts"],"sourcesContent":["import { encode as bs58Encode, decode as bs58Decode } from 'bs58';\n// js extension is required for mjs build, not importing the whole package to reduce bundle size\n// eslint-disable-next-line import/extensions\nimport Sha256 from 'sha.js/sha256.js';\nimport {\n DecodeError,\n ArgumentError,\n InvalidChecksumError,\n PayloadLengthError,\n} from './errors';\nimport { concatBuffers, isKeyOfObject } from './other';\nimport * as Encoded from './encoder-types';\nimport { Encoding } from './encoder-types';\n\nexport { Encoded, Encoding };\n\n/**\n * Calculate SHA256 hash of `input`\n * @param input - Data to hash\n * @returns Hash\n * @deprecated use `SubtleCrypto.digest` or `sha.js` package instead\n */\nexport function sha256hash(input: Uint8Array | string): Buffer {\n return new Sha256().update(input).digest();\n}\n\n/**\n * @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L177-L202}\n */\nconst base64Types = [\n Encoding.ContractBytearray,\n Encoding.ContractStoreKey,\n Encoding.ContractStoreValue,\n Encoding.Transaction,\n Encoding.OracleQuery,\n Encoding.OracleResponse,\n Encoding.State,\n Encoding.Poi,\n Encoding.StateTrees,\n Encoding.CallStateTree,\n Encoding.Bytearray,\n] as const;\nconst base58Types = [\n Encoding.KeyBlockHash,\n Encoding.MicroBlockHash,\n Encoding.BlockPofHash,\n Encoding.BlockTxHash,\n Encoding.BlockStateHash,\n Encoding.Channel,\n Encoding.ContractAddress,\n Encoding.TxHash,\n Encoding.OracleAddress,\n Encoding.OracleQueryId,\n Encoding.AccountAddress,\n Encoding.Signature,\n Encoding.Commitment,\n Encoding.PeerPubkey,\n Encoding.Name,\n] as const;\n\n/**\n * @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L261-L286}\n */\nconst byteSizeForType = {\n [Encoding.KeyBlockHash]: 32,\n [Encoding.MicroBlockHash]: 32,\n [Encoding.BlockPofHash]: 32,\n [Encoding.BlockTxHash]: 32,\n [Encoding.BlockStateHash]: 32,\n [Encoding.Channel]: 32,\n [Encoding.ContractAddress]: 32,\n [Encoding.TxHash]: 32,\n [Encoding.OracleAddress]: 32,\n [Encoding.OracleQueryId]: 32,\n [Encoding.AccountAddress]: 32,\n [Encoding.Signature]: 64,\n [Encoding.Commitment]: 32,\n [Encoding.PeerPubkey]: 32,\n [Encoding.State]: 32,\n} as const;\n\nfunction ensureValidLength(data: Uint8Array, type: Encoding): void {\n if (!isKeyOfObject(type, byteSizeForType)) return;\n const reqLen = byteSizeForType[type];\n if (reqLen == null || data.length === reqLen) return;\n throw new PayloadLengthError(`Payload should be ${reqLen} bytes, got ${data.length} instead`);\n}\n\nconst getChecksum = (payload: Uint8Array): Buffer => sha256hash(sha256hash(payload)).slice(0, 4);\n\nconst addChecksum = (payload: Uint8Array): Buffer => concatBuffers([payload, getChecksum(payload)]);\n\nfunction getPayload(buffer: Buffer): Buffer {\n const payload = buffer.slice(0, -4);\n if (!getChecksum(payload).equals(buffer.slice(-4))) throw new InvalidChecksumError();\n return payload;\n}\n\nconst base64 = {\n encode: (buffer: Uint8Array) => addChecksum(buffer).toString('base64'),\n decode: (string: string) => getPayload(Buffer.from(string, 'base64')),\n};\n\nconst base58 = {\n encode: (buffer: Uint8Array) => bs58Encode(addChecksum(buffer)),\n decode: (string: string) => getPayload(Buffer.from(bs58Decode(string))),\n};\n\nconst parseType = (maybeType: unknown): [Encoding, typeof base64] => {\n const base64Type = base64Types.find((t) => t === maybeType);\n if (base64Type != null) return [base64Type, base64];\n const base58Type = base58Types.find((t) => t === maybeType);\n if (base58Type != null) return [base58Type, base58];\n throw new ArgumentError('prefix', `one of ${[...base58Types, ...base64Types].join(', ')}`, maybeType);\n};\n\n/**\n * Decode data using the default encoding/decoding algorithm\n * @param data - An Base58/64check encoded and prefixed string\n * (ex tx_..., sg_..., ak_....)\n * @returns Decoded data\n */\nexport function decode(data: Encoded.Any): Buffer {\n const [prefix, encodedPayload, extra] = data.split('_');\n if (encodedPayload == null) throw new DecodeError(`Encoded string missing payload: ${data}`);\n if (extra != null) throw new DecodeError(`Encoded string have extra parts: ${data}`);\n const [type, encoder] = parseType(prefix);\n const payload = encoder.decode(encodedPayload);\n ensureValidLength(payload, type);\n return payload;\n}\n\n/**\n * Encode data using the default encoding/decoding algorithm\n * @param data - An decoded data\n * @param type - Prefix of Transaction\n * @returns Encoded string Base58check or Base64check data\n */\nexport function encode<Type extends Encoding>(\n data: Uint8Array,\n type: Type,\n): Encoded.Generic<Type> {\n const [, encoder] = parseType(type);\n ensureValidLength(data, type);\n return `${type}_${encoder.encode(data)}`;\n}\n"],"mappings":";;;;AAAA,gBAA2D,MAA3D,C,CACA;AACA;;;;;;AACA,OAAOA,MAAP,MAAmB,kBAAnB;SAEEC,W,EACAC,a,EACAC,oB,EACAC,kB;SAEOC,a,EAAeC,a;OACjB,KAAKC,O;SACHC,Q;AAET,SAASD,OAAT,EAAkBC,QAAlB;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,UAAT,CAAoBC,KAApB,EAAwD;EAC7D,OAAO,IAAIV,MAAJ,GAAaW,MAAb,CAAoBD,KAApB,EAA2BE,MAA3B,EAAP;AACD;AAED;AACA;AACA;;AACA,MAAMC,WAAW,GAAG,CAClBL,QAAQ,CAACM,iBADS,EAElBN,QAAQ,CAACO,gBAFS,EAGlBP,QAAQ,CAACQ,kBAHS,EAIlBR,QAAQ,CAACS,WAJS,EAKlBT,QAAQ,CAACU,WALS,EAMlBV,QAAQ,CAACW,cANS,EAOlBX,QAAQ,CAACY,KAPS,EAQlBZ,QAAQ,CAACa,GARS,EASlBb,QAAQ,CAACc,UATS,EAUlBd,QAAQ,CAACe,aAVS,EAWlBf,QAAQ,CAACgB,SAXS,CAApB;AAaA,MAAMC,WAAW,GAAG,CAClBjB,QAAQ,CAACkB,YADS,EAElBlB,QAAQ,CAACmB,cAFS,EAGlBnB,QAAQ,CAACoB,YAHS,EAIlBpB,QAAQ,CAACqB,WA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