@aeternity/aepp-sdk 13.0.1 → 13.2.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 (322) hide show
  1. package/README.md +4 -2
  2. package/bin/aesophia_cli +0 -0
  3. package/dist/aepp-sdk.browser-script.js +1 -1
  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 +28490 -17706
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/AeSdkAepp.mjs.map +1 -1
  10. package/es/AeSdkBase.d.ts +21 -3
  11. package/es/AeSdkBase.mjs +51 -3
  12. package/es/AeSdkBase.mjs.map +1 -1
  13. package/es/AeSdkMethods.d.ts +9 -14
  14. package/es/AeSdkMethods.mjs +20 -49
  15. package/es/AeSdkMethods.mjs.map +1 -1
  16. package/es/AeSdkWallet.d.ts +1 -1
  17. package/es/AeSdkWallet.mjs +79 -23
  18. package/es/AeSdkWallet.mjs.map +1 -1
  19. package/es/Middleware.d.ts +38 -0
  20. package/es/Middleware.mjs +90 -0
  21. package/es/Middleware.mjs.map +1 -0
  22. package/es/MiddlewareSubscriber.d.ts +30 -0
  23. package/es/MiddlewareSubscriber.mjs +198 -0
  24. package/es/MiddlewareSubscriber.mjs.map +1 -0
  25. package/es/Node.d.ts +1 -1
  26. package/es/Node.mjs.map +1 -1
  27. package/es/account/Base.d.ts +57 -3
  28. package/es/account/Base.mjs +95 -1
  29. package/es/account/Base.mjs.map +1 -1
  30. package/es/account/Generalized.d.ts +4 -0
  31. package/es/account/Generalized.mjs +20 -0
  32. package/es/account/Generalized.mjs.map +1 -1
  33. package/es/account/Ledger.d.ts +4 -0
  34. package/es/account/Ledger.mjs +20 -0
  35. package/es/account/Ledger.mjs.map +1 -1
  36. package/es/account/LedgerFactory.mjs.map +1 -1
  37. package/es/account/Memory.d.ts +12 -0
  38. package/es/account/Memory.mjs +52 -0
  39. package/es/account/Memory.mjs.map +1 -1
  40. package/es/account/Rpc.d.ts +5 -6
  41. package/es/account/Rpc.mjs +53 -10
  42. package/es/account/Rpc.mjs.map +1 -1
  43. package/es/aens.d.ts +1 -1
  44. package/es/aens.mjs +1 -1
  45. package/es/aens.mjs.map +1 -1
  46. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
  47. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
  48. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
  49. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
  50. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -2
  51. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
  52. package/es/aepp-wallet-communication/rpc/types.d.ts +19 -0
  53. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
  54. package/es/aepp-wallet-communication/schema.d.ts +2 -8
  55. package/es/aepp-wallet-communication/schema.mjs +21 -33
  56. package/es/aepp-wallet-communication/schema.mjs.map +1 -1
  57. package/es/aepp-wallet-communication/wallet-detector.d.ts +1 -1
  58. package/es/aepp-wallet-communication/wallet-detector.mjs +0 -3
  59. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
  60. package/es/apis/compiler/compiler.mjs +15 -1
  61. package/es/apis/compiler/compiler.mjs.map +1 -1
  62. package/es/apis/compiler/models/index.d.ts +1 -7
  63. package/es/apis/compiler/models/index.mjs.map +1 -1
  64. package/es/apis/compiler/models/mappers.d.ts +0 -1
  65. package/es/apis/compiler/models/mappers.mjs +0 -43
  66. package/es/apis/compiler/models/mappers.mjs.map +1 -1
  67. package/es/apis/middleware/index.d.ts +2 -0
  68. package/es/apis/middleware/index.mjs +3 -0
  69. package/es/apis/middleware/index.mjs.map +1 -0
  70. package/es/apis/middleware/middleware.d.ts +309 -0
  71. package/es/apis/middleware/middleware.mjs +1527 -0
  72. package/es/apis/middleware/middleware.mjs.map +1 -0
  73. package/es/apis/middleware/models/index.d.ts +1496 -0
  74. package/es/apis/middleware/models/index.mjs +580 -0
  75. package/es/apis/middleware/models/index.mjs.map +1 -0
  76. package/es/apis/middleware/models/mappers.d.ts +102 -0
  77. package/es/apis/middleware/models/mappers.mjs +3334 -0
  78. package/es/apis/middleware/models/mappers.mjs.map +1 -0
  79. package/es/apis/middleware/models/parameters.d.ts +43 -0
  80. package/es/apis/middleware/models/parameters.mjs +417 -0
  81. package/es/apis/middleware/models/parameters.mjs.map +1 -0
  82. package/es/apis/node/node.mjs.map +1 -1
  83. package/es/chain.d.ts +2 -1
  84. package/es/chain.mjs +5 -3
  85. package/es/chain.mjs.map +1 -1
  86. package/es/channel/Base.d.ts +1 -1
  87. package/es/channel/Base.mjs +1 -4
  88. package/es/channel/Base.mjs.map +1 -1
  89. package/es/channel/Contract.mjs.map +1 -1
  90. package/es/channel/Spend.mjs.map +1 -1
  91. package/es/channel/handlers.mjs +2 -2
  92. package/es/channel/handlers.mjs.map +1 -1
  93. package/es/channel/internal.mjs +7 -5
  94. package/es/channel/internal.mjs.map +1 -1
  95. package/es/contract/Contract.mjs +2 -2
  96. package/es/contract/Contract.mjs.map +1 -1
  97. package/es/contract/compiler/Base.d.ts +21 -0
  98. package/es/contract/compiler/Base.mjs.map +1 -1
  99. package/es/contract/compiler/Cli.d.ts +2 -0
  100. package/es/contract/compiler/Cli.mjs +24 -3
  101. package/es/contract/compiler/Cli.mjs.map +1 -1
  102. package/es/contract/compiler/Http.d.ts +2 -0
  103. package/es/contract/compiler/Http.mjs +22 -2
  104. package/es/contract/compiler/Http.mjs.map +1 -1
  105. package/es/contract/compiler/HttpNode.d.ts +1 -0
  106. package/es/contract/compiler/HttpNode.mjs +5 -0
  107. package/es/contract/compiler/HttpNode.mjs.map +1 -1
  108. package/es/contract/delegation-signature.d.ts +2 -1
  109. package/es/contract/delegation-signature.mjs +39 -8
  110. package/es/contract/delegation-signature.mjs.map +1 -1
  111. package/es/contract/ga.mjs.map +1 -1
  112. package/es/deprecated.d.ts +14 -0
  113. package/es/deprecated.mjs +22 -0
  114. package/es/deprecated.mjs.map +1 -0
  115. package/es/index-browser.d.ts +20 -14
  116. package/es/index-browser.mjs +19 -15
  117. package/es/index-browser.mjs.map +1 -1
  118. package/es/oracle.mjs.map +1 -1
  119. package/es/spend.d.ts +2 -1
  120. package/es/spend.mjs +4 -2
  121. package/es/spend.mjs.map +1 -1
  122. package/es/tx/builder/constants.d.ts +0 -1
  123. package/es/tx/builder/constants.mjs +26 -24
  124. package/es/tx/builder/constants.mjs.map +1 -1
  125. package/es/tx/builder/field-types/abi-version.mjs.map +1 -1
  126. package/es/tx/builder/field-types/coin-amount.d.ts +1 -1
  127. package/es/tx/builder/field-types/coin-amount.mjs +2 -1
  128. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
  129. package/es/tx/builder/field-types/ct-version.mjs.map +1 -1
  130. package/es/tx/builder/field-types/deposit.d.ts +1 -1
  131. package/es/tx/builder/field-types/deposit.mjs.map +1 -1
  132. package/es/tx/builder/field-types/entry.mjs +2 -1
  133. package/es/tx/builder/field-types/entry.mjs.map +1 -1
  134. package/es/tx/builder/field-types/fee.mjs.map +1 -1
  135. package/es/tx/builder/field-types/field.mjs.map +1 -1
  136. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
  137. package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
  138. package/es/tx/builder/field-types/index.d.ts +28 -150
  139. package/es/tx/builder/field-types/index.mjs +28 -56
  140. package/es/tx/builder/field-types/index.mjs.map +1 -1
  141. package/es/tx/builder/field-types/map.mjs.map +1 -1
  142. package/es/tx/builder/field-types/mptree.mjs +3 -3
  143. package/es/tx/builder/field-types/mptree.mjs.map +1 -1
  144. package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
  145. package/es/tx/builder/field-types/pointers.mjs.map +1 -1
  146. package/es/tx/builder/field-types/string.mjs.map +1 -1
  147. package/es/tx/builder/field-types/ttl.mjs.map +1 -1
  148. package/es/tx/builder/field-types/u-int.mjs +1 -1
  149. package/es/tx/builder/field-types/u-int.mjs.map +1 -1
  150. package/es/tx/builder/helpers.d.ts +8 -1
  151. package/es/tx/builder/helpers.mjs +53 -9
  152. package/es/tx/builder/helpers.mjs.map +1 -1
  153. package/es/tx/builder/index.d.ts +4 -2
  154. package/es/tx/builder/index.mjs +0 -1
  155. package/es/tx/builder/index.mjs.map +1 -1
  156. package/es/tx/builder/schema.d.ts +9 -9
  157. package/es/tx/builder/schema.mjs +11 -10
  158. package/es/tx/builder/schema.mjs.map +1 -1
  159. package/es/tx/execution-cost.mjs.map +1 -1
  160. package/es/tx/transaction-signer.mjs.map +1 -1
  161. package/es/tx/validator.mjs +6 -3
  162. package/es/tx/validator.mjs.map +1 -1
  163. package/es/utils/amount-formatter.mjs +7 -7
  164. package/es/utils/amount-formatter.mjs.map +1 -1
  165. package/es/utils/autorest.mjs +6 -8
  166. package/es/utils/autorest.mjs.map +1 -1
  167. package/es/utils/bignumber.mjs.map +1 -1
  168. package/es/utils/bytes.mjs.map +1 -1
  169. package/es/utils/crypto.d.ts +1 -0
  170. package/es/utils/crypto.mjs +12 -2
  171. package/es/utils/crypto.mjs.map +1 -1
  172. package/es/utils/encoder-types.mjs +3 -3
  173. package/es/utils/encoder-types.mjs.map +1 -1
  174. package/es/utils/encoder.mjs.map +1 -1
  175. package/es/utils/errors.d.ts +2 -2
  176. package/es/utils/errors.mjs.map +1 -1
  177. package/es/utils/hd-wallet.mjs.map +1 -1
  178. package/es/utils/keystore.mjs.map +1 -1
  179. package/es/utils/other.d.ts +1 -0
  180. package/es/utils/other.mjs +5 -0
  181. package/es/utils/other.mjs.map +1 -1
  182. package/es/utils/semver-satisfies.mjs.map +1 -1
  183. package/es/utils/string.mjs.map +1 -1
  184. package/es/utils/typed-data.d.ts +45 -0
  185. package/es/utils/typed-data.mjs +70 -0
  186. package/es/utils/typed-data.mjs.map +1 -0
  187. package/package.json +56 -37
  188. package/src/AeSdkBase.ts +66 -5
  189. package/src/AeSdkMethods.ts +31 -50
  190. package/src/AeSdkWallet.ts +63 -17
  191. package/src/Middleware.ts +141 -0
  192. package/src/MiddlewareSubscriber.ts +207 -0
  193. package/src/Node.ts +1 -1
  194. package/src/account/Base.ts +102 -4
  195. package/src/account/Generalized.ts +20 -0
  196. package/src/account/Ledger.ts +20 -0
  197. package/src/account/Memory.ts +68 -1
  198. package/src/account/Rpc.ts +54 -7
  199. package/src/aens.ts +1 -1
  200. package/src/aepp-wallet-communication/rpc/RpcClient.ts +11 -3
  201. package/src/aepp-wallet-communication/rpc/types.ts +21 -0
  202. package/src/aepp-wallet-communication/schema.ts +3 -17
  203. package/src/aepp-wallet-communication/wallet-detector.ts +1 -2
  204. package/src/apis/compiler/compiler.ts +8 -1
  205. package/src/apis/compiler/models/index.ts +1 -8
  206. package/src/apis/compiler/models/mappers.ts +0 -36
  207. package/src/apis/middleware/index.ts +2 -0
  208. package/src/apis/middleware/middleware.ts +1807 -0
  209. package/src/apis/middleware/models/index.ts +1747 -0
  210. package/src/apis/middleware/models/mappers.ts +3370 -0
  211. package/src/apis/middleware/models/parameters.ts +463 -0
  212. package/src/chain.ts +4 -3
  213. package/src/channel/Base.ts +5 -5
  214. package/src/channel/internal.ts +2 -0
  215. package/src/contract/Contract.ts +2 -1
  216. package/src/contract/compiler/Base.ts +26 -0
  217. package/src/contract/compiler/Cli.ts +27 -3
  218. package/src/contract/compiler/Http.ts +21 -2
  219. package/src/contract/compiler/HttpNode.ts +6 -0
  220. package/src/contract/delegation-signature.ts +37 -11
  221. package/src/deprecated.ts +23 -0
  222. package/src/index-browser.ts +77 -15
  223. package/src/spend.ts +2 -2
  224. package/src/tx/builder/constants.ts +0 -1
  225. package/src/tx/builder/field-types/coin-amount.ts +2 -1
  226. package/src/tx/builder/field-types/entry.ts +1 -1
  227. package/src/tx/builder/field-types/index.ts +28 -58
  228. package/src/tx/builder/field-types/u-int.ts +1 -1
  229. package/src/tx/builder/helpers.ts +54 -9
  230. package/src/tx/builder/index.ts +6 -9
  231. package/src/tx/validator.ts +4 -2
  232. package/src/utils/autorest.ts +5 -10
  233. package/src/utils/crypto.ts +12 -2
  234. package/src/utils/errors.ts +2 -2
  235. package/src/utils/other.ts +5 -0
  236. package/src/utils/typed-data.ts +95 -0
  237. package/types-legacy/ts4.2/AeSdkBase.d.ts +21 -3
  238. package/types-legacy/ts4.2/AeSdkMethods.d.ts +9 -14
  239. package/types-legacy/ts4.2/AeSdkWallet.d.ts +1 -1
  240. package/types-legacy/ts4.2/Middleware.d.ts +46 -0
  241. package/types-legacy/ts4.2/MiddlewareSubscriber.d.ts +30 -0
  242. package/types-legacy/ts4.2/Node.d.ts +1 -1
  243. package/types-legacy/ts4.2/account/Base.d.ts +57 -3
  244. package/types-legacy/ts4.2/account/Generalized.d.ts +4 -0
  245. package/types-legacy/ts4.2/account/Ledger.d.ts +4 -0
  246. package/types-legacy/ts4.2/account/Memory.d.ts +12 -0
  247. package/types-legacy/ts4.2/account/Rpc.d.ts +5 -6
  248. package/types-legacy/ts4.2/aens.d.ts +1 -1
  249. package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +19 -0
  250. package/types-legacy/ts4.2/aepp-wallet-communication/schema.d.ts +2 -8
  251. package/types-legacy/ts4.2/aepp-wallet-communication/wallet-detector.d.ts +1 -1
  252. package/types-legacy/ts4.2/apis/compiler/models/index.d.ts +1 -7
  253. package/types-legacy/ts4.2/apis/compiler/models/mappers.d.ts +0 -1
  254. package/types-legacy/ts4.2/apis/middleware/index.d.ts +2 -0
  255. package/types-legacy/ts4.2/apis/middleware/middleware.d.ts +309 -0
  256. package/types-legacy/ts4.2/apis/middleware/models/index.d.ts +1496 -0
  257. package/types-legacy/ts4.2/apis/middleware/models/mappers.d.ts +102 -0
  258. package/types-legacy/ts4.2/apis/middleware/models/parameters.d.ts +43 -0
  259. package/types-legacy/ts4.2/chain.d.ts +2 -1
  260. package/types-legacy/ts4.2/channel/Base.d.ts +1 -1
  261. package/types-legacy/ts4.2/contract/compiler/Base.d.ts +21 -0
  262. package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +2 -0
  263. package/types-legacy/ts4.2/contract/compiler/Http.d.ts +2 -0
  264. package/types-legacy/ts4.2/contract/compiler/HttpNode.d.ts +1 -0
  265. package/types-legacy/ts4.2/contract/delegation-signature.d.ts +2 -1
  266. package/types-legacy/ts4.2/deprecated.d.ts +14 -0
  267. package/types-legacy/ts4.2/index-browser.d.ts +20 -14
  268. package/types-legacy/ts4.2/spend.d.ts +2 -1
  269. package/types-legacy/ts4.2/tx/builder/constants.d.ts +0 -1
  270. package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +1 -1
  271. package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +1 -1
  272. package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +28 -153
  273. package/types-legacy/ts4.2/tx/builder/helpers.d.ts +8 -1
  274. package/types-legacy/ts4.2/tx/builder/index.d.ts +4 -2
  275. package/types-legacy/ts4.2/tx/builder/schema.d.ts +9 -9
  276. package/types-legacy/ts4.2/utils/crypto.d.ts +1 -0
  277. package/types-legacy/ts4.2/utils/errors.d.ts +2 -2
  278. package/types-legacy/ts4.2/utils/other.d.ts +1 -0
  279. package/types-legacy/ts4.2/utils/typed-data.d.ts +60 -0
  280. package/types-legacy/ts4.5/AeSdkBase.d.ts +21 -3
  281. package/types-legacy/ts4.5/AeSdkMethods.d.ts +9 -14
  282. package/types-legacy/ts4.5/AeSdkWallet.d.ts +1 -1
  283. package/types-legacy/ts4.5/Middleware.d.ts +46 -0
  284. package/types-legacy/ts4.5/MiddlewareSubscriber.d.ts +30 -0
  285. package/types-legacy/ts4.5/Node.d.ts +1 -1
  286. package/types-legacy/ts4.5/account/Base.d.ts +57 -3
  287. package/types-legacy/ts4.5/account/Generalized.d.ts +4 -0
  288. package/types-legacy/ts4.5/account/Ledger.d.ts +4 -0
  289. package/types-legacy/ts4.5/account/Memory.d.ts +12 -0
  290. package/types-legacy/ts4.5/account/Rpc.d.ts +5 -6
  291. package/types-legacy/ts4.5/aens.d.ts +1 -1
  292. package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +19 -0
  293. package/types-legacy/ts4.5/aepp-wallet-communication/schema.d.ts +2 -8
  294. package/types-legacy/ts4.5/aepp-wallet-communication/wallet-detector.d.ts +1 -1
  295. package/types-legacy/ts4.5/apis/compiler/models/index.d.ts +1 -7
  296. package/types-legacy/ts4.5/apis/compiler/models/mappers.d.ts +0 -1
  297. package/types-legacy/ts4.5/apis/middleware/index.d.ts +2 -0
  298. package/types-legacy/ts4.5/apis/middleware/middleware.d.ts +309 -0
  299. package/types-legacy/ts4.5/apis/middleware/models/index.d.ts +1496 -0
  300. package/types-legacy/ts4.5/apis/middleware/models/mappers.d.ts +102 -0
  301. package/types-legacy/ts4.5/apis/middleware/models/parameters.d.ts +43 -0
  302. package/types-legacy/ts4.5/chain.d.ts +2 -1
  303. package/types-legacy/ts4.5/channel/Base.d.ts +1 -1
  304. package/types-legacy/ts4.5/contract/compiler/Base.d.ts +21 -0
  305. package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +2 -0
  306. package/types-legacy/ts4.5/contract/compiler/Http.d.ts +2 -0
  307. package/types-legacy/ts4.5/contract/compiler/HttpNode.d.ts +1 -0
  308. package/types-legacy/ts4.5/contract/delegation-signature.d.ts +2 -1
  309. package/types-legacy/ts4.5/deprecated.d.ts +14 -0
  310. package/types-legacy/ts4.5/index-browser.d.ts +20 -14
  311. package/types-legacy/ts4.5/spend.d.ts +2 -1
  312. package/types-legacy/ts4.5/tx/builder/constants.d.ts +0 -1
  313. package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +1 -1
  314. package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +1 -1
  315. package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +28 -153
  316. package/types-legacy/ts4.5/tx/builder/helpers.d.ts +8 -1
  317. package/types-legacy/ts4.5/tx/builder/index.d.ts +4 -2
  318. package/types-legacy/ts4.5/tx/builder/schema.d.ts +9 -9
  319. package/types-legacy/ts4.5/utils/crypto.d.ts +1 -0
  320. package/types-legacy/ts4.5/utils/errors.d.ts +2 -2
  321. package/types-legacy/ts4.5/utils/other.d.ts +1 -0
  322. package/types-legacy/ts4.5/utils/typed-data.d.ts +60 -0
@@ -7,7 +7,7 @@ import { v4 as uuid } from '@aeternity/uuid';
7
7
  import AeSdk from "./AeSdk.mjs";
8
8
  import verifyTransaction from "./tx/validator.mjs";
9
9
  import RpcClient from "./aepp-wallet-communication/rpc/RpcClient.mjs";
10
- import { METHODS, RPC_STATUS, SUBSCRIPTION_TYPES, RpcBroadcastError, RpcInvalidTransactionError, RpcNotAuthorizeError, RpcPermissionDenyError, RpcUnsupportedProtocolError } from "./aepp-wallet-communication/schema.mjs";
10
+ import { METHODS, RPC_STATUS, SUBSCRIPTION_TYPES, RpcInvalidTransactionError, RpcNotAuthorizeError, RpcPermissionDenyError, RpcUnsupportedProtocolError } from "./aepp-wallet-communication/schema.mjs";
11
11
  import { InternalError, UnknownRpcClientError } from "./utils/errors.mjs";
12
12
  import { RPC_VERSION } from "./aepp-wallet-communication/rpc/types.mjs";
13
13
  import jsonBig from "./utils/json-big.mjs";
@@ -47,9 +47,22 @@ export default class AeSdkWallet extends AeSdk {
47
47
  this.id = id;
48
48
  this._type = type;
49
49
  }
50
+ _getAccountsForClient(_ref2) {
51
+ let {
52
+ addressSubscription
53
+ } = _ref2;
54
+ const {
55
+ current,
56
+ connected
57
+ } = this.getAccounts();
58
+ return {
59
+ current: addressSubscription.has('current') || addressSubscription.has('connected') ? current : {},
60
+ connected: addressSubscription.has('connected') ? connected : {}
61
+ };
62
+ }
50
63
  _pushAccountsToApps() {
51
64
  if (this._clients == null) return;
52
- Array.from(this._clients.keys()).filter(clientId => this._isRpcClientSubscribed(clientId)).map(clientId => this._getClient(clientId).rpc).forEach(client => client.notify(METHODS.updateAddress, this.getAccounts()));
65
+ Array.from(this._clients.keys()).filter(clientId => this._isRpcClientConnected(clientId)).map(clientId => this._getClient(clientId)).filter(client => client.addressSubscription.size !== 0).forEach(client => client.rpc.notify(METHODS.updateAddress, this._getAccountsForClient(client)));
53
66
  }
54
67
  selectAccount(address) {
55
68
  super.selectAccount(address);
@@ -83,9 +96,6 @@ export default class AeSdkWallet extends AeSdk {
83
96
  if (client == null) throw new UnknownRpcClientError(clientId);
84
97
  return client;
85
98
  }
86
- _isRpcClientSubscribed(clientId) {
87
- return this._isRpcClientConnected(clientId) && this._getClient(clientId).addressSubscription.size !== 0;
88
- }
89
99
  _isRpcClientConnected(clientId) {
90
100
  return RPC_STATUS.CONNECTED === this._getClient(clientId).status && this._getClient(clientId).rpc.connection.isConnected();
91
101
  }
@@ -130,13 +140,13 @@ export default class AeSdkWallet extends AeSdk {
130
140
  },
131
141
  // Store client info and prepare two fn for each client `connect` and `denyConnection`
132
142
  // which automatically prepare and send response for that client
133
- [METHODS.connect]: async (_ref2, origin) => {
143
+ [METHODS.connect]: async (_ref3, origin) => {
134
144
  let {
135
145
  name,
136
146
  version,
137
147
  icons,
138
148
  connectNode
139
- } = _ref2;
149
+ } = _ref3;
140
150
  if (version !== RPC_VERSION) throw new RpcUnsupportedProtocolError();
141
151
  await this.onConnection(id, {
142
152
  name,
@@ -150,18 +160,19 @@ export default class AeSdkWallet extends AeSdk {
150
160
  ...(connectNode && this._getNode())
151
161
  };
152
162
  },
153
- [METHODS.subscribeAddress]: async (_ref3, origin) => {
163
+ [METHODS.subscribeAddress]: async (_ref4, origin) => {
154
164
  let {
155
165
  type,
156
166
  value
157
- } = _ref3;
167
+ } = _ref4;
158
168
  if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();
159
- await this.onSubscription(id, {
160
- type,
161
- value
162
- }, origin);
163
169
  switch (type) {
164
170
  case SUBSCRIPTION_TYPES.subscribe:
171
+ // TODO: remove `type` as it always subscribe
172
+ await this.onSubscription(id, {
173
+ type,
174
+ value
175
+ }, origin);
165
176
  client.addressSubscription.add(value);
166
177
  break;
167
178
  case SUBSCRIPTION_TYPES.unsubscribe:
@@ -172,20 +183,21 @@ export default class AeSdkWallet extends AeSdk {
172
183
  }
173
184
  return {
174
185
  subscription: Array.from(client.addressSubscription),
175
- address: this.getAccounts()
186
+ address: this._getAccountsForClient(client)
176
187
  };
177
188
  },
178
189
  [METHODS.address]: async (params, origin) => {
179
- if (!this._isRpcClientSubscribed(id)) throw new RpcNotAuthorizeError();
190
+ if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();
180
191
  await this.onAskAccounts(id, params, origin);
181
192
  return this.addresses();
182
193
  },
183
- [METHODS.sign]: async (_ref4, origin) => {
194
+ [METHODS.sign]: async (_ref5, origin) => {
184
195
  let {
185
196
  tx,
186
197
  onAccount = this.address,
187
- returnSigned
188
- } = _ref4;
198
+ returnSigned,
199
+ innerTx
200
+ } = _ref5;
189
201
  if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();
190
202
  if (!this.addresses().includes(onAccount)) {
191
203
  throw new RpcPermissionDenyError(onAccount);
@@ -193,9 +205,10 @@ export default class AeSdkWallet extends AeSdk {
193
205
  const parameters = {
194
206
  onAccount,
195
207
  aeppOrigin: origin,
196
- aeppRpcClientId: id
208
+ aeppRpcClientId: id,
209
+ innerTx
197
210
  };
198
- if (returnSigned) {
211
+ if (returnSigned || innerTx === true) {
199
212
  return {
200
213
  signedTransaction: await this.signTransaction(tx, parameters)
201
214
  };
@@ -210,14 +223,14 @@ export default class AeSdkWallet extends AeSdk {
210
223
  } catch (error) {
211
224
  const validation = await verifyTransaction(tx, this.api);
212
225
  if (validation.length > 0) throw new RpcInvalidTransactionError(validation);
213
- throw new RpcBroadcastError(error.message);
226
+ throw error;
214
227
  }
215
228
  },
216
- [METHODS.signMessage]: async (_ref5, origin) => {
229
+ [METHODS.signMessage]: async (_ref6, origin) => {
217
230
  let {
218
231
  message,
219
232
  onAccount = this.address
220
- } = _ref5;
233
+ } = _ref6;
221
234
  if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();
222
235
  if (!this.addresses().includes(onAccount)) {
223
236
  throw new RpcPermissionDenyError(onAccount);
@@ -230,6 +243,49 @@ export default class AeSdkWallet extends AeSdk {
230
243
  return {
231
244
  signature: _Buffer.from(await this.signMessage(message, parameters)).toString('hex')
232
245
  };
246
+ },
247
+ [METHODS.signTypedData]: async (_ref7, origin) => {
248
+ let {
249
+ domain,
250
+ aci,
251
+ data,
252
+ onAccount = this.address
253
+ } = _ref7;
254
+ if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();
255
+ if (!this.addresses().includes(onAccount)) {
256
+ throw new RpcPermissionDenyError(onAccount);
257
+ }
258
+ const parameters = {
259
+ ...domain,
260
+ onAccount,
261
+ aeppOrigin: origin,
262
+ aeppRpcClientId: id
263
+ };
264
+ return {
265
+ signature: await this.signTypedData(data, aci, parameters)
266
+ };
267
+ },
268
+ [METHODS.signDelegationToContract]: async (_ref8, origin) => {
269
+ var _ref9, _ref10;
270
+ let {
271
+ contractAddress,
272
+ name,
273
+ oracleQueryId,
274
+ onAccount = this.address
275
+ } = _ref8;
276
+ if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();
277
+ if (!this.addresses().includes(onAccount)) {
278
+ throw new RpcPermissionDenyError(onAccount);
279
+ }
280
+ const parameters = {
281
+ onAccount,
282
+ aeppOrigin: origin,
283
+ aeppRpcClientId: id
284
+ };
285
+ const signature = await ((_ref9 = (_ref10 = name == null ? null : this.signNameDelegationToContract(contractAddress, name, parameters)) !== null && _ref10 !== void 0 ? _ref10 : oracleQueryId == null ? null : this.signOracleQueryDelegationToContract(contractAddress, oracleQueryId, parameters)) !== null && _ref9 !== void 0 ? _ref9 : this.signDelegationToContract(contractAddress, parameters));
286
+ return {
287
+ signature
288
+ };
233
289
  }
234
290
  })
235
291
  };
@@ -1 +1 @@
1
- {"version":3,"file":"AeSdkWallet.mjs","names":["v4","uuid","AeSdk","verifyTransaction","RpcClient","METHODS","RPC_STATUS","SUBSCRIPTION_TYPES","RpcBroadcastError","RpcInvalidTransactionError","RpcNotAuthorizeError","RpcPermissionDenyError","RpcUnsupportedProtocolError","InternalError","UnknownRpcClientError","RPC_VERSION","jsonBig","AeSdkWallet","constructor","_ref","name","id","type","onConnection","onSubscription","onDisconnect","onAskAccounts","options","_defineProperty","Map","_type","_pushAccountsToApps","_clients","Array","from","keys","filter","clientId","_isRpcClientSubscribed","map","_getClient","rpc","forEach","client","notify","updateAddress","getAccounts","selectAccount","address","addAccount","account","_getNode","ensureNodeConnected","node","url","api","$host","selectedNodeName","selectNode","networkId","getNetworkId","_isRpcClientConnected","updateNetwork","connectNode","get","addressSubscription","size","CONNECTED","status","connection","isConnected","_disconnectRpcClient","disconnect","DISCONNECTED","Set","removeRpcClient","delete","addRpcClient","clientConnection","disconnectParams","WAITING_FOR_CONNECTION_REQUEST","closeConnection","params","connect","_ref2","origin","version","icons","getWalletInfo","subscribeAddress","_ref3","value","subscribe","add","unsubscribe","subscription","addresses","sign","_ref4","tx","onAccount","returnSigned","includes","parameters","aeppOrigin","aeppRpcClientId","signedTransaction","signTransaction","parse","stringify","transactionHash","sendTransaction","verify","error","validation","length","message","signMessage","_ref5","signature","_Buffer","toString","set","shareWalletInfo","readyToConnect","window","location","current","selectedAddress","connected","a","reduce","acc"],"sources":["../src/AeSdkWallet.ts"],"sourcesContent":["import { v4 as uuid } from '@aeternity/uuid';\nimport AeSdk from './AeSdk';\nimport verifyTransaction from './tx/validator';\nimport RpcClient from './aepp-wallet-communication/rpc/RpcClient';\nimport {\n METHODS, RPC_STATUS, SUBSCRIPTION_TYPES, WALLET_TYPE,\n RpcBroadcastError, RpcInvalidTransactionError,\n RpcNotAuthorizeError, RpcPermissionDenyError, RpcUnsupportedProtocolError,\n} from './aepp-wallet-communication/schema';\nimport { InternalError, UnknownRpcClientError } from './utils/errors';\nimport AccountBase from './account/Base';\nimport BrowserConnection from './aepp-wallet-communication/connection/Browser';\nimport {\n Accounts,\n AeppApi,\n Network,\n RPC_VERSION,\n WalletApi,\n WalletInfo,\n} from './aepp-wallet-communication/rpc/types';\nimport { Encoded } from './utils/encoder';\nimport jsonBig from './utils/json-big';\n\ntype RpcClientWallet = RpcClient<AeppApi, WalletApi>;\n\ntype OnConnection = (\n clientId: string, params: Omit<Parameters<WalletApi[METHODS.connect]>[0], 'version'>, origin: string\n) => void;\n\ntype OnSubscription = (\n clientId: string, params: Parameters<WalletApi[METHODS.subscribeAddress]>[0], origin: string\n) => void;\n\ntype OnDisconnect = (\n clientId: string, params: Parameters<WalletApi[METHODS.closeConnection]>[0]\n) => void;\n\ntype OnAskAccounts = (\n clientId: string, params: undefined, origin: string\n) => void;\n\ninterface RpcClientsInfo {\n id: string;\n status: RPC_STATUS;\n connectNode: boolean;\n addressSubscription: Set<'connected' | 'current'>;\n rpc: RpcClientWallet;\n}\n\n/**\n * Contain functionality for aepp interaction and managing multiple aepps\n * @category aepp wallet communication\n */\nexport default class AeSdkWallet extends AeSdk {\n id: string;\n\n _type: WALLET_TYPE;\n\n name: string;\n\n _clients = new Map<string, RpcClientsInfo>();\n\n onConnection: OnConnection;\n\n onSubscription: OnSubscription;\n\n onDisconnect: OnDisconnect;\n\n onAskAccounts: OnAskAccounts;\n\n /**\n * @param options - Options\n * @param options.name - Wallet name\n * @param options.id - Wallet id\n * @param options.type - Wallet type\n * @param options.onConnection - Call-back function for incoming AEPP connection\n * @param options.onSubscription - Call-back function for incoming AEPP account subscription\n * @param options.onAskAccounts - Call-back function for incoming AEPP get address request\n * @param options.onDisconnect - Call-back function for disconnect event\n */\n constructor({\n name,\n id,\n type,\n onConnection,\n onSubscription,\n onDisconnect,\n onAskAccounts,\n ...options\n }: {\n id: string;\n type: WALLET_TYPE;\n name: string;\n onConnection: OnConnection;\n onSubscription: OnSubscription;\n onDisconnect: OnDisconnect;\n onAskAccounts: OnAskAccounts;\n } & ConstructorParameters<typeof AeSdk>[0]) {\n super(options);\n this.onConnection = onConnection;\n this.onSubscription = onSubscription;\n this.onDisconnect = onDisconnect;\n this.onAskAccounts = onAskAccounts;\n this.name = name;\n this.id = id;\n this._type = type;\n }\n\n _pushAccountsToApps(): void {\n if (this._clients == null) return;\n Array.from(this._clients.keys())\n .filter((clientId) => this._isRpcClientSubscribed(clientId))\n .map((clientId) => this._getClient(clientId).rpc)\n .forEach((client) => client.notify(METHODS.updateAddress, this.getAccounts()));\n }\n\n override selectAccount(address: Encoded.AccountAddress): void {\n super.selectAccount(address);\n this._pushAccountsToApps();\n }\n\n override addAccount(account: AccountBase, options?: Parameters<AeSdk['addAccount']>[1]): void {\n super.addAccount(account, options);\n this._pushAccountsToApps();\n }\n\n _getNode(): { node: Network['node'] } {\n this.ensureNodeConnected();\n return { node: { url: this.api.$host, name: this.selectedNodeName } };\n }\n\n override async selectNode(name: string): Promise<void> {\n super.selectNode(name);\n const networkId = await this.api.getNetworkId();\n Array.from(this._clients.keys())\n .filter((clientId) => this._isRpcClientConnected(clientId))\n .map((clientId) => this._getClient(clientId))\n .forEach((client) => {\n client.rpc.notify(METHODS.updateNetwork, {\n networkId,\n ...client.connectNode && this._getNode(),\n });\n });\n }\n\n _getClient(clientId: string): RpcClientsInfo {\n const client = this._clients.get(clientId);\n if (client == null) throw new UnknownRpcClientError(clientId);\n return client;\n }\n\n _isRpcClientSubscribed(clientId: string): boolean {\n return this._isRpcClientConnected(clientId)\n && this._getClient(clientId).addressSubscription.size !== 0;\n }\n\n _isRpcClientConnected(clientId: string): boolean {\n return RPC_STATUS.CONNECTED === this._getClient(clientId).status\n && this._getClient(clientId).rpc.connection.isConnected();\n }\n\n _disconnectRpcClient(clientId: string): void {\n const client = this._getClient(clientId);\n client.rpc.connection.disconnect();\n client.status = RPC_STATUS.DISCONNECTED;\n client.addressSubscription = new Set();\n }\n\n /**\n * Remove specific RpcClient by ID\n * @param id - Client ID\n */\n removeRpcClient(id: string): void {\n this._disconnectRpcClient(id);\n this._clients.delete(id);\n }\n\n /**\n * Add new client by AEPP connection\n * @param clientConnection - AEPP connection object\n * @returns Client ID\n */\n addRpcClient(clientConnection: BrowserConnection): string {\n // @TODO detect if aepp has some history based on origin????\n // if yes use this instance for connection\n const id = uuid();\n let disconnectParams: any;\n const client: RpcClientsInfo = {\n id,\n status: RPC_STATUS.WAITING_FOR_CONNECTION_REQUEST,\n addressSubscription: new Set(),\n connectNode: false,\n rpc: new RpcClient<AeppApi, WalletApi>(\n clientConnection,\n () => {\n this._clients.delete(id);\n this.onDisconnect(id, disconnectParams); // also related info\n },\n {\n [METHODS.closeConnection]: (params) => {\n disconnectParams = params;\n this._disconnectRpcClient(id);\n },\n // Store client info and prepare two fn for each client `connect` and `denyConnection`\n // which automatically prepare and send response for that client\n [METHODS.connect]: async ({\n name, version, icons, connectNode,\n }, origin) => {\n if (version !== RPC_VERSION) throw new RpcUnsupportedProtocolError();\n\n await this.onConnection(id, { name, icons, connectNode }, origin);\n client.status = RPC_STATUS.CONNECTED;\n client.connectNode = connectNode;\n return {\n ...await this.getWalletInfo(),\n ...connectNode && this._getNode(),\n };\n },\n [METHODS.subscribeAddress]: async ({ type, value }, origin) => {\n if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();\n\n await this.onSubscription(id, { type, value }, origin);\n\n switch (type) {\n case SUBSCRIPTION_TYPES.subscribe:\n client.addressSubscription.add(value);\n break;\n case SUBSCRIPTION_TYPES.unsubscribe:\n client.addressSubscription.delete(value);\n break;\n default:\n throw new InternalError(`Unknown subscription type: ${type}`);\n }\n\n return {\n subscription: Array.from(client.addressSubscription),\n address: this.getAccounts(),\n };\n },\n [METHODS.address]: async (params, origin) => {\n if (!this._isRpcClientSubscribed(id)) throw new RpcNotAuthorizeError();\n await this.onAskAccounts(id, params, origin);\n return this.addresses();\n },\n [METHODS.sign]: async ({ tx, onAccount = this.address, returnSigned }, origin) => {\n if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();\n if (!this.addresses().includes(onAccount)) {\n throw new RpcPermissionDenyError(onAccount);\n }\n\n const parameters = { onAccount, aeppOrigin: origin, aeppRpcClientId: id };\n if (returnSigned) {\n return { signedTransaction: await this.signTransaction(tx, parameters) };\n }\n try {\n return jsonBig.parse(jsonBig.stringify({\n transactionHash: await this.sendTransaction(tx, { ...parameters, verify: false }),\n }));\n } catch (error) {\n const validation = await verifyTransaction(tx, this.api);\n if (validation.length > 0) throw new RpcInvalidTransactionError(validation);\n throw new RpcBroadcastError(error.message);\n }\n },\n [METHODS.signMessage]: async ({ message, onAccount = this.address }, origin) => {\n if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();\n if (!this.addresses().includes(onAccount)) {\n throw new RpcPermissionDenyError(onAccount);\n }\n\n const parameters = { onAccount, aeppOrigin: origin, aeppRpcClientId: id };\n return {\n signature: Buffer.from(await this.signMessage(message, parameters)).toString('hex'),\n };\n },\n },\n ),\n };\n this._clients.set(id, client);\n return id;\n }\n\n /**\n * Send shareWalletInfo message to notify AEPP about wallet\n * @param clientId - ID of RPC client send message to\n */\n async shareWalletInfo(clientId: string): Promise<void> {\n this._getClient(clientId).rpc.notify(METHODS.readyToConnect, await this.getWalletInfo());\n }\n\n /**\n * Get Wallet info object\n * @returns Object with wallet information\n */\n async getWalletInfo(): Promise<WalletInfo> {\n return {\n id: this.id,\n name: this.name,\n networkId: await this.api.getNetworkId(),\n origin: window.location.origin,\n type: this._type,\n };\n }\n\n /**\n * Get Wallet accounts\n * @returns Object with accounts information (\\{ connected: Object, current: Object \\})\n */\n getAccounts(): Accounts {\n return {\n current: this.selectedAddress != null ? { [this.selectedAddress]: {} } : {},\n connected: this.addresses()\n .filter((a) => a !== this.selectedAddress)\n .reduce((acc, a) => ({ ...acc, [a]: {} }), {}),\n };\n }\n}\n"],"mappings":";;;;;AAAA,SAASA,EAAE,IAAIC,IAAI,QAAQ,iBAAiB;AAAC,OACtCC,KAAK;AAAA,OACLC,iBAAiB;AAAA,OACjBC,SAAS;AAAA,SAEdC,OAAO,EAAEC,UAAU,EAAEC,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version":3,"file":"AeSdkWallet.mjs","names":["v4","uuid","AeSdk","verifyTransaction","RpcClient","METHODS","RPC_STATUS","SUBSCRIPTION_TYPES","RpcInvalidTransactionError","RpcNotAuthorizeError","RpcPermissionDenyError","RpcUnsupportedProtocolError","InternalError","UnknownRpcClientError","RPC_VERSION","jsonBig","AeSdkWallet","constructor","_ref","name","id","type","onConnection","onSubscription","onDisconnect","onAskAccounts","options","_defineProperty","Map","_type","_getAccountsForClient","_ref2","addressSubscription","current","connected","getAccounts","has","_pushAccountsToApps","_clients","Array","from","keys","filter","clientId","_isRpcClientConnected","map","_getClient","client","size","forEach","rpc","notify","updateAddress","selectAccount","address","addAccount","account","_getNode","ensureNodeConnected","node","url","api","$host","selectedNodeName","selectNode","networkId","getNetworkId","updateNetwork","connectNode","get","CONNECTED","status","connection","isConnected","_disconnectRpcClient","disconnect","DISCONNECTED","Set","removeRpcClient","delete","addRpcClient","clientConnection","disconnectParams","WAITING_FOR_CONNECTION_REQUEST","closeConnection","params","connect","_ref3","origin","version","icons","getWalletInfo","subscribeAddress","_ref4","value","subscribe","add","unsubscribe","subscription","addresses","sign","_ref5","tx","onAccount","returnSigned","innerTx","includes","parameters","aeppOrigin","aeppRpcClientId","signedTransaction","signTransaction","parse","stringify","transactionHash","sendTransaction","verify","error","validation","length","signMessage","_ref6","message","signature","_Buffer","toString","signTypedData","_ref7","domain","aci","data","signDelegationToContract","_ref8","_ref9","_ref10","contractAddress","oracleQueryId","signNameDelegationToContract","signOracleQueryDelegationToContract","set","shareWalletInfo","readyToConnect","window","location","selectedAddress","a","reduce","acc"],"sources":["../src/AeSdkWallet.ts"],"sourcesContent":["import { v4 as uuid } from '@aeternity/uuid';\nimport AeSdk from './AeSdk';\nimport verifyTransaction from './tx/validator';\nimport RpcClient from './aepp-wallet-communication/rpc/RpcClient';\nimport {\n METHODS, RPC_STATUS, SUBSCRIPTION_TYPES, WALLET_TYPE,\n RpcInvalidTransactionError,\n RpcNotAuthorizeError, RpcPermissionDenyError, RpcUnsupportedProtocolError,\n} from './aepp-wallet-communication/schema';\nimport { InternalError, UnknownRpcClientError } from './utils/errors';\nimport AccountBase from './account/Base';\nimport BrowserConnection from './aepp-wallet-communication/connection/Browser';\nimport {\n Accounts,\n AeppApi,\n Network,\n RPC_VERSION,\n WalletApi,\n WalletInfo,\n} from './aepp-wallet-communication/rpc/types';\nimport { Encoded } from './utils/encoder';\nimport jsonBig from './utils/json-big';\n\ntype RpcClientWallet = RpcClient<AeppApi, WalletApi>;\n\ntype OnConnection = (\n clientId: string, params: Omit<Parameters<WalletApi[METHODS.connect]>[0], 'version'>, origin: string\n) => void;\n\ntype OnSubscription = (\n clientId: string, params: Parameters<WalletApi[METHODS.subscribeAddress]>[0], origin: string\n) => void;\n\ntype OnDisconnect = (\n clientId: string, params: Parameters<WalletApi[METHODS.closeConnection]>[0]\n) => void;\n\ntype OnAskAccounts = (\n clientId: string, params: undefined, origin: string\n) => void;\n\ninterface RpcClientsInfo {\n id: string;\n status: RPC_STATUS;\n connectNode: boolean;\n addressSubscription: Set<'connected' | 'current'>;\n rpc: RpcClientWallet;\n}\n\n/**\n * Contain functionality for aepp interaction and managing multiple aepps\n * @category aepp wallet communication\n */\nexport default class AeSdkWallet extends AeSdk {\n id: string;\n\n _type: WALLET_TYPE;\n\n name: string;\n\n _clients = new Map<string, RpcClientsInfo>();\n\n onConnection: OnConnection;\n\n onSubscription: OnSubscription;\n\n onDisconnect: OnDisconnect;\n\n onAskAccounts: OnAskAccounts;\n\n /**\n * @param options - Options\n * @param options.name - Wallet name\n * @param options.id - Wallet id\n * @param options.type - Wallet type\n * @param options.onConnection - Call-back function for incoming AEPP connection\n * @param options.onSubscription - Call-back function for incoming AEPP account subscription\n * @param options.onAskAccounts - Call-back function for incoming AEPP get address request\n * @param options.onDisconnect - Call-back function for disconnect event\n */\n constructor({\n name,\n id,\n type,\n onConnection,\n onSubscription,\n onDisconnect,\n onAskAccounts,\n ...options\n }: {\n id: string;\n type: WALLET_TYPE;\n name: string;\n onConnection: OnConnection;\n onSubscription: OnSubscription;\n onDisconnect: OnDisconnect;\n onAskAccounts: OnAskAccounts;\n } & ConstructorParameters<typeof AeSdk>[0]) {\n super(options);\n this.onConnection = onConnection;\n this.onSubscription = onSubscription;\n this.onDisconnect = onDisconnect;\n this.onAskAccounts = onAskAccounts;\n this.name = name;\n this.id = id;\n this._type = type;\n }\n\n _getAccountsForClient({ addressSubscription }: RpcClientsInfo): Accounts {\n const { current, connected } = this.getAccounts();\n return {\n current: addressSubscription.has('current') || addressSubscription.has('connected')\n ? current : {},\n connected: addressSubscription.has('connected') ? connected : {},\n };\n }\n\n _pushAccountsToApps(): void {\n if (this._clients == null) return;\n Array.from(this._clients.keys())\n .filter((clientId) => this._isRpcClientConnected(clientId))\n .map((clientId) => this._getClient(clientId))\n .filter((client) => client.addressSubscription.size !== 0)\n .forEach((client) => client.rpc\n .notify(METHODS.updateAddress, this._getAccountsForClient(client)));\n }\n\n override selectAccount(address: Encoded.AccountAddress): void {\n super.selectAccount(address);\n this._pushAccountsToApps();\n }\n\n override addAccount(account: AccountBase, options?: Parameters<AeSdk['addAccount']>[1]): void {\n super.addAccount(account, options);\n this._pushAccountsToApps();\n }\n\n _getNode(): { node: Network['node'] } {\n this.ensureNodeConnected();\n return { node: { url: this.api.$host, name: this.selectedNodeName } };\n }\n\n override async selectNode(name: string): Promise<void> {\n super.selectNode(name);\n const networkId = await this.api.getNetworkId();\n Array.from(this._clients.keys())\n .filter((clientId) => this._isRpcClientConnected(clientId))\n .map((clientId) => this._getClient(clientId))\n .forEach((client) => {\n client.rpc.notify(METHODS.updateNetwork, {\n networkId,\n ...client.connectNode && this._getNode(),\n });\n });\n }\n\n _getClient(clientId: string): RpcClientsInfo {\n const client = this._clients.get(clientId);\n if (client == null) throw new UnknownRpcClientError(clientId);\n return client;\n }\n\n _isRpcClientConnected(clientId: string): boolean {\n return RPC_STATUS.CONNECTED === this._getClient(clientId).status\n && this._getClient(clientId).rpc.connection.isConnected();\n }\n\n _disconnectRpcClient(clientId: string): void {\n const client = this._getClient(clientId);\n client.rpc.connection.disconnect();\n client.status = RPC_STATUS.DISCONNECTED;\n client.addressSubscription = new Set();\n }\n\n /**\n * Remove specific RpcClient by ID\n * @param id - Client ID\n */\n removeRpcClient(id: string): void {\n this._disconnectRpcClient(id);\n this._clients.delete(id);\n }\n\n /**\n * Add new client by AEPP connection\n * @param clientConnection - AEPP connection object\n * @returns Client ID\n */\n addRpcClient(clientConnection: BrowserConnection): string {\n // @TODO detect if aepp has some history based on origin????\n // if yes use this instance for connection\n const id = uuid();\n let disconnectParams: any;\n const client: RpcClientsInfo = {\n id,\n status: RPC_STATUS.WAITING_FOR_CONNECTION_REQUEST,\n addressSubscription: new Set(),\n connectNode: false,\n rpc: new RpcClient<AeppApi, WalletApi>(\n clientConnection,\n () => {\n this._clients.delete(id);\n this.onDisconnect(id, disconnectParams); // also related info\n },\n {\n [METHODS.closeConnection]: (params) => {\n disconnectParams = params;\n this._disconnectRpcClient(id);\n },\n // Store client info and prepare two fn for each client `connect` and `denyConnection`\n // which automatically prepare and send response for that client\n [METHODS.connect]: async ({\n name, version, icons, connectNode,\n }, origin) => {\n if (version !== RPC_VERSION) throw new RpcUnsupportedProtocolError();\n\n await this.onConnection(id, { name, icons, connectNode }, origin);\n client.status = RPC_STATUS.CONNECTED;\n client.connectNode = connectNode;\n return {\n ...await this.getWalletInfo(),\n ...connectNode && this._getNode(),\n };\n },\n [METHODS.subscribeAddress]: async ({ type, value }, origin) => {\n if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();\n\n switch (type) {\n case SUBSCRIPTION_TYPES.subscribe:\n // TODO: remove `type` as it always subscribe\n await this.onSubscription(id, { type, value }, origin);\n client.addressSubscription.add(value);\n break;\n case SUBSCRIPTION_TYPES.unsubscribe:\n client.addressSubscription.delete(value);\n break;\n default:\n throw new InternalError(`Unknown subscription type: ${type}`);\n }\n\n return {\n subscription: Array.from(client.addressSubscription),\n address: this._getAccountsForClient(client),\n };\n },\n [METHODS.address]: async (params, origin) => {\n if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();\n await this.onAskAccounts(id, params, origin);\n return this.addresses();\n },\n [METHODS.sign]: async (\n {\n tx, onAccount = this.address, returnSigned, innerTx,\n },\n origin,\n ) => {\n if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();\n if (!this.addresses().includes(onAccount)) {\n throw new RpcPermissionDenyError(onAccount);\n }\n\n const parameters = {\n onAccount, aeppOrigin: origin, aeppRpcClientId: id, innerTx,\n };\n if (returnSigned || innerTx === true) {\n return { signedTransaction: await this.signTransaction(tx, parameters) };\n }\n try {\n return jsonBig.parse(jsonBig.stringify({\n transactionHash: await this.sendTransaction(tx, { ...parameters, verify: false }),\n }));\n } catch (error) {\n const validation = await verifyTransaction(tx, this.api);\n if (validation.length > 0) throw new RpcInvalidTransactionError(validation);\n throw error;\n }\n },\n [METHODS.signMessage]: async ({ message, onAccount = this.address }, origin) => {\n if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();\n if (!this.addresses().includes(onAccount)) {\n throw new RpcPermissionDenyError(onAccount);\n }\n\n const parameters = { onAccount, aeppOrigin: origin, aeppRpcClientId: id };\n return {\n signature: Buffer.from(await this.signMessage(message, parameters)).toString('hex'),\n };\n },\n [METHODS.signTypedData]: async ({\n domain, aci, data, onAccount = this.address,\n }, origin) => {\n if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();\n if (!this.addresses().includes(onAccount)) {\n throw new RpcPermissionDenyError(onAccount);\n }\n\n const parameters = {\n ...domain, onAccount, aeppOrigin: origin, aeppRpcClientId: id,\n };\n return {\n signature: await this.signTypedData(data, aci, parameters),\n };\n },\n [METHODS.signDelegationToContract]: async ({\n contractAddress, name, oracleQueryId, onAccount = this.address,\n }, origin) => {\n if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();\n if (!this.addresses().includes(onAccount)) {\n throw new RpcPermissionDenyError(onAccount);\n }\n\n const parameters = { onAccount, aeppOrigin: origin, aeppRpcClientId: id };\n const signature = await (\n (name == null ? null : this\n .signNameDelegationToContract(contractAddress, name, parameters))\n ?? (oracleQueryId == null ? null : this\n .signOracleQueryDelegationToContract(contractAddress, oracleQueryId, parameters))\n ?? this.signDelegationToContract(contractAddress, parameters)\n );\n return { signature };\n },\n },\n ),\n };\n this._clients.set(id, client);\n return id;\n }\n\n /**\n * Send shareWalletInfo message to notify AEPP about wallet\n * @param clientId - ID of RPC client send message to\n */\n async shareWalletInfo(clientId: string): Promise<void> {\n this._getClient(clientId).rpc.notify(METHODS.readyToConnect, await this.getWalletInfo());\n }\n\n /**\n * Get Wallet info object\n * @returns Object with wallet information\n */\n async getWalletInfo(): Promise<WalletInfo> {\n return {\n id: this.id,\n name: this.name,\n networkId: await this.api.getNetworkId(),\n origin: window.location.origin,\n type: this._type,\n };\n }\n\n /**\n * Get Wallet accounts\n * @returns Object with accounts information (\\{ connected: Object, current: Object \\})\n */\n getAccounts(): Accounts {\n return {\n current: this.selectedAddress != null ? { [this.selectedAddress]: {} } : {},\n connected: this.addresses()\n .filter((a) => a !== this.selectedAddress)\n .reduce((acc, a) => ({ ...acc, [a]: {} }), {}),\n };\n }\n}\n"],"mappings":";;;;;AAAA,SAASA,EAAE,IAAIC,IAAI,QAAQ,iBAAiB;AAAC,OACtCC,KAAK;AAAA,OACLC,iBAAiB;AAAA,OACjBC,SAAS;AAAA,SAEdC,OAAO,EAAEC,UAAU,EAAEC,kBAAkB,EACvCC,0BAA0B,EAC1BC,oBAAoB,EAAEC,sBAAsB,EAAEC,2BAA2B;AAAA,SAElEC,aAAa,EAAEC,qBAAqB;AAAA,SAO3CC,WAAW;AAAA,OAKNC,OAAO;AA4Bd;AACA;AACA;AACA;AACA,eAAe,MAAMC,WAAW,SAASd,KAAK,CAAC;EAiB7C;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEe,WAAWA,CAAAC,IAAA,EAiBiC;IAAA,IAjBhC;MACV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AE,MAAM,IAAI,CAACJ,GAAG,CAACK,YAAY,CAAC,CAAC;MACxCsB,MAAM,EAAEsD,MAAM,CAACC,QAAQ,CAACvD,MAAM;MAC9BnE,IAAI,EAAE,IAAI,CAACQ;IACb,CAAC;EACH;;EAEA;AACF;AACA;AACA;EACEM,WAAWA,CAAA,EAAa;IACtB,OAAO;MACLF,OAAO,EAAE,IAAI,CAAC+G,eAAe,IAAI,IAAI,GAAG;QAAE,CAAC,IAAI,CAACA,eAAe,GAAG,CAAC;MAAE,CAAC,GAAG,CAAC,CAAC;MAC3E9G,SAAS,EAAE,IAAI,CAACiE,SAAS,CAAC,CAAC,CACxBzD,MAAM,CAAEuG,CAAC,IAAKA,CAAC,KAAK,IAAI,CAACD,eAAe,CAAC,CACzCE,MAAM,CAAC,CAACC,GAAG,EAAEF,CAAC,MAAM;QAAE,GAAGE,GAAG;QAAE,CAACF,CAAC,GAAG,CAAC;MAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IACjD,CAAC;EACH;AACF"}
@@ -0,0 +1,38 @@
1
+ import { Middleware as MiddlewareApi, MiddlewareOptionalParams } from './apis/middleware';
2
+ import { Encoded } from './utils/encoder';
3
+ import { ConsensusProtocolVersion } from './tx/builder/constants';
4
+ declare const bigIntPropertyNames: readonly [];
5
+ declare const numberPropertyNames: readonly [];
6
+ type BigIntPropertyNames = typeof bigIntPropertyNames[number];
7
+ type NumberPropertyNames = typeof numberPropertyNames[number];
8
+ type PreserveOptional<NewType, OrigType> = OrigType extends undefined ? NewType | undefined : NewType;
9
+ export type TransformMiddlewareType<Type> = Type extends (...args: infer Args) => infer Ret ? (...args: TransformMiddlewareType<Args>) => TransformMiddlewareType<Ret> : Type extends [infer Item, ...infer Rest] ? [TransformMiddlewareType<Item>, ...TransformMiddlewareType<Rest>] : Type extends Array<infer Item> ? Array<TransformMiddlewareType<Item>> : Type extends Promise<infer T> ? Promise<TransformMiddlewareType<T>> : Type extends {
10
+ [P in any]: any;
11
+ } ? {
12
+ [Property in keyof Type]: Property extends BigIntPropertyNames ? PreserveOptional<bigint, Type[Property]> : Property extends NumberPropertyNames ? PreserveOptional<number, Type[Property]> : Property extends 'txHash' ? PreserveOptional<Encoded.TxHash, Type[Property]> : Property extends 'bytecode' ? PreserveOptional<Encoded.ContractBytearray, Type[Property]> : TransformMiddlewareType<Type[Property]>;
13
+ } : Type;
14
+ type MiddlewareTransformedApi = new (...args: ConstructorParameters<typeof MiddlewareApi>) => {
15
+ [Name in keyof InstanceType<typeof MiddlewareApi>]: Name extends 'pipeline' | 'sendRequest' | 'sendOperationRequest' ? MiddlewareApi[Name] : TransformMiddlewareType<MiddlewareApi[Name]>;
16
+ };
17
+ export interface MiddlewareInfo {
18
+ url: string;
19
+ nodeNetworkId: string;
20
+ version: string;
21
+ consensusProtocolVersion: ConsensusProtocolVersion;
22
+ }
23
+ declare const Middleware_base: MiddlewareTransformedApi;
24
+ export default class Middleware extends Middleware_base {
25
+ /**
26
+ * @param url - Url for middleware API
27
+ * @param options - Options
28
+ * @param options.ignoreVersion - Don't check node version
29
+ * @param options.retryCount - Amount of extra requests to do in case of failure
30
+ * @param options.retryOverallDelay - Time in ms to wait between all retries
31
+ */
32
+ constructor(url: string, { ignoreVersion, retryCount, retryOverallDelay, ...options }?: MiddlewareOptionalParams & {
33
+ ignoreVersion?: boolean;
34
+ retryCount?: number;
35
+ retryOverallDelay?: number;
36
+ });
37
+ }
38
+ export {};
@@ -0,0 +1,90 @@
1
+ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
2
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
3
+ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
4
+ // eslint-disable-next-line max-classes-per-file
5
+ import BigNumber from 'bignumber.js';
6
+ import { genRequestQueuesPolicy, genCombineGetRequestsPolicy, genErrorFormatterPolicy, genVersionCheckPolicy, genRetryOnFailurePolicy } from "./utils/autorest.mjs";
7
+ import { Middleware as MiddlewareApi } from "./apis/middleware/index.mjs";
8
+ import { mapObject } from "./utils/other.mjs";
9
+ const bigIntPropertyNames = [];
10
+ const numberPropertyNames = [];
11
+ var _mapData = /*#__PURE__*/new WeakSet();
12
+ var _encodeArg = /*#__PURE__*/new WeakSet();
13
+ var _decodeRes = /*#__PURE__*/new WeakSet();
14
+ class MiddlewareTransformed extends MiddlewareApi {
15
+ constructor() {
16
+ super(...arguments);
17
+ _classPrivateMethodInitSpec(this, _decodeRes);
18
+ _classPrivateMethodInitSpec(this, _encodeArg);
19
+ _classPrivateMethodInitSpec(this, _mapData);
20
+ }
21
+ async sendOperationRequest(operationArguments, operationSpec) {
22
+ const args = mapObject(operationArguments, _ref => {
23
+ let [key, value] = _ref;
24
+ return [key, _classPrivateMethodGet(this, _encodeArg, _encodeArg2).call(this, value)];
25
+ });
26
+ return _classPrivateMethodGet(this, _decodeRes, _decodeRes2).call(this, await super.sendOperationRequest(args, operationSpec));
27
+ }
28
+ }
29
+ function _mapData2(data, transform) {
30
+ if (Array.isArray(data)) return data.map(d => _classPrivateMethodGet(this, _mapData, _mapData2).call(this, d, transform));
31
+ if (data != null && typeof data === 'object') {
32
+ return mapObject(data, _ref3 => {
33
+ let [key, value] = _ref3;
34
+ if (value == null) return [key, value];
35
+ if (bigIntPropertyNames.some(k => k === key)) return [key, transform.bigInt(value)];
36
+ if (numberPropertyNames.some(k => k === key)) return [key, transform.number(value)];
37
+ return [key, _classPrivateMethodGet(this, _mapData, _mapData2).call(this, value, transform)];
38
+ });
39
+ }
40
+ return data;
41
+ }
42
+ function _encodeArg2(data) {
43
+ return _classPrivateMethodGet(this, _mapData, _mapData2).call(this, data, {
44
+ bigInt: value => {
45
+ if (value instanceof BigNumber) return value.toFixed();
46
+ return value.toString();
47
+ },
48
+ number: value => value.toString()
49
+ });
50
+ }
51
+ function _decodeRes2(data) {
52
+ return _classPrivateMethodGet(this, _mapData, _mapData2).call(this, data, {
53
+ bigInt: value => BigInt(value),
54
+ number: value => +value
55
+ });
56
+ }
57
+ export default class Middleware extends MiddlewareTransformed {
58
+ /**
59
+ * @param url - Url for middleware API
60
+ * @param options - Options
61
+ * @param options.ignoreVersion - Don't check node version
62
+ * @param options.retryCount - Amount of extra requests to do in case of failure
63
+ * @param options.retryOverallDelay - Time in ms to wait between all retries
64
+ */
65
+ constructor(url) {
66
+ let {
67
+ ignoreVersion = false,
68
+ retryCount = 3,
69
+ retryOverallDelay = 800,
70
+ ...options
71
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
72
+ // eslint-disable-next-line constructor-super
73
+ super(url, {
74
+ allowInsecureConnection: true,
75
+ additionalPolicies: [genRequestQueuesPolicy(), genCombineGetRequestsPolicy(), genRetryOnFailurePolicy(retryCount, retryOverallDelay), genErrorFormatterPolicy(body => ` ${body.error}`)],
76
+ ...options
77
+ });
78
+ if (!ignoreVersion) {
79
+ const statusPromise = this.getStatus();
80
+ const versionPromise = statusPromise.then(_ref2 => {
81
+ let {
82
+ mdwVersion
83
+ } = _ref2;
84
+ return mdwVersion;
85
+ }, error => error);
86
+ this.pipeline.addPolicy(genVersionCheckPolicy('middleware', '/v2/status', versionPromise, '1.47.0', '2.0.0'));
87
+ }
88
+ }
89
+ }
90
+ //# sourceMappingURL=Middleware.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Middleware.mjs","names":["BigNumber","genRequestQueuesPolicy","genCombineGetRequestsPolicy","genErrorFormatterPolicy","genVersionCheckPolicy","genRetryOnFailurePolicy","Middleware","MiddlewareApi","mapObject","bigIntPropertyNames","numberPropertyNames","_mapData","WeakSet","_encodeArg","_decodeRes","MiddlewareTransformed","constructor","arguments","_classPrivateMethodInitSpec","sendOperationRequest","operationArguments","operationSpec","args","_ref","key","value","_classPrivateMethodGet","_encodeArg2","call","_decodeRes2","_mapData2","data","transform","Array","isArray","map","d","_ref3","some","k","bigInt","number","toFixed","toString","BigInt","url","ignoreVersion","retryCount","retryOverallDelay","options","length","undefined","allowInsecureConnection","additionalPolicies","body","error","statusPromise","getStatus","versionPromise","then","_ref2","mdwVersion","pipeline","addPolicy"],"sources":["../src/Middleware.ts"],"sourcesContent":["// eslint-disable-next-line max-classes-per-file\nimport BigNumber from 'bignumber.js';\nimport { OperationArguments, OperationSpec } from '@azure/core-client';\nimport {\n genRequestQueuesPolicy, genCombineGetRequestsPolicy, genErrorFormatterPolicy,\n genVersionCheckPolicy, genRetryOnFailurePolicy,\n} from './utils/autorest';\nimport { Middleware as MiddlewareApi, MiddlewareOptionalParams, ErrorResponse } from './apis/middleware';\nimport { mapObject } from './utils/other';\nimport { Encoded } from './utils/encoder';\nimport { ConsensusProtocolVersion } from './tx/builder/constants';\n\nconst bigIntPropertyNames = [] as const;\n\nconst numberPropertyNames = [] as const;\n\nclass MiddlewareTransformed extends MiddlewareApi {\n override async sendOperationRequest(\n operationArguments: OperationArguments,\n operationSpec: OperationSpec,\n ): Promise<any> {\n const args = mapObject(\n operationArguments,\n ([key, value]) => [key, this.#encodeArg(value)],\n ) as OperationArguments;\n return this.#decodeRes(await super.sendOperationRequest(args, operationSpec));\n }\n\n #mapData(data: any, transform: {\n bigInt: (v: any) => any;\n number: (v: any) => any;\n }): unknown {\n if (Array.isArray(data)) return data.map((d) => this.#mapData(d, transform));\n if (data != null && typeof data === 'object') {\n return mapObject(data, ([key, value]) => {\n if (value == null) return [key, value];\n if (bigIntPropertyNames.some((k) => k === key)) return [key, transform.bigInt(value)];\n if (numberPropertyNames.some((k) => k === key)) return [key, transform.number(value)];\n return [key, this.#mapData(value, transform)];\n });\n }\n return data;\n }\n\n #encodeArg(data: any): any {\n return this.#mapData(data, {\n bigInt: (value) => {\n if (value instanceof BigNumber) return value.toFixed();\n return value.toString();\n },\n number: (value) => value.toString(),\n });\n }\n\n #decodeRes(data: any): any {\n return this.#mapData(data, {\n bigInt: (value) => BigInt(value),\n number: (value) => +value,\n });\n }\n}\n\ntype BigIntPropertyNames = typeof bigIntPropertyNames[number];\ntype NumberPropertyNames = typeof numberPropertyNames[number];\ntype PreserveOptional<NewType, OrigType> =\n OrigType extends undefined ? NewType | undefined : NewType;\nexport type TransformMiddlewareType<Type> =\n Type extends (...args: infer Args) => infer Ret\n ? (...args: TransformMiddlewareType<Args>) => TransformMiddlewareType<Ret>\n : Type extends [infer Item, ...infer Rest]\n ? [TransformMiddlewareType<Item>, ...TransformMiddlewareType<Rest>]\n : Type extends Array<infer Item>\n ? Array<TransformMiddlewareType<Item>>\n : Type extends Promise<infer T>\n ? Promise<TransformMiddlewareType<T>>\n : Type extends { [P in any]: any }\n ? {\n [Property in keyof Type]:\n Property extends BigIntPropertyNames\n ? PreserveOptional<bigint, Type[Property]>\n : Property extends NumberPropertyNames\n ? PreserveOptional<number, Type[Property]>\n : Property extends 'txHash'\n ? PreserveOptional<Encoded.TxHash, Type[Property]>\n : Property extends 'bytecode'\n ? PreserveOptional<Encoded.ContractBytearray, Type[Property]>\n : TransformMiddlewareType<Type[Property]>\n }\n : Type;\ntype MiddlewareTransformedApi = new (...args: ConstructorParameters<typeof MiddlewareApi>) => {\n [Name in keyof InstanceType<typeof MiddlewareApi>]:\n Name extends 'pipeline' | 'sendRequest' | 'sendOperationRequest'\n ? MiddlewareApi[Name] : TransformMiddlewareType<MiddlewareApi[Name]>\n};\n\nexport interface MiddlewareInfo {\n url: string;\n nodeNetworkId: string;\n version: string;\n consensusProtocolVersion: ConsensusProtocolVersion;\n}\n\nexport default class Middleware\n extends (MiddlewareTransformed as unknown as MiddlewareTransformedApi) {\n /**\n * @param url - Url for middleware API\n * @param options - Options\n * @param options.ignoreVersion - Don't check node version\n * @param options.retryCount - Amount of extra requests to do in case of failure\n * @param options.retryOverallDelay - Time in ms to wait between all retries\n */\n constructor(\n url: string,\n {\n ignoreVersion = false, retryCount = 3, retryOverallDelay = 800, ...options\n }: MiddlewareOptionalParams & {\n ignoreVersion?: boolean;\n retryCount?: number;\n retryOverallDelay?: number;\n } = {},\n ) {\n // eslint-disable-next-line constructor-super\n super(url, {\n allowInsecureConnection: true,\n additionalPolicies: [\n genRequestQueuesPolicy(),\n genCombineGetRequestsPolicy(),\n genRetryOnFailurePolicy(retryCount, retryOverallDelay),\n genErrorFormatterPolicy((body: ErrorResponse) => ` ${body.error}`),\n ],\n ...options,\n });\n if (!ignoreVersion) {\n const statusPromise = this.getStatus();\n const versionPromise = statusPromise.then(({ mdwVersion }) => mdwVersion, (error) => error);\n this.pipeline.addPolicy(\n genVersionCheckPolicy('middleware', '/v2/status', versionPromise, '1.47.0', '2.0.0'),\n );\n }\n }\n}\n"],"mappings":";;;AAAA;AACA,OAAOA,SAAS,MAAM,cAAc;AAAC,SAGnCC,sBAAsB,EAAEC,2BAA2B,EAAEC,uBAAuB,EAC5EC,qBAAqB,EAAEC,uBAAuB;AAAA,SAEvCC,UAAU,IAAIC,aAAa;AAAA,SAC3BC,SAAS;AAIlB,MAAMC,mBAAmB,GAAG,EAAW;AAEvC,MAAMC,mBAAmB,GAAG,EAAW;AAAC,IAAAC,QAAA,oBAAAC,OAAA;AAAA,IAAAC,UAAA,oBAAAD,OAAA;AAAA,IAAAE,UAAA,oBAAAF,OAAA;AAExC,MAAMG,qBAAqB,SAASR,aAAa,CAAC;EAAAS,YAAA;IAAA,SAAAC,SAAA;IAAAC,2BAAA,OAAAJ,UAAA;IAAAI,2BAAA,OAAAL,UAAA;IAAAK,2BAAA,OAAAP,QAAA;EAAA;EAChD,MAAeQ,oBAAoBA,CACjCC,kBAAsC,EACtCC,aAA4B,EACd;IACd,MAAMC,IAAI,GAAGd,SAAS,CACpBY,kBAAkB,EAClBG,IAAA;MAAA,IAAC,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;MAAA,OAAK,CAACC,GAAG,EAAAE,sBAAA,CAAE,IAAI,EAAAb,UAAA,EAAAc,WAAA,EAAAC,IAAA,CAAJ,IAA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C,CACnE;MACD,GAAGN;IACL,CAAC,CAAC;IACF,IAAI,CAACH,aAAa,EAAE;MAClB,MAAMU,aAAa,GAAG,IAAI,CAACC,SAAS,CAAC,CAAC;MACtC,MAAMC,cAAc,GAAGF,aAAa,CAACG,IAAI,CAACC,KAAA;QAAA,IAAC;UAAEC;QAAW,CAAC,GAAAD,KAAA;QAAA,OAAKC,UAAU;MAAA,GAAGN,KAAK,IAAKA,KAAK,CAAC;MAC3F,IAAI,CAACO,QAAQ,CAACC,SAAS,CACrB3D,qBAAqB,CAAC,YAAY,EAAE,YAAY,EAAEsD,cAAc,EAAE,QAAQ,EAAE,OAAO,CACrF,CAAC;IACH;EACF;AACF"}
@@ -0,0 +1,30 @@
1
+ /// <reference types="ws" />
2
+ import WebSocket from 'isomorphic-ws';
3
+ import { BaseError } from './utils/errors';
4
+ import { Encoded } from './utils/encoder';
5
+ export declare class MiddlewareSubscriberError extends BaseError {
6
+ constructor(message: string);
7
+ }
8
+ export declare class MiddlewareSubscriberDisconnected extends MiddlewareSubscriberError {
9
+ readonly closeEvent: WebSocket.CloseEvent;
10
+ constructor(closeEvent: WebSocket.CloseEvent);
11
+ }
12
+ export default class MiddlewareSubscriber {
13
+ #private;
14
+ readonly url: string;
15
+ get webSocket(): WebSocket | undefined;
16
+ constructor(url: string);
17
+ reconnect(): Promise<void>;
18
+ subscribeKeyBlocks(cb: (p?: any, e?: Error) => void): () => void;
19
+ subscribeKeyBlocksNode(cb: (p?: any, e?: Error) => void): () => void;
20
+ subscribeKeyBlocksAll(cb: (p?: any, e?: Error) => void): () => void;
21
+ subscribeMicroBlocks(cb: (p?: any, e?: Error) => void): () => void;
22
+ subscribeMicroBlocksNode(cb: (p?: any, e?: Error) => void): () => void;
23
+ subscribeMicroBlocksAll(cb: (p?: any, e?: Error) => void): () => void;
24
+ subscribeTransactions(cb: (p?: any, e?: Error) => void): () => void;
25
+ subscribeTransactionsNode(cb: (p?: any, e?: Error) => void): () => void;
26
+ subscribeTransactionsAll(cb: (p?: any, e?: Error) => void): () => void;
27
+ subscribeObject(target: Encoded.KeyBlockHash | Encoded.Channel | Encoded.ContractAddress | Encoded.OracleAddress | Encoded.OracleQueryId | Encoded.AccountAddress | Encoded.Name | `${string}.chain`, cb: (p?: any, e?: Error) => void): () => void;
28
+ subscribeObjectNode(target: Encoded.KeyBlockHash | Encoded.Channel | Encoded.ContractAddress | Encoded.OracleAddress | Encoded.OracleQueryId | Encoded.AccountAddress | Encoded.Name | `${string}.chain`, cb: (p?: any, e?: Error) => void): () => void;
29
+ subscribeObjectAll(target: Encoded.KeyBlockHash | Encoded.Channel | Encoded.ContractAddress | Encoded.OracleAddress | Encoded.OracleQueryId | Encoded.AccountAddress | Encoded.Name | `${string}.chain`, cb: (p?: any, e?: Error) => void): () => void;
30
+ }