@aeternity/aepp-sdk 11.0.1 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (376) hide show
  1. package/LICENSE +1 -1
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +12 -19
  4. package/dist/aepp-sdk.browser-script.js.map +1 -1
  5. package/dist/aepp-sdk.browser.js +1 -1
  6. package/dist/aepp-sdk.browser.js.map +1 -1
  7. package/dist/aepp-sdk.js +1 -1
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/AeSdk.d.ts +37 -0
  10. package/es/AeSdk.mjs +81 -0
  11. package/es/AeSdk.mjs.map +1 -0
  12. package/es/AeSdkAepp.d.ts +69 -0
  13. package/es/AeSdkAepp.mjs +175 -0
  14. package/es/AeSdkAepp.mjs.map +1 -0
  15. package/es/AeSdkBase.d.ts +212 -0
  16. package/es/AeSdkBase.mjs +310 -0
  17. package/es/AeSdkBase.mjs.map +1 -0
  18. package/es/AeSdkWallet.d.ts +103 -0
  19. package/es/AeSdkWallet.mjs +322 -0
  20. package/es/AeSdkWallet.mjs.map +1 -0
  21. package/es/Node.d.ts +44 -0
  22. package/es/Node.mjs +141 -0
  23. package/es/Node.mjs.map +1 -0
  24. package/es/account/Base.d.ts +65 -0
  25. package/es/account/Base.mjs +123 -0
  26. package/es/account/Base.mjs.map +1 -0
  27. package/es/account/Memory.d.ts +25 -0
  28. package/es/account/Memory.mjs +81 -0
  29. package/es/account/Memory.mjs.map +1 -0
  30. package/es/account/Rpc.d.ts +27 -0
  31. package/es/account/Rpc.mjs +79 -0
  32. package/es/account/Rpc.mjs.map +1 -0
  33. package/es/aens.d.ts +209 -0
  34. package/es/aens.mjs +332 -0
  35. package/es/aens.mjs.map +1 -0
  36. package/es/aepp-wallet-communication/connection/Browser.d.ts +32 -0
  37. package/es/aepp-wallet-communication/connection/Browser.mjs +70 -0
  38. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
  39. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +17 -0
  40. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +57 -0
  41. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
  42. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +35 -0
  43. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +142 -0
  44. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
  45. package/es/aepp-wallet-communication/connection-proxy.d.ts +10 -0
  46. package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +15 -11
  47. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
  48. package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +33 -0
  49. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +169 -0
  50. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -0
  51. package/es/aepp-wallet-communication/rpc/types.d.ts +77 -0
  52. package/es/aepp-wallet-communication/rpc/types.mjs +3 -0
  53. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -0
  54. package/es/aepp-wallet-communication/schema.d.ts +90 -46
  55. package/es/aepp-wallet-communication/schema.mjs +214 -0
  56. package/es/aepp-wallet-communication/schema.mjs.map +1 -0
  57. package/es/aepp-wallet-communication/wallet-detector.d.ts +24 -0
  58. package/es/aepp-wallet-communication/wallet-detector.mjs +63 -0
  59. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  60. package/es/apis/compiler/compiler.d.ts +92 -0
  61. package/es/apis/compiler/compiler.mjs +576 -0
  62. package/es/apis/compiler/compiler.mjs.map +1 -0
  63. package/es/apis/compiler/index.d.ts +2 -0
  64. package/es/apis/compiler/index.mjs +3 -0
  65. package/es/apis/compiler/index.mjs.map +1 -0
  66. package/es/apis/compiler/models/index.d.ts +248 -0
  67. package/es/apis/compiler/models/index.mjs +48 -0
  68. package/es/apis/compiler/models/index.mjs.map +1 -0
  69. package/es/apis/compiler/models/mappers.d.ts +23 -0
  70. package/es/apis/compiler/models/mappers.mjs +585 -0
  71. package/es/apis/compiler/models/mappers.mjs.map +1 -0
  72. package/es/apis/compiler/models/parameters.d.ts +13 -0
  73. package/es/apis/compiler/models/parameters.mjs +71 -0
  74. package/es/apis/compiler/models/parameters.mjs.map +1 -0
  75. package/es/apis/node/index.d.ts +2 -0
  76. package/es/apis/node/index.mjs +3 -0
  77. package/es/apis/node/index.mjs.map +1 -0
  78. package/es/apis/node/models/index.d.ts +1061 -0
  79. package/es/apis/node/models/index.mjs +2 -0
  80. package/es/apis/node/models/index.mjs.map +1 -0
  81. package/es/apis/node/models/mappers.d.ts +95 -0
  82. package/es/apis/node/models/mappers.mjs +4164 -0
  83. package/es/apis/node/models/mappers.mjs.map +1 -0
  84. package/es/apis/node/models/parameters.d.ts +17 -0
  85. package/es/apis/node/models/parameters.mjs +165 -0
  86. package/es/apis/node/models/parameters.mjs.map +1 -0
  87. package/es/apis/node/node.d.ts +215 -0
  88. package/es/apis/node/node.mjs +1165 -0
  89. package/es/apis/node/node.mjs.map +1 -0
  90. package/es/chain.d.ts +220 -0
  91. package/es/chain.mjs +524 -0
  92. package/es/chain.mjs.map +1 -0
  93. package/es/channel/handlers.d.ts +34 -0
  94. package/es/channel/handlers.mjs +147 -112
  95. package/es/channel/handlers.mjs.map +1 -1
  96. package/es/channel/index.d.ts +634 -0
  97. package/es/channel/index.mjs +898 -900
  98. package/es/channel/index.mjs.map +1 -1
  99. package/es/channel/internal.d.ts +100 -0
  100. package/es/channel/internal.mjs +97 -51
  101. package/es/channel/internal.mjs.map +1 -1
  102. package/es/contract/Compiler.d.ts +17 -0
  103. package/es/contract/Compiler.mjs +67 -0
  104. package/es/contract/Compiler.mjs.map +1 -0
  105. package/es/contract/aci.d.ts +125 -0
  106. package/es/contract/aci.mjs +199 -180
  107. package/es/contract/aci.mjs.map +1 -1
  108. package/es/contract/ga.d.ts +68 -0
  109. package/es/contract/ga.mjs +190 -0
  110. package/es/contract/ga.mjs.map +1 -0
  111. package/es/contract/methods.d.ts +68 -0
  112. package/es/contract/methods.mjs +101 -0
  113. package/es/contract/methods.mjs.map +1 -0
  114. package/es/index.d.ts +32 -0
  115. package/es/index.mjs +32 -40
  116. package/es/index.mjs.map +1 -1
  117. package/es/oracle.d.ts +154 -0
  118. package/es/oracle.mjs +288 -0
  119. package/es/oracle.mjs.map +1 -0
  120. package/es/spend.d.ts +61 -0
  121. package/es/spend.mjs +122 -0
  122. package/es/spend.mjs.map +1 -0
  123. package/es/tx/builder/constants.d.ts +41 -0
  124. package/es/tx/builder/constants.mjs +11 -19
  125. package/es/tx/builder/constants.mjs.map +1 -1
  126. package/es/tx/builder/field-types.d.ts +62 -0
  127. package/es/tx/builder/field-types.mjs +62 -10
  128. package/es/tx/builder/field-types.mjs.map +1 -1
  129. package/es/tx/builder/helpers.d.ts +131 -0
  130. package/es/tx/builder/helpers.mjs +71 -169
  131. package/es/tx/builder/helpers.mjs.map +1 -1
  132. package/es/tx/builder/index.d.ts +75 -0
  133. package/es/tx/builder/index.mjs +141 -323
  134. package/es/tx/builder/index.mjs.map +1 -1
  135. package/es/tx/builder/schema.d.ts +350 -0
  136. package/es/tx/builder/schema.mjs +173 -510
  137. package/es/tx/builder/schema.mjs.map +1 -1
  138. package/es/tx/index.d.ts +63 -0
  139. package/es/tx/index.mjs +171 -265
  140. package/es/tx/index.mjs.map +1 -1
  141. package/es/tx/min-fee.d.ts +20 -0
  142. package/es/tx/min-fee.mjs +148 -0
  143. package/es/tx/min-fee.mjs.map +1 -0
  144. package/es/tx/validator.d.ts +19 -0
  145. package/es/tx/validator.mjs +64 -71
  146. package/es/tx/validator.mjs.map +1 -1
  147. package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
  148. package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
  149. package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
  150. package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
  151. package/es/typings/bip32-path/index.d.mjs +2 -0
  152. package/es/typings/bip32-path/index.d.mjs.map +1 -0
  153. package/es/typings/blakejs/index.d.mjs.map +1 -1
  154. package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
  155. package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
  156. package/es/utils/amount-formatter.d.ts +42 -0
  157. package/es/utils/amount-formatter.mjs +28 -41
  158. package/es/utils/amount-formatter.mjs.map +1 -1
  159. package/es/utils/autorest.d.ts +6 -0
  160. package/es/utils/autorest.mjs +97 -0
  161. package/es/utils/autorest.mjs.map +1 -0
  162. package/es/utils/bignumber.d.ts +13 -0
  163. package/es/utils/bignumber.mjs +10 -8
  164. package/es/utils/bignumber.mjs.map +1 -1
  165. package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
  166. package/es/utils/bytes.mjs +10 -14
  167. package/es/utils/bytes.mjs.map +1 -1
  168. package/es/utils/crypto.d.ts +103 -0
  169. package/es/utils/crypto.mjs +60 -68
  170. package/es/utils/crypto.mjs.map +1 -1
  171. package/es/utils/encoder.d.ts +26 -0
  172. package/es/utils/encoder.mjs +47 -51
  173. package/es/utils/encoder.mjs.map +1 -1
  174. package/es/{errors.d.ts → utils/errors.d.ts} +254 -57
  175. package/es/utils/errors.mjs +318 -125
  176. package/es/utils/errors.mjs.map +1 -1
  177. package/es/utils/hd-wallet.d.ts +34 -0
  178. package/es/utils/hd-wallet.mjs +27 -16
  179. package/es/utils/hd-wallet.mjs.map +1 -1
  180. package/es/utils/json-big.d.ts +5 -0
  181. package/es/utils/json-big.mjs +10 -14
  182. package/es/utils/json-big.mjs.map +1 -1
  183. package/es/utils/keystore.d.ts +51 -0
  184. package/es/utils/keystore.mjs +98 -193
  185. package/es/utils/keystore.mjs.map +1 -1
  186. package/es/{mptree.d.ts → utils/mptree.d.ts} +5 -8
  187. package/es/utils/mptree.mjs +13 -14
  188. package/es/utils/mptree.mjs.map +1 -1
  189. package/es/utils/other.d.ts +14 -0
  190. package/es/utils/other.mjs +21 -36
  191. package/es/utils/other.mjs.map +1 -1
  192. package/es/{semver-satisfies.d.ts → utils/semver-satisfies.d.ts} +0 -0
  193. package/es/utils/semver-satisfies.mjs.map +1 -1
  194. package/es/utils/string.d.ts +24 -0
  195. package/es/utils/string.mjs +8 -10
  196. package/es/utils/string.mjs.map +1 -1
  197. package/package.json +49 -39
  198. package/src/AeSdk.ts +65 -0
  199. package/src/AeSdkAepp.ts +167 -0
  200. package/src/AeSdkBase.ts +320 -0
  201. package/src/AeSdkWallet.ts +332 -0
  202. package/src/Node.ts +167 -0
  203. package/src/account/Base.ts +114 -0
  204. package/src/account/Memory.ts +83 -0
  205. package/src/account/Rpc.ts +67 -0
  206. package/src/aens.ts +391 -0
  207. package/src/aepp-wallet-communication/connection/Browser.ts +68 -0
  208. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +58 -0
  209. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +111 -0
  210. package/{es/utils/crypto-ts.mjs → src/aepp-wallet-communication/connection-proxy.ts} +16 -17
  211. package/src/aepp-wallet-communication/rpc/RpcClient.ts +137 -0
  212. package/src/aepp-wallet-communication/rpc/types.ts +66 -0
  213. package/src/aepp-wallet-communication/schema.ts +181 -0
  214. package/src/aepp-wallet-communication/wallet-detector.ts +71 -0
  215. package/src/apis/compiler/code-model-v4.yaml +2649 -0
  216. package/src/apis/compiler/compiler.ts +585 -0
  217. package/src/apis/compiler/index.ts +2 -0
  218. package/src/apis/compiler/models/index.ts +301 -0
  219. package/src/apis/compiler/models/mappers.ts +583 -0
  220. package/src/apis/compiler/models/parameters.ts +93 -0
  221. package/src/apis/node/code-model-v4.yaml +10046 -0
  222. package/src/apis/node/index.ts +2 -0
  223. package/src/apis/node/models/index.ts +1253 -0
  224. package/src/apis/node/models/mappers.ts +4278 -0
  225. package/src/apis/node/models/parameters.ts +188 -0
  226. package/src/apis/node/node.ts +1299 -0
  227. package/src/chain.ts +444 -0
  228. package/src/channel/{handlers.js → handlers.ts} +220 -128
  229. package/src/channel/index.ts +991 -0
  230. package/src/channel/internal.ts +345 -0
  231. package/src/contract/Compiler.ts +66 -0
  232. package/src/contract/aci.ts +529 -0
  233. package/src/contract/ga.ts +178 -0
  234. package/src/contract/methods.ts +118 -0
  235. package/src/index.ts +51 -0
  236. package/src/oracle.ts +342 -0
  237. package/src/spend.ts +152 -0
  238. package/src/tx/builder/{constants.js → constants.ts} +12 -16
  239. package/src/tx/builder/field-types.ts +111 -0
  240. package/src/tx/builder/helpers.ts +253 -0
  241. package/src/tx/builder/index.ts +394 -0
  242. package/src/tx/builder/schema.ts +771 -0
  243. package/src/tx/index.ts +199 -0
  244. package/src/tx/min-fee.ts +136 -0
  245. package/src/tx/validator.ts +226 -0
  246. package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
  247. package/src/typings/@aeternity__uuid/index.d.ts +3 -0
  248. package/src/typings/bip32-path/index.d.ts +33 -0
  249. package/src/typings/tweetnacl-auth/index.d.ts +14 -0
  250. package/src/utils/amount-formatter.ts +29 -42
  251. package/src/utils/autorest.ts +90 -0
  252. package/src/utils/bignumber.ts +9 -11
  253. package/src/utils/bytes.ts +12 -14
  254. package/src/utils/crypto.ts +217 -0
  255. package/src/utils/encoder.ts +52 -55
  256. package/src/utils/errors.ts +268 -134
  257. package/src/utils/hd-wallet.ts +134 -0
  258. package/src/utils/json-big.ts +26 -0
  259. package/src/utils/keystore.ts +179 -0
  260. package/src/utils/mptree.ts +14 -14
  261. package/src/utils/other.ts +28 -43
  262. package/src/utils/string.ts +8 -10
  263. package/es/account/base.mjs +0 -179
  264. package/es/account/base.mjs.map +0 -1
  265. package/es/account/memory.mjs +0 -99
  266. package/es/account/memory.mjs.map +0 -1
  267. package/es/account/multiple.mjs +0 -179
  268. package/es/account/multiple.mjs.map +0 -1
  269. package/es/ae/aens.mjs +0 -404
  270. package/es/ae/aens.mjs.map +0 -1
  271. package/es/ae/aepp.mjs +0 -45
  272. package/es/ae/aepp.mjs.map +0 -1
  273. package/es/ae/contract.mjs +0 -159
  274. package/es/ae/contract.mjs.map +0 -1
  275. package/es/ae/index.mjs +0 -207
  276. package/es/ae/index.mjs.map +0 -1
  277. package/es/ae/oracle.mjs +0 -339
  278. package/es/ae/oracle.mjs.map +0 -1
  279. package/es/ae/universal.mjs +0 -45
  280. package/es/ae/universal.mjs.map +0 -1
  281. package/es/ae/wallet.mjs +0 -50
  282. package/es/ae/wallet.mjs.map +0 -1
  283. package/es/amount-formatter.d.ts +0 -58
  284. package/es/bignumber.d.ts +0 -18
  285. package/es/chain/index.mjs +0 -272
  286. package/es/chain/index.mjs.map +0 -1
  287. package/es/chain/node.mjs +0 -442
  288. package/es/chain/node.mjs.map +0 -1
  289. package/es/contract/compiler.mjs +0 -115
  290. package/es/contract/compiler.mjs.map +0 -1
  291. package/es/contract/ga/helpers.mjs +0 -30
  292. package/es/contract/ga/helpers.mjs.map +0 -1
  293. package/es/contract/ga/index.mjs +0 -178
  294. package/es/contract/ga/index.mjs.map +0 -1
  295. package/es/crypto-ts.d.ts +0 -9
  296. package/es/encoder.d.ts +0 -26
  297. package/es/node-pool/index.mjs +0 -188
  298. package/es/node-pool/index.mjs.map +0 -1
  299. package/es/node.mjs +0 -133
  300. package/es/node.mjs.map +0 -1
  301. package/es/other.d.ts +0 -31
  302. package/es/string.d.ts +0 -26
  303. package/es/tx/tx-object.mjs +0 -283
  304. package/es/tx/tx-object.mjs.map +0 -1
  305. package/es/tx/tx.mjs +0 -938
  306. package/es/tx/tx.mjs.map +0 -1
  307. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs +0 -132
  308. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +0 -1
  309. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +0 -183
  310. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +0 -1
  311. package/es/utils/aepp-wallet-communication/connection/index.mjs +0 -87
  312. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +0 -1
  313. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs +0 -98
  314. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +0 -1
  315. package/es/utils/aepp-wallet-communication/helpers.mjs +0 -92
  316. package/es/utils/aepp-wallet-communication/helpers.mjs.map +0 -1
  317. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +0 -375
  318. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +0 -1
  319. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +0 -275
  320. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +0 -1
  321. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +0 -541
  322. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +0 -1
  323. package/es/utils/aepp-wallet-communication/schema.mjs +0 -102
  324. package/es/utils/aepp-wallet-communication/schema.mjs.map +0 -1
  325. package/es/utils/aepp-wallet-communication/wallet-detector.mjs +0 -110
  326. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +0 -1
  327. package/es/utils/async-init.mjs +0 -64
  328. package/es/utils/async-init.mjs.map +0 -1
  329. package/es/utils/crypto-ts.mjs.map +0 -1
  330. package/es/utils/swagger.mjs +0 -164
  331. package/es/utils/swagger.mjs.map +0 -1
  332. package/src/account/base.js +0 -153
  333. package/src/account/memory.js +0 -83
  334. package/src/account/multiple.js +0 -162
  335. package/src/ae/aens.js +0 -361
  336. package/src/ae/aepp.js +0 -45
  337. package/src/ae/contract.js +0 -148
  338. package/src/ae/index.js +0 -168
  339. package/src/ae/oracle.js +0 -311
  340. package/src/ae/universal.js +0 -47
  341. package/src/ae/wallet.js +0 -50
  342. package/src/chain/index.js +0 -269
  343. package/src/chain/node.js +0 -320
  344. package/src/channel/index.js +0 -903
  345. package/src/channel/internal.js +0 -236
  346. package/src/contract/aci.js +0 -376
  347. package/src/contract/compiler.js +0 -100
  348. package/src/contract/ga/helpers.js +0 -19
  349. package/src/contract/ga/index.js +0 -150
  350. package/src/index.js +0 -89
  351. package/src/node-pool/index.js +0 -172
  352. package/src/node.js +0 -116
  353. package/src/tx/builder/field-types.js +0 -61
  354. package/src/tx/builder/helpers.js +0 -334
  355. package/src/tx/builder/index.js +0 -465
  356. package/src/tx/builder/schema.js +0 -1100
  357. package/src/tx/index.js +0 -301
  358. package/src/tx/tx-object.js +0 -187
  359. package/src/tx/tx.js +0 -631
  360. package/src/tx/validator.js +0 -181
  361. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -119
  362. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -165
  363. package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
  364. package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -86
  365. package/src/utils/aepp-wallet-communication/helpers.js +0 -60
  366. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -294
  367. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -232
  368. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -401
  369. package/src/utils/aepp-wallet-communication/schema.ts +0 -80
  370. package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -92
  371. package/src/utils/async-init.js +0 -45
  372. package/src/utils/crypto.js +0 -219
  373. package/src/utils/hd-wallet.js +0 -100
  374. package/src/utils/json-big.js +0 -26
  375. package/src/utils/keystore.js +0 -219
  376. package/src/utils/swagger.js +0 -156
@@ -0,0 +1,6 @@
1
+ import { PipelinePolicy } from '@azure/core-rest-pipeline';
2
+ import { AdditionalPolicyConfig } from '@azure/core-client';
3
+ export declare const genRequestQueuesPolicy: () => AdditionalPolicyConfig;
4
+ export declare const genCombineGetRequestsPolicy: () => AdditionalPolicyConfig;
5
+ export declare const genErrorFormatterPolicy: (getMessage: (b: any) => string) => AdditionalPolicyConfig;
6
+ export declare const genVersionCheckPolicy: (name: string, ignorePath: string, versionPromise: Promise<string>, geVersion: string, ltVersion: string) => PipelinePolicy;
@@ -0,0 +1,97 @@
1
+ import { RestError } from '@azure/core-rest-pipeline';
2
+ import { pause } from "./other.mjs";
3
+ import semverSatisfies from "./semver-satisfies.mjs";
4
+ import { UnsupportedVersionError } from "./errors.mjs";
5
+ export const genRequestQueuesPolicy = () => {
6
+ const requestQueues = new Map();
7
+ return {
8
+ policy: {
9
+ name: 'request-queues',
10
+
11
+ async sendRequest(request, next) {
12
+ var _requestQueues$get;
13
+
14
+ const key = request.headers.get('__queue');
15
+ request.headers.delete('__queue');
16
+
17
+ const getResponse = async () => await next(request);
18
+
19
+ if (key == null) return await getResponse();
20
+ const req = ((_requestQueues$get = requestQueues.get(key)) !== null && _requestQueues$get !== void 0 ? _requestQueues$get : Promise.resolve()).then(getResponse, getResponse); // TODO: remove after fixing https://github.com/aeternity/aeternity/issues/3803
21
+ // gap to ensure that node won't reject the nonce
22
+
23
+ requestQueues.set(key, req.then(async () => await pause(750)));
24
+ return await req;
25
+ }
26
+
27
+ },
28
+ position: 'perCall'
29
+ };
30
+ };
31
+ export const genCombineGetRequestsPolicy = () => {
32
+ const pendingGetRequests = new Map();
33
+ return {
34
+ policy: {
35
+ name: 'combine-requests',
36
+
37
+ async sendRequest(request, next) {
38
+ var _pendingGetRequests$g;
39
+
40
+ if (request.method !== 'GET') return await next(request);
41
+ const key = JSON.stringify([request.url, request.body]);
42
+ const response = (_pendingGetRequests$g = pendingGetRequests.get(key)) !== null && _pendingGetRequests$g !== void 0 ? _pendingGetRequests$g : next(request);
43
+ pendingGetRequests.set(key, response);
44
+
45
+ try {
46
+ return await response;
47
+ } finally {
48
+ pendingGetRequests.delete(key);
49
+ }
50
+ }
51
+
52
+ },
53
+ position: 'perCall'
54
+ };
55
+ };
56
+ export const genErrorFormatterPolicy = getMessage => ({
57
+ policy: {
58
+ name: 'error-formatter',
59
+
60
+ async sendRequest(request, next) {
61
+ try {
62
+ return await next(request);
63
+ } catch (error) {
64
+ var _error$response;
65
+
66
+ if (!(error instanceof RestError) || error.request == null) throw error;
67
+ if (((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.bodyAsText) == null) throw error;
68
+ let body;
69
+
70
+ try {
71
+ body = JSON.parse(error.response.bodyAsText);
72
+ } catch (e) {
73
+ throw error;
74
+ }
75
+
76
+ error.message = `${new URL(error.request.url).pathname.slice(1)} error`;
77
+ const message = getMessage(body);
78
+ if (message !== '') error.message += `:${message}`;
79
+ throw error;
80
+ }
81
+ }
82
+
83
+ },
84
+ position: 'perCall'
85
+ });
86
+ export const genVersionCheckPolicy = (name, ignorePath, versionPromise, geVersion, ltVersion) => ({
87
+ name: 'version-check',
88
+
89
+ async sendRequest(request, next) {
90
+ if (new URL(request.url).pathname === ignorePath) return await next(request);
91
+ const args = [await versionPromise, geVersion, ltVersion];
92
+ if (!semverSatisfies(...args)) throw new UnsupportedVersionError(name, ...args);
93
+ return await next(request);
94
+ }
95
+
96
+ });
97
+ //# sourceMappingURL=autorest.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autorest.mjs","names":["RestError","pause","semverSatisfies","UnsupportedVersionError","genRequestQueuesPolicy","requestQueues","Map","policy","name","sendRequest","request","next","key","headers","get","delete","getResponse","req","Promise","resolve","then","set","position","genCombineGetRequestsPolicy","pendingGetRequests","method","JSON","stringify","url","body","response","genErrorFormatterPolicy","getMessage","error","bodyAsText","parse","e","message","URL","pathname","slice","genVersionCheckPolicy","ignorePath","versionPromise","geVersion","ltVersion","args"],"sources":["../../src/utils/autorest.ts"],"sourcesContent":["import { RestError, PipelineResponse, PipelinePolicy } from '@azure/core-rest-pipeline'\nimport { AdditionalPolicyConfig } from '@azure/core-client'\nimport { pause } from './other'\nimport semverSatisfies from './semver-satisfies'\nimport { UnsupportedVersionError } from './errors'\n\nexport const genRequestQueuesPolicy = (): AdditionalPolicyConfig => {\n const requestQueues = new Map<string, Promise<unknown>>()\n\n return {\n policy: {\n name: 'request-queues',\n async sendRequest (request, next) {\n const key = request.headers.get('__queue')\n request.headers.delete('__queue')\n const getResponse = async (): Promise<PipelineResponse> => await next(request)\n if (key == null) return await getResponse()\n const req = (requestQueues.get(key) ?? Promise.resolve()).then(getResponse, getResponse)\n // TODO: remove after fixing https://github.com/aeternity/aeternity/issues/3803\n // gap to ensure that node won't reject the nonce\n requestQueues.set(key, req.then(async () => await pause(750)))\n return await req\n }\n },\n position: 'perCall'\n }\n}\n\nexport const genCombineGetRequestsPolicy = (): AdditionalPolicyConfig => {\n const pendingGetRequests = new Map<string, Promise<PipelineResponse>>()\n\n return {\n policy: {\n name: 'combine-requests',\n async sendRequest (request, next) {\n if (request.method !== 'GET') return await next(request)\n const key = JSON.stringify([request.url, request.body])\n const response = pendingGetRequests.get(key) ?? next(request)\n pendingGetRequests.set(key, response)\n try {\n return await response\n } finally {\n pendingGetRequests.delete(key)\n }\n }\n },\n position: 'perCall'\n }\n}\n\nexport const genErrorFormatterPolicy = (\n getMessage: (b: any) => string\n): AdditionalPolicyConfig => ({\n policy: {\n name: 'error-formatter',\n async sendRequest (request, next) {\n try {\n return await next(request)\n } catch (error) {\n if (!(error instanceof RestError) || error.request == null) throw error\n if (error.response?.bodyAsText == null) throw error\n\n let body\n try {\n body = JSON.parse(error.response.bodyAsText)\n } catch (e) {\n throw error\n }\n error.message = `${new URL(error.request.url).pathname.slice(1)} error`\n const message = getMessage(body)\n if (message !== '') error.message += `:${message}`\n throw error\n }\n }\n },\n position: 'perCall'\n})\n\nexport const genVersionCheckPolicy = (\n name: string, ignorePath: string,\n versionPromise: Promise<string>, geVersion: string, ltVersion: string\n): PipelinePolicy => ({\n name: 'version-check',\n async sendRequest (request, next) {\n if (new URL(request.url).pathname === ignorePath) return await next(request)\n const args = [await versionPromise, geVersion, ltVersion] as const\n if (!semverSatisfies(...args)) throw new UnsupportedVersionError(name, ...args)\n return await next(request)\n }\n})\n"],"mappings":"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"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Big Number Helpers
3
+ */
4
+ import BigNumber from 'bignumber.js';
5
+ /**
6
+ * Check if value is BigNumber, Number, BigInt or number string representation
7
+ * @param number - number to check
8
+ */
9
+ export declare const isBigNumber: (number: string | number | bigint | BigNumber) => boolean;
10
+ /**
11
+ * BigNumber ceil operation
12
+ */
13
+ export declare const ceil: (bigNumber: BigNumber) => BigNumber;
@@ -1,20 +1,22 @@
1
+ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
2
+
1
3
  /**
2
4
  * Big Number Helpers
3
- * @module @aeternity/aepp-sdk/es/utils/bignumber
4
- * @example import { isBigNumber, ceil } from '@aeternity/aepp-sdk/es/utils/bignumber'
5
5
  */
6
6
  import BigNumber from 'bignumber.js';
7
7
  /**
8
- * Check if value is BigNumber, Number or number string representation
9
- * @param {String|Number|BigNumber} number number to convert
10
- * @return {Boolean}
8
+ * Check if value is BigNumber, Number, BigInt or number string representation
9
+ * @param number - number to check
11
10
  */
12
11
 
13
- export const isBigNumber = number => ['number', 'object', 'string', 'bigint'].includes(typeof number) && (!isNaN(number) || Number.isInteger(number) || BigNumber.isBigNumber(number));
12
+ export const isBigNumber = number => {
13
+ var _context;
14
+
15
+ if (typeof number === 'bigint') return true;
16
+ return _includesInstanceProperty(_context = ['number', 'object', 'string']).call(_context, typeof number) && (!isNaN(number) || Number.isInteger(number) || BigNumber.isBigNumber(number));
17
+ };
14
18
  /**
15
19
  * BigNumber ceil operation
16
- * @param {BigNumber} bigNumber
17
- * @return {BigNumber}
18
20
  */
19
21
 
20
22
  export const ceil = bigNumber => bigNumber.integerValue(BigNumber.ROUND_CEIL);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/bignumber.ts"],"names":["BigNumber","isBigNumber","number","includes","isNaN","Number","isInteger","ceil","bigNumber","integerValue","ROUND_CEIL"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,cAAtB;AAEA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,WAAW,GAAIC,MAAD,IACzB,CAAC,QAAD,EAAW,QAAX,EAAqB,QAArB,EAA+B,QAA/B,EAAyCC,QAAzC,CAAkD,OAAOD,MAAzD,MACC,CAACE,KAAK,CAACF,MAAD,CAAN,IAA4BG,MAAM,CAACC,SAAP,CAAiBJ,MAAjB,CAA5B,IAAwDF,SAAS,CAACC,WAAV,CAAsBC,MAAtB,CADzD,CADK;AAIP;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMK,IAAI,GAAIC,SAAD,IAAqCA,SAAS,CAACC,YAAV,CAAuBT,SAAS,CAACU,UAAjC,CAAlD","sourcesContent":["/**\n * Big Number Helpers\n * @module @aeternity/aepp-sdk/es/utils/bignumber\n * @example import { isBigNumber, ceil } from '@aeternity/aepp-sdk/es/utils/bignumber'\n */\nimport BigNumber from 'bignumber.js'\n\n/**\n * Check if value is BigNumber, Number or number string representation\n * @param {String|Number|BigNumber} number number to convert\n * @return {Boolean}\n */\nexport const isBigNumber = (number: string | number | BigNumber): boolean =>\n ['number', 'object', 'string', 'bigint'].includes(typeof number) &&\n (!isNaN(number as number) || Number.isInteger(number) || BigNumber.isBigNumber(number))\n\n/**\n * BigNumber ceil operation\n * @param {BigNumber} bigNumber\n * @return {BigNumber}\n */\nexport const ceil = (bigNumber: BigNumber): BigNumber => bigNumber.integerValue(BigNumber.ROUND_CEIL)\n"],"file":"bignumber.mjs"}
1
+ {"version":3,"file":"bignumber.mjs","names":["BigNumber","isBigNumber","number","isNaN","Number","isInteger","ceil","bigNumber","integerValue","ROUND_CEIL"],"sources":["../../src/utils/bignumber.ts"],"sourcesContent":["/**\n * Big Number Helpers\n */\nimport BigNumber from 'bignumber.js'\n\n/**\n * Check if value is BigNumber, Number, BigInt or number string representation\n * @param number - number to check\n */\nexport const isBigNumber = (number: string | number | bigint | BigNumber): boolean => {\n if (typeof number === 'bigint') return true\n return ['number', 'object', 'string'].includes(typeof number) &&\n (!isNaN(number as number) || Number.isInteger(number) || BigNumber.isBigNumber(number))\n}\n\n/**\n * BigNumber ceil operation\n */\nexport const ceil = (bigNumber: BigNumber): BigNumber => bigNumber\n .integerValue(BigNumber.ROUND_CEIL)\n"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,cAAtB;AAEA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,WAAW,GAAIC,MAAD,IAA2D;EAAA;;EACpF,IAAI,OAAOA,MAAP,KAAkB,QAAtB,EAAgC,OAAO,IAAP;EAChC,OAAO,sCAAC,QAAD,EAAW,QAAX,EAAqB,QAArB,kBAAwC,OAAOA,MAA/C,MACJ,CAACC,KAAK,CAACD,MAAD,CAAN,IAA4BE,MAAM,CAACC,SAAP,CAAiBH,MAAjB,CAA5B,IAAwDF,SAAS,CAACC,WAAV,CAAsBC,MAAtB,CADpD,CAAP;AAED,CAJM;AAMP;AACA;AACA;;AACA,OAAO,MAAMI,IAAI,GAAIC,SAAD,IAAqCA,SAAS,CAC/DC,YADsD,CACzCR,SAAS,CAACS,UAD+B,CAAlD"}
@@ -1,29 +1,26 @@
1
1
  /// <reference types="node" />
2
2
  import BigNumber from 'bignumber.js';
3
- /**
4
- * Bytes module
5
- * @module @aeternity/aepp-sdk/es/utils/bytes
6
- * @example import { Crypto } from '@aeternity/aepp-sdk'
7
- */
8
3
  /**
9
4
  * Convert bignumber to byte array
10
- * @param {BigNumber} x bignumber instance
11
- * @return Buffer
5
+ * @param x - bignumber instance
6
+ * @returns Buffer
12
7
  */
13
8
  export declare function bigNumberToByteArray(x: BigNumber): Buffer;
14
9
  /**
15
10
  * Convert string, number, or BigNumber to byte array
16
- * @param {null|string|number|BigNumber} val
17
- * @param {boolean} big enables force conversion to BigNumber
18
- * @return Buffer
11
+ * @param val - value to convert
12
+ * @param big - enables force conversion to BigNumber
13
+ * @returns Buffer
19
14
  */
20
15
  export declare function toBytes(val?: null | string | number | BigNumber, big?: boolean): Buffer;
21
16
  /**
22
17
  * Convert a string to a Buffer. If encoding is not specified, hex-encoding
23
18
  * will be used if the input is valid hex. If the input is valid base64 but
24
19
  * not valid hex, base64 will be used. Otherwise, utf8 will be used.
25
- * @param {string} str String to be converted.
26
- * @param {string} [enc] Encoding of the input string.
27
- * @return {buffer} Buffer containing the input data.
20
+ * @param str - String to be converted.
21
+ * @param enc - Encoding of the input string.
22
+ * @returns Buffer containing the input data.
28
23
  */
29
24
  export declare function str2buf(str: string, enc?: BufferEncoding): Buffer;
25
+ export declare const bytesToHex: (b: Uint8Array) => string;
26
+ export declare const hexToBytes: (s: string) => Uint8Array;
@@ -22,16 +22,10 @@ const {
22
22
  import BigNumber from 'bignumber.js';
23
23
  import { NoSerializerFoundError, TypeError } from "./errors.mjs";
24
24
  import { isBase64, isHex } from "./string.mjs";
25
- /**
26
- * Bytes module
27
- * @module @aeternity/aepp-sdk/es/utils/bytes
28
- * @example import { Crypto } from '@aeternity/aepp-sdk'
29
- */
30
-
31
25
  /**
32
26
  * Convert bignumber to byte array
33
- * @param {BigNumber} x bignumber instance
34
- * @return Buffer
27
+ * @param x - bignumber instance
28
+ * @returns Buffer
35
29
  */
36
30
 
37
31
  export function bigNumberToByteArray(x) {
@@ -42,9 +36,9 @@ export function bigNumberToByteArray(x) {
42
36
  }
43
37
  /**
44
38
  * Convert string, number, or BigNumber to byte array
45
- * @param {null|string|number|BigNumber} val
46
- * @param {boolean} big enables force conversion to BigNumber
47
- * @return Buffer
39
+ * @param val - value to convert
40
+ * @param big - enables force conversion to BigNumber
41
+ * @returns Buffer
48
42
  */
49
43
 
50
44
  export function toBytes(val) {
@@ -69,9 +63,9 @@ export function toBytes(val) {
69
63
  * Convert a string to a Buffer. If encoding is not specified, hex-encoding
70
64
  * will be used if the input is valid hex. If the input is valid base64 but
71
65
  * not valid hex, base64 will be used. Otherwise, utf8 will be used.
72
- * @param {string} str String to be converted.
73
- * @param {string} [enc] Encoding of the input string.
74
- * @return {buffer} Buffer containing the input data.
66
+ * @param str - String to be converted.
67
+ * @param enc - Encoding of the input string.
68
+ * @returns Buffer containing the input data.
75
69
  */
76
70
 
77
71
  export function str2buf(str, enc) {
@@ -79,4 +73,6 @@ export function str2buf(str, enc) {
79
73
 
80
74
  return _Buffer.from(str, (_ref = enc !== null && enc !== void 0 ? enc : isHex(str) ? 'hex' : undefined) !== null && _ref !== void 0 ? _ref : isBase64(str) ? 'base64' : undefined);
81
75
  }
76
+ export const bytesToHex = b => _Buffer.from(b).toString('hex');
77
+ export const hexToBytes = s => _Buffer.from(s, 'hex');
82
78
  //# sourceMappingURL=bytes.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/bytes.ts"],"names":["BigNumber","NoSerializerFoundError","TypeError","isBase64","isHex","bigNumberToByteArray","x","isInteger","toFixed","hexString","toString","length","from","toBytes","val","big","undefined","Number","isBigNumber","str2buf","str","enc"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,cAAtB;SACSC,sB,EAAwBC,S;SACxBC,Q,EAAUC,K;AAEnB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,oBAAT,CAA+BC,CAA/B,EAAqD;AAC1D,MAAI,CAACA,CAAC,CAACC,SAAF,EAAL,EAAoB,MAAM,IAAIL,SAAJ,CAAe,iCAAgCI,CAAC,CAACE,OAAF,EAAY,EAA3D,CAAN;AACpB,MAAIC,SAAS,GAAGH,CAAC,CAACI,QAAF,CAAW,EAAX,CAAhB;AACA,MAAID,SAAS,CAACE,MAAV,GAAmB,CAAnB,KAAyB,CAA7B,EAAgCF,SAAS,GAAG,MAAMA,SAAlB;AAChC,SAAO,QAAOG,IAAP,CAAYH,SAAZ,EAAuB,KAAvB,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASI,OAAT,CAAkBC,GAAlB,EAA0F;AAAA,MAA9BC,GAA8B,uEAAf,KAAe;AAC/F;AACA;AACA;AAEA,MAAID,GAAG,KAAKE,SAAR,IAAqBF,GAAG,KAAK,IAAjC,EAAuC,OAAO,QAAOF,IAAP,CAAY,EAAZ,CAAP;;AACvC,MAAIK,MAAM,CAACV,SAAP,CAAiBO,GAAjB,KAAyBd,SAAS,CAACkB,WAAV,CAAsBJ,GAAtB,CAAzB,IAAuDC,GAA3D,EAAgE;AAC9D,QAAI,CAACf,SAAS,CAACkB,WAAV,CAAsBJ,GAAtB,CAAL,EAAiCA,GAAG,GAAG,IAAId,SAAJ,CAAcc,GAAd,CAAN;AACjC,WAAOT,oBAAoB,CAACS,GAAD,CAA3B;AACD;;AACD,MAAI,OAAOA,GAAP,KAAe,QAAnB,EAA6B;AAC3B,WAAO,QAAOF,IAAP,CAAYE,GAAZ,CAAP;AACD;;AACD,QAAM,IAAIb,sBAAJ,EAAN;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASkB,OAAT,CAAkBC,GAAlB,EAA+BC,GAA/B,EAA6D;AAAA;;AAClE,SAAO,QAAOT,IAAP,CACLQ,GADK,UAELC,GAFK,aAELA,GAFK,cAELA,GAFK,GAEGjB,KAAK,CAACgB,GAAD,CAAL,GAAa,KAAb,GAAqBJ,SAFxB,uCAEuCb,QAAQ,CAACiB,GAAD,CAAR,GAAgB,QAAhB,GAA2BJ,SAFlE,CAAP;AAID","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 BigNumber from 'bignumber.js'\nimport { NoSerializerFoundError, TypeError } from './errors'\nimport { isBase64, isHex } from './string'\n\n/**\n * Bytes module\n * @module @aeternity/aepp-sdk/es/utils/bytes\n * @example import { Crypto } from '@aeternity/aepp-sdk'\n */\n\n/**\n * Convert bignumber to byte array\n * @param {BigNumber} x bignumber instance\n * @return Buffer\n */\nexport function bigNumberToByteArray (x: BigNumber): Buffer {\n if (!x.isInteger()) throw new TypeError(`Unexpected not integer value: ${x.toFixed()}`)\n let hexString = x.toString(16)\n if (hexString.length % 2 === 1) hexString = '0' + hexString\n return Buffer.from(hexString, 'hex')\n}\n\n/**\n * Convert string, number, or BigNumber to byte array\n * @param {null|string|number|BigNumber} val\n * @param {boolean} big enables force conversion to BigNumber\n * @return Buffer\n */\nexport function toBytes (val?: null | string | number | BigNumber, big: boolean = false): Buffer {\n // Encode a value to bytes.\n // If the value is an int it will be encoded as bytes big endian\n // Raises ValueError if the input is not an int or string\n\n if (val === undefined || val === null) return Buffer.from([])\n if (Number.isInteger(val) || BigNumber.isBigNumber(val) || big) {\n if (!BigNumber.isBigNumber(val)) val = new BigNumber(val)\n return bigNumberToByteArray(val)\n }\n if (typeof val === 'string') {\n return Buffer.from(val)\n }\n throw new NoSerializerFoundError()\n}\n\n/**\n * Convert a string to a Buffer. If encoding is not specified, hex-encoding\n * will be used if the input is valid hex. If the input is valid base64 but\n * not valid hex, base64 will be used. Otherwise, utf8 will be used.\n * @param {string} str String to be converted.\n * @param {string} [enc] Encoding of the input string.\n * @return {buffer} Buffer containing the input data.\n */\nexport function str2buf (str: string, enc?: BufferEncoding): Buffer {\n return Buffer.from(\n str,\n enc ?? (isHex(str) ? 'hex' : undefined) ?? (isBase64(str) ? 'base64' : undefined)\n )\n}\n"],"file":"bytes.mjs"}
1
+ {"version":3,"file":"bytes.mjs","names":["BigNumber","NoSerializerFoundError","TypeError","isBase64","isHex","bigNumberToByteArray","x","isInteger","toFixed","hexString","toString","length","from","toBytes","val","big","undefined","Number","isBigNumber","str2buf","str","enc","bytesToHex","b","hexToBytes","s"],"sources":["../../src/utils/bytes.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 BigNumber from 'bignumber.js'\nimport { NoSerializerFoundError, TypeError } from './errors'\nimport { isBase64, isHex } from './string'\n\n/**\n * Convert bignumber to byte array\n * @param x - bignumber instance\n * @returns Buffer\n */\nexport function bigNumberToByteArray (x: BigNumber): Buffer {\n if (!x.isInteger()) throw new TypeError(`Unexpected not integer value: ${x.toFixed()}`)\n let hexString = x.toString(16)\n if (hexString.length % 2 === 1) hexString = '0' + hexString\n return Buffer.from(hexString, 'hex')\n}\n\n/**\n * Convert string, number, or BigNumber to byte array\n * @param val - value to convert\n * @param big - enables force conversion to BigNumber\n * @returns Buffer\n */\nexport function toBytes (val?: null | string | number | BigNumber, big: boolean = false): Buffer {\n // Encode a value to bytes.\n // If the value is an int it will be encoded as bytes big endian\n // Raises ValueError if the input is not an int or string\n\n if (val === undefined || val === null) return Buffer.from([])\n if (Number.isInteger(val) || BigNumber.isBigNumber(val) || big) {\n if (!BigNumber.isBigNumber(val)) val = new BigNumber(val)\n return bigNumberToByteArray(val)\n }\n if (typeof val === 'string') {\n return Buffer.from(val)\n }\n throw new NoSerializerFoundError()\n}\n\n/**\n * Convert a string to a Buffer. If encoding is not specified, hex-encoding\n * will be used if the input is valid hex. If the input is valid base64 but\n * not valid hex, base64 will be used. Otherwise, utf8 will be used.\n * @param str - String to be converted.\n * @param enc - Encoding of the input string.\n * @returns Buffer containing the input data.\n */\nexport function str2buf (str: string, enc?: BufferEncoding): Buffer {\n return Buffer.from(\n str,\n enc ?? (isHex(str) ? 'hex' : undefined) ?? (isBase64(str) ? 'base64' : undefined)\n )\n}\n\nexport const bytesToHex = (b: Uint8Array): string => Buffer.from(b).toString('hex')\n\nexport const hexToBytes = (s: string): Uint8Array => Buffer.from(s, 'hex')\n"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,cAAtB;SACSC,sB,EAAwBC,S;SACxBC,Q,EAAUC,K;AAEnB;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,oBAAT,CAA+BC,CAA/B,EAAqD;EAC1D,IAAI,CAACA,CAAC,CAACC,SAAF,EAAL,EAAoB,MAAM,IAAIL,SAAJ,CAAe,iCAAgCI,CAAC,CAACE,OAAF,EAAY,EAA3D,CAAN;EACpB,IAAIC,SAAS,GAAGH,CAAC,CAACI,QAAF,CAAW,EAAX,CAAhB;EACA,IAAID,SAAS,CAACE,MAAV,GAAmB,CAAnB,KAAyB,CAA7B,EAAgCF,SAAS,GAAG,MAAMA,SAAlB;EAChC,OAAO,QAAOG,IAAP,CAAYH,SAAZ,EAAuB,KAAvB,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASI,OAAT,CAAkBC,GAAlB,EAA0F;EAAA,IAA9BC,GAA8B,uEAAf,KAAe;EAC/F;EACA;EACA;EAEA,IAAID,GAAG,KAAKE,SAAR,IAAqBF,GAAG,KAAK,IAAjC,EAAuC,OAAO,QAAOF,IAAP,CAAY,EAAZ,CAAP;;EACvC,IAAIK,MAAM,CAACV,SAAP,CAAiBO,GAAjB,KAAyBd,SAAS,CAACkB,WAAV,CAAsBJ,GAAtB,CAAzB,IAAuDC,GAA3D,EAAgE;IAC9D,IAAI,CAACf,SAAS,CAACkB,WAAV,CAAsBJ,GAAtB,CAAL,EAAiCA,GAAG,GAAG,IAAId,SAAJ,CAAcc,GAAd,CAAN;IACjC,OAAOT,oBAAoB,CAACS,GAAD,CAA3B;EACD;;EACD,IAAI,OAAOA,GAAP,KAAe,QAAnB,EAA6B;IAC3B,OAAO,QAAOF,IAAP,CAAYE,GAAZ,CAAP;EACD;;EACD,MAAM,IAAIb,sBAAJ,EAAN;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASkB,OAAT,CAAkBC,GAAlB,EAA+BC,GAA/B,EAA6D;EAAA;;EAClE,OAAO,QAAOT,IAAP,CACLQ,GADK,UAELC,GAFK,aAELA,GAFK,cAELA,GAFK,GAEGjB,KAAK,CAACgB,GAAD,CAAL,GAAa,KAAb,GAAqBJ,SAFxB,uCAEuCb,QAAQ,CAACiB,GAAD,CAAR,GAAgB,QAAhB,GAA2BJ,SAFlE,CAAP;AAID;AAED,OAAO,MAAMM,UAAU,GAAIC,CAAD,IAA2B,QAAOX,IAAP,CAAYW,CAAZ,EAAeb,QAAf,CAAwB,KAAxB,CAA9C;AAEP,OAAO,MAAMc,UAAU,GAAIC,CAAD,IAA2B,QAAOb,IAAP,CAAYa,CAAZ,EAAe,KAAf,CAA9C"}
@@ -0,0 +1,103 @@
1
+ /// <reference types="node" />
2
+ import { SignKeyPair } from 'tweetnacl';
3
+ import { Data } from 'blakejs';
4
+ import { sha256hash, EncodedData, EncodingType } from './encoder';
5
+ export { sha256hash };
6
+ /**
7
+ * Generate address from secret key
8
+ * @param secret - Private key
9
+ * @returns Public key encoded as address
10
+ */
11
+ export declare function getAddressFromPriv(secret: string | Uint8Array): EncodedData<'ak'>;
12
+ /**
13
+ * Check if address is valid
14
+ * @param address - Address
15
+ * @param prefix - Transaction prefix. Default: 'ak'
16
+ * @returns is valid
17
+ */
18
+ export declare function isAddressValid(address: string, prefix?: EncodingType): boolean;
19
+ /**
20
+ * Generate a random salt (positive integer)
21
+ * @returns random salt
22
+ */
23
+ export declare function salt(): number;
24
+ /**
25
+ * Converts a positive integer to the smallest possible
26
+ * representation in a binary digit representation
27
+ * @param value - Value to encode
28
+ * @returns Encoded number
29
+ */
30
+ export declare function encodeUnsigned(value: number): Buffer;
31
+ /**
32
+ * Calculate 256bits Blake2b hash of `input`
33
+ * @param input - Data to hash
34
+ * @returns Hash
35
+ */
36
+ export declare function hash(input: Data): Buffer;
37
+ /**
38
+ * Compute contract address
39
+ * @param owner - Address of contract owner
40
+ * @param nonce - Round when contract was created
41
+ * @returns Contract address
42
+ */
43
+ export declare function encodeContractAddress(owner: EncodedData<'ak'>, nonce: number): EncodedData<'ct'>;
44
+ /**
45
+ * Generate keyPair from secret key
46
+ * @param secret - secret key
47
+ * @returns Object with Private(privateKey) and Public(publicKey) keys
48
+ */
49
+ export declare function generateKeyPairFromSecret(secret: Uint8Array): SignKeyPair;
50
+ /**
51
+ * Generate a random ED25519 keypair
52
+ * @param raw - Whether to return raw (binary) keys
53
+ * @returns Key pair
54
+ */
55
+ export declare function generateKeyPair(raw: true): {
56
+ publicKey: Buffer;
57
+ secretKey: Buffer;
58
+ };
59
+ export declare function generateKeyPair(raw?: false): {
60
+ publicKey: EncodedData<'ak'>;
61
+ secretKey: string;
62
+ };
63
+ /**
64
+ * Encrypt given data using `password`
65
+ * @param password - Password to encrypt with
66
+ * @param binaryData - Data to encrypt
67
+ * @returns Encrypted data
68
+ */
69
+ export declare function encryptKey(password: string, binaryData: Uint8Array): Uint8Array;
70
+ /**
71
+ * Decrypt given data using `password`
72
+ * @param password - Password to decrypt with
73
+ * @param encrypted - Data to decrypt
74
+ * @returns Decrypted data
75
+ */
76
+ export declare function decryptKey(password: string, encrypted: Uint8Array): Uint8Array;
77
+ /**
78
+ * Generate signature
79
+ * @param data - Data to sign
80
+ * @param privateKey - Key to sign with
81
+ * @returns Signature
82
+ */
83
+ export declare function sign(data: string | Uint8Array, privateKey: string | Uint8Array): Uint8Array;
84
+ /**
85
+ * Verify that signature was signed by public key
86
+ * @param data - Data to verify
87
+ * @param signature - Signature to verify
88
+ * @param publicKey - Key to verify against
89
+ * @returns Valid?
90
+ */
91
+ export declare function verify(data: Uint8Array, signature: Uint8Array, publicKey: string | Uint8Array): boolean;
92
+ export declare function messageToHash(message: string): Buffer;
93
+ export declare function signMessage(message: string, privateKey: string | Buffer): Uint8Array;
94
+ export declare function verifyMessage(str: string, signature: Uint8Array, publicKey: string | Uint8Array): boolean;
95
+ /**
96
+ * Check key pair for validity
97
+ *
98
+ * Sign a message, and then verifying that signature
99
+ * @param privateKey - Private key to verify
100
+ * @param publicKey - Public key to verify
101
+ * @returns Valid?
102
+ */
103
+ export declare function isValidKeypair(privateKey: string | Uint8Array, publicKey: string | Uint8Array): boolean;
@@ -19,48 +19,44 @@ 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
-
23
- /**
24
- * Crypto module
25
- * @module @aeternity/aepp-sdk/es/utils/crypto
26
- * @example import { Crypto } from '@aeternity/aepp-sdk'
27
- */
28
22
  import nacl from 'tweetnacl';
29
23
  import aesjs from 'aes-js';
24
+ import _blakejs from 'blakejs';
25
+ const {
26
+ blake2b
27
+ } = _blakejs;
28
+ import _varuintBitcoin from 'varuint-bitcoin';
29
+ const {
30
+ encode: varuintEncode
31
+ } = _varuintBitcoin;
30
32
  import { str2buf } from "./bytes.mjs";
33
+ import { concatBuffers } from "./other.mjs";
31
34
  import { encode, decode, sha256hash } from "./encoder.mjs";
32
- import { hash } from "./crypto-ts.mjs";
33
- import { NotImplementedError } from "./errors.mjs";
34
- export * from "./crypto-ts.mjs";
35
35
  export { sha256hash };
36
36
  const Ecb = aesjs.ModeOfOperation.ecb;
37
37
  /**
38
38
  * Generate address from secret key
39
- * @rtype (secret: String) => tx: Promise[String]
40
- * @param {String} secret - Private key
41
- * @return {String} Public key
39
+ * @param secret - Private key
40
+ * @returns Public key encoded as address
42
41
  */
43
42
 
44
43
  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');
44
+ const secretBuffer = typeof secret === 'string' ? str2buf(secret) : secret;
45
+ const keys = nacl.sign.keyPair.fromSecretKey(secretBuffer);
46
+ return encode(keys.publicKey, 'ak');
50
47
  }
51
48
  /**
52
49
  * 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
50
+ * @param address - Address
51
+ * @param prefix - Transaction prefix. Default: 'ak'
52
+ * @returns is valid
57
53
  */
58
54
 
59
55
  export function isAddressValid(address) {
60
56
  let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'ak';
61
57
 
62
58
  try {
63
- decode(address, prefix);
59
+ decode(address);
64
60
  return true;
65
61
  } catch (e) {
66
62
  return false;
@@ -68,8 +64,7 @@ export function isAddressValid(address) {
68
64
  }
69
65
  /**
70
66
  * Generate a random salt (positive integer)
71
- * @rtype () => salt: Number
72
- * @return {Number} random salt
67
+ * @returns random salt
73
68
  */
74
69
 
75
70
  export function salt() {
@@ -78,9 +73,8 @@ export function salt() {
78
73
  /**
79
74
  * Converts a positive integer to the smallest possible
80
75
  * representation in a binary digit representation
81
- * @rtype (value: Number) => Buffer
82
- * @param {Number} value - Value to encode
83
- * @return {Buffer} - Encoded data
76
+ * @param value - Value to encode
77
+ * @returns Encoded number
84
78
  */
85
79
 
86
80
  export function encodeUnsigned(value) {
@@ -88,29 +82,34 @@ export function encodeUnsigned(value) {
88
82
 
89
83
  binary.writeUInt32BE(value);
90
84
  return binary.slice(binary.findIndex(i => i !== 0));
85
+ }
86
+ /**
87
+ * Calculate 256bits Blake2b hash of `input`
88
+ * @param input - Data to hash
89
+ * @returns Hash
90
+ */
91
+
92
+ export function hash(input) {
93
+ return _Buffer.from(blake2b(input, undefined, 32)); // 256 bits
91
94
  } // Todo Duplicated in tx builder. remove
92
95
 
93
96
  /**
94
97
  * Compute contract address
95
- * @rtype (owner: String, nonce: Number) => String
96
- * @param {String} owner - Address of contract owner
97
- * @param {Number} nonce - Round when contract was created
98
- * @return {String} - Contract address
98
+ * @param owner - Address of contract owner
99
+ * @param nonce - Round when contract was created
100
+ * @returns Contract address
99
101
  */
100
102
 
101
103
  export function encodeContractAddress(owner, nonce) {
102
- const publicKey = decode(owner, 'ak');
103
-
104
- const binary = _Buffer.concat([publicKey, encodeUnsigned(nonce)]);
105
-
104
+ const publicKey = decode(owner);
105
+ const binary = concatBuffers([publicKey, encodeUnsigned(nonce)]);
106
106
  return encode(hash(binary), 'ct');
107
107
  } // KEY-PAIR HELPERS
108
108
 
109
109
  /**
110
110
  * Generate keyPair from secret key
111
- * @rtype (secret: Uint8Array) => KeyPair
112
- * @param {Uint8Array} secret - secret key
113
- * @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
114
113
  */
115
114
 
116
115
  export function generateKeyPairFromSecret(secret) {
@@ -118,14 +117,12 @@ export function generateKeyPairFromSecret(secret) {
118
117
  }
119
118
  /**
120
119
  * Generate a random ED25519 keypair
121
- * @rtype (raw: Boolean) => {publicKey: String | Buffer, secretKey: String | Buffer}
122
- * @param {Boolean} raw - Whether to return raw (binary) keys
123
- * @return {Object} Key pair
120
+ * @param raw - Whether to return raw (binary) keys
121
+ * @returns Key pair
124
122
  */
125
123
 
126
124
  export function generateKeyPair() {
127
125
  let raw = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
128
- // <node>/apps/aens/test/aens_test_utils.erl
129
126
  const keyPair = nacl.sign.keyPair();
130
127
 
131
128
  const publicBuffer = _Buffer.from(keyPair.publicKey);
@@ -146,10 +143,9 @@ export function generateKeyPair() {
146
143
  }
147
144
  /**
148
145
  * Encrypt given data using `password`
149
- * @rtype (password: String, binaryData: Buffer) => Uint8Array
150
- * @param {String} password - Password to encrypt with
151
- * @param {Buffer} binaryData - Data to encrypt
152
- * @return {Uint8Array} Encrypted data
146
+ * @param password - Password to encrypt with
147
+ * @param binaryData - Data to encrypt
148
+ * @returns Encrypted data
153
149
  */
154
150
 
155
151
  export function encryptKey(password, binaryData) {
@@ -159,10 +155,9 @@ export function encryptKey(password, binaryData) {
159
155
  }
160
156
  /**
161
157
  * Decrypt given data using `password`
162
- * @rtype (password: String, encrypted: String) => Uint8Array
163
- * @param {String} password - Password to decrypt with
164
- * @param {String} encrypted - Data to decrypt
165
- * @return {Buffer} Decrypted data
158
+ * @param password - Password to decrypt with
159
+ * @param encrypted - Data to decrypt
160
+ * @returns Decrypted data
166
161
  */
167
162
 
168
163
  export function decryptKey(password, encrypted) {
@@ -170,15 +165,14 @@ export function decryptKey(password, encrypted) {
170
165
 
171
166
  const hashedPasswordBytes = sha256hash(password);
172
167
  const aesEcb = new Ecb(hashedPasswordBytes);
173
- return _Buffer.from(aesEcb.decrypt(encryptedBytes));
168
+ return aesEcb.decrypt(encryptedBytes);
174
169
  } // SIGNATURES
175
170
 
176
171
  /**
177
172
  * Generate signature
178
- * @rtype (data: String|Buffer, privateKey: Buffer) => Buffer
179
- * @param {String|Buffer} data - Data to sign
180
- * @param {String|Buffer} privateKey - Key to sign with
181
- * @return {Buffer|Uint8Array} Signature
173
+ * @param data - Data to sign
174
+ * @param privateKey - Key to sign with
175
+ * @returns Signature
182
176
  */
183
177
 
184
178
  export function sign(data, privateKey) {
@@ -186,23 +180,22 @@ export function sign(data, privateKey) {
186
180
  }
187
181
  /**
188
182
  * Verify that signature was signed by public key
189
- * @rtype (str: String, signature: Buffer, publicKey: Buffer) => Boolean
190
- * @param {String|Buffer} str - Data to verify
191
- * @param {Buffer} signature - Signature to verify
192
- * @param {Buffer} publicKey - Key to verify against
193
- * @return {Boolean} Valid?
183
+ * @param data - Data to verify
184
+ * @param signature - Signature to verify
185
+ * @param publicKey - Key to verify against
186
+ * @returns Valid?
194
187
  */
195
188
 
196
- export function verify(str, signature, publicKey) {
197
- return nacl.sign.detached.verify(new Uint8Array(str), signature, publicKey);
189
+ export function verify(data, signature, publicKey) {
190
+ const publicKeyBuffer = typeof publicKey === 'string' ? str2buf(publicKey) : publicKey;
191
+ return nacl.sign.detached.verify(data, signature, publicKeyBuffer);
198
192
  }
199
193
  export function messageToHash(message) {
200
194
  const p = _Buffer.from('aeternity Signed Message:\n', 'utf8');
201
195
 
202
196
  const msg = _Buffer.from(message, 'utf8');
203
197
 
204
- if (msg.length >= 0xFD) throw new NotImplementedError('Message too long');
205
- return hash(_Buffer.concat([_Buffer.from([p.length]), p, _Buffer.from([msg.length]), msg]));
198
+ return hash(concatBuffers([varuintEncode(p.length), p, varuintEncode(msg.length), msg]));
206
199
  }
207
200
  export function signMessage(message, privateKey) {
208
201
  return sign(messageToHash(message), privateKey);
@@ -214,10 +207,9 @@ export function verifyMessage(str, signature, publicKey) {
214
207
  * Check key pair for validity
215
208
  *
216
209
  * Sign a message, and then verifying that signature
217
- * @rtype (privateKey: Buffer, publicKey: Buffer) => Boolean
218
- * @param {Buffer} privateKey - Private key to verify
219
- * @param {Buffer} publicKey - Public key to verify
220
- * @return {Boolean} Valid?
210
+ * @param privateKey - Private key to verify
211
+ * @param publicKey - Public key to verify
212
+ * @returns Valid?
221
213
  */
222
214
 
223
215
  export function isValidKeypair(privateKey, publicKey) {