@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
@@ -0,0 +1,198 @@
1
+ import _classPrivateFieldSet from "@babel/runtime-corejs3/helpers/classPrivateFieldSet";
2
+ import _classPrivateFieldGet from "@babel/runtime-corejs3/helpers/classPrivateFieldGet";
3
+ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
4
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
5
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
6
+ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
7
+ /* eslint-disable max-classes-per-file */
8
+ import WebSocket from 'isomorphic-ws';
9
+ import { BaseError, UnexpectedTsError, InternalError } from "./utils/errors.mjs";
10
+ var Source = /*#__PURE__*/function (Source) {
11
+ Source["Middleware"] = "mdw";
12
+ Source["Node"] = "node";
13
+ Source["All"] = "all";
14
+ return Source;
15
+ }(Source || {});
16
+ export class MiddlewareSubscriberError extends BaseError {
17
+ constructor(message) {
18
+ super(message);
19
+ this.name = 'MiddlewareSubscriberError';
20
+ }
21
+ }
22
+ export class MiddlewareSubscriberDisconnected extends MiddlewareSubscriberError {
23
+ constructor(closeEvent) {
24
+ super('Connection closed');
25
+ this.closeEvent = closeEvent;
26
+ this.name = 'MiddlewareSubscriberDisconnected';
27
+ }
28
+ }
29
+ var _subscriptions = /*#__PURE__*/new WeakMap();
30
+ var _requestQueue = /*#__PURE__*/new WeakMap();
31
+ var _webSocket = /*#__PURE__*/new WeakMap();
32
+ var _targets = /*#__PURE__*/new WeakMap();
33
+ var _sendMessage = /*#__PURE__*/new WeakSet();
34
+ var _sendSubscribe = /*#__PURE__*/new WeakSet();
35
+ var _emit = /*#__PURE__*/new WeakSet();
36
+ var _disconnect = /*#__PURE__*/new WeakSet();
37
+ var _messageHandler = /*#__PURE__*/new WeakSet();
38
+ var _subscribe = /*#__PURE__*/new WeakSet();
39
+ export default class MiddlewareSubscriber {
40
+ get webSocket() {
41
+ return _classPrivateFieldGet(this, _webSocket);
42
+ }
43
+ constructor(url) {
44
+ _classPrivateMethodInitSpec(this, _subscribe);
45
+ _classPrivateMethodInitSpec(this, _messageHandler);
46
+ _classPrivateMethodInitSpec(this, _disconnect);
47
+ _classPrivateMethodInitSpec(this, _emit);
48
+ _classPrivateMethodInitSpec(this, _sendSubscribe);
49
+ _classPrivateMethodInitSpec(this, _sendMessage);
50
+ _classPrivateFieldInitSpec(this, _targets, {
51
+ get: _get_targets,
52
+ set: void 0
53
+ });
54
+ _classPrivateFieldInitSpec(this, _subscriptions, {
55
+ writable: true,
56
+ value: []
57
+ });
58
+ _classPrivateFieldInitSpec(this, _requestQueue, {
59
+ writable: true,
60
+ value: []
61
+ });
62
+ _classPrivateFieldInitSpec(this, _webSocket, {
63
+ writable: true,
64
+ value: void 0
65
+ });
66
+ this.url = url;
67
+ }
68
+ async reconnect() {
69
+ _classPrivateMethodGet(this, _disconnect, _disconnect2).call(this);
70
+ _classPrivateFieldSet(this, _webSocket, await new Promise(resolve => {
71
+ const webSocket = new WebSocket(this.url);
72
+ Object.assign(webSocket, {
73
+ onopen: () => resolve(webSocket),
74
+ onerror: errorEvent => {
75
+ _classPrivateMethodGet(this, _emit, _emit2).call(this, () => true, undefined, errorEvent.error);
76
+ },
77
+ onmessage: event => {
78
+ if (typeof event.data !== 'string') {
79
+ throw new InternalError(`Unknown incoming message type: ${typeof event.data}`);
80
+ }
81
+ _classPrivateMethodGet(this, _messageHandler, _messageHandler2).call(this, JSON.parse(event.data));
82
+ },
83
+ onclose: event => {
84
+ _classPrivateMethodGet(this, _emit, _emit2).call(this, () => true, undefined, new MiddlewareSubscriberDisconnected(event));
85
+ _classPrivateMethodGet(this, _disconnect, _disconnect2).call(this, true);
86
+ }
87
+ });
88
+ }));
89
+ await Promise.all([..._classPrivateFieldGet(this, _targets)].map(target => _classPrivateMethodGet(this, _sendSubscribe, _sendSubscribe2).call(this, true, target)));
90
+ }
91
+ // TODO: replace p?: any with a proper type definition
92
+
93
+ subscribeKeyBlocks(cb) {
94
+ return _classPrivateMethodGet(this, _subscribe, _subscribe2).call(this, 'KeyBlocks', Source.Middleware, cb);
95
+ }
96
+ subscribeKeyBlocksNode(cb) {
97
+ return _classPrivateMethodGet(this, _subscribe, _subscribe2).call(this, 'KeyBlocks', Source.Node, cb);
98
+ }
99
+ subscribeKeyBlocksAll(cb) {
100
+ return _classPrivateMethodGet(this, _subscribe, _subscribe2).call(this, 'KeyBlocks', Source.All, cb);
101
+ }
102
+ subscribeMicroBlocks(cb) {
103
+ return _classPrivateMethodGet(this, _subscribe, _subscribe2).call(this, 'MicroBlocks', Source.Middleware, cb);
104
+ }
105
+ subscribeMicroBlocksNode(cb) {
106
+ return _classPrivateMethodGet(this, _subscribe, _subscribe2).call(this, 'MicroBlocks', Source.Node, cb);
107
+ }
108
+ subscribeMicroBlocksAll(cb) {
109
+ return _classPrivateMethodGet(this, _subscribe, _subscribe2).call(this, 'MicroBlocks', Source.All, cb);
110
+ }
111
+ subscribeTransactions(cb) {
112
+ return _classPrivateMethodGet(this, _subscribe, _subscribe2).call(this, 'Transactions', Source.Middleware, cb);
113
+ }
114
+ subscribeTransactionsNode(cb) {
115
+ return _classPrivateMethodGet(this, _subscribe, _subscribe2).call(this, 'Transactions', Source.Node, cb);
116
+ }
117
+ subscribeTransactionsAll(cb) {
118
+ return _classPrivateMethodGet(this, _subscribe, _subscribe2).call(this, 'Transactions', Source.All, cb);
119
+ }
120
+ subscribeObject(target, cb) {
121
+ return _classPrivateMethodGet(this, _subscribe, _subscribe2).call(this, target, Source.Middleware, cb);
122
+ }
123
+ subscribeObjectNode(target, cb) {
124
+ return _classPrivateMethodGet(this, _subscribe, _subscribe2).call(this, target, Source.Node, cb);
125
+ }
126
+ subscribeObjectAll(target, cb) {
127
+ return _classPrivateMethodGet(this, _subscribe, _subscribe2).call(this, target, Source.All, cb);
128
+ }
129
+ }
130
+ function _get_targets() {
131
+ return new Set(_classPrivateFieldGet(this, _subscriptions).map(_ref => {
132
+ let [target] = _ref;
133
+ return target;
134
+ }));
135
+ }
136
+ function _sendMessage2(message) {
137
+ if (_classPrivateFieldGet(this, _webSocket) == null) throw new UnexpectedTsError();
138
+ _classPrivateFieldGet(this, _webSocket).send(JSON.stringify(message));
139
+ }
140
+ function _sendSubscribe2(isSubscribe, target) {
141
+ if (_classPrivateFieldGet(this, _webSocket) == null) return;
142
+ const payload = ['KeyBlocks', 'MicroBlocks', 'Transactions'].includes(target) ? target : 'Object';
143
+ _classPrivateMethodGet(this, _sendMessage, _sendMessage2).call(this, {
144
+ op: isSubscribe ? 'Subscribe' : 'Unsubscribe',
145
+ payload,
146
+ ...(payload === 'Object' && {
147
+ target
148
+ })
149
+ });
150
+ _classPrivateFieldGet(this, _requestQueue).push([isSubscribe, target]);
151
+ }
152
+ function _emit2(condition, p, e) {
153
+ _classPrivateFieldGet(this, _subscriptions).filter(_ref2 => {
154
+ let [target, source] = _ref2;
155
+ return condition(target, source);
156
+ }).forEach(_ref3 => {
157
+ let [,, cb] = _ref3;
158
+ return cb(p, e);
159
+ });
160
+ }
161
+ function _disconnect2() {
162
+ let onlyReset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
163
+ if (_classPrivateFieldGet(this, _webSocket) == null) return;
164
+ if (!onlyReset) _classPrivateFieldGet(this, _webSocket).close();
165
+ Object.assign(_classPrivateFieldGet(this, _webSocket), {
166
+ onopen: undefined,
167
+ onerror: undefined,
168
+ onmessage: undefined
169
+ });
170
+ _classPrivateFieldSet(this, _webSocket, undefined);
171
+ }
172
+ function _messageHandler2(message) {
173
+ if (typeof message === 'string' || Array.isArray(message)) {
174
+ const request = _classPrivateFieldGet(this, _requestQueue).shift();
175
+ if (request == null) throw new InternalError('Request queue is empty');
176
+ const [isSubscribe, target] = request;
177
+ let error;
178
+ if (typeof message === 'string') error = new MiddlewareSubscriberError(message);
179
+ if (message.includes(target) !== isSubscribe) {
180
+ error = new InternalError(`Expected ${target} to be${isSubscribe ? '' : ' not'} included into ${message}`);
181
+ }
182
+ if (error != null) _classPrivateMethodGet(this, _emit, _emit2).call(this, t => target === t, undefined, error);
183
+ return;
184
+ }
185
+ _classPrivateMethodGet(this, _emit, _emit2).call(this, (target, source) => (target === message.subscription || target === message.target) && (source === message.source || source === Source.All), message.payload);
186
+ }
187
+ function _subscribe2(target, source, cb) {
188
+ const subscription = [target, source, cb];
189
+ if (_classPrivateFieldGet(this, _targets).size === 0) this.reconnect();
190
+ if (!_classPrivateFieldGet(this, _targets).has(target)) _classPrivateMethodGet(this, _sendSubscribe, _sendSubscribe2).call(this, true, target);
191
+ _classPrivateFieldGet(this, _subscriptions).push(subscription);
192
+ return () => {
193
+ _classPrivateFieldSet(this, _subscriptions, _classPrivateFieldGet(this, _subscriptions).filter(item => item !== subscription));
194
+ if (!_classPrivateFieldGet(this, _targets).has(target)) _classPrivateMethodGet(this, _sendSubscribe, _sendSubscribe2).call(this, false, target);
195
+ if (_classPrivateFieldGet(this, _targets).size === 0) _classPrivateMethodGet(this, _disconnect, _disconnect2).call(this);
196
+ };
197
+ }
198
+ //# sourceMappingURL=MiddlewareSubscriber.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MiddlewareSubscriber.mjs","names":["WebSocket","BaseError","UnexpectedTsError","InternalError","Source","MiddlewareSubscriberError","constructor","message","name","MiddlewareSubscriberDisconnected","closeEvent","_subscriptions","WeakMap","_requestQueue","_webSocket","_targets","_sendMessage","WeakSet","_sendSubscribe","_emit","_disconnect","_messageHandler","_subscribe","MiddlewareSubscriber","webSocket","_classPrivateFieldGet","url","_classPrivateMethodInitSpec","_classPrivateFieldInitSpec","get","_get_targets","set","writable","value","reconnect","_classPrivateMethodGet","_disconnect2","call","_classPrivateFieldSet","Promise","resolve","Object","assign","onopen","onerror","errorEvent","_emit2","undefined","error","onmessage","event","data","_messageHandler2","JSON","parse","onclose","all","map","target","_sendSubscribe2","subscribeKeyBlocks","cb","_subscribe2","Middleware","subscribeKeyBlocksNode","Node","subscribeKeyBlocksAll","All","subscribeMicroBlocks","subscribeMicroBlocksNode","subscribeMicroBlocksAll","subscribeTransactions","subscribeTransactionsNode","subscribeTransactionsAll","subscribeObject","subscribeObjectNode","subscribeObjectAll","Set","_ref","_sendMessage2","send","stringify","isSubscribe","payload","includes","op","push","condition","p","e","filter","_ref2","source","forEach","_ref3","onlyReset","arguments","length","close","Array","isArray","request","shift","t","subscription","size","has","item"],"sources":["../src/MiddlewareSubscriber.ts"],"sourcesContent":["/* eslint-disable max-classes-per-file */\nimport WebSocket from 'isomorphic-ws';\nimport { BaseError, UnexpectedTsError, InternalError } from './utils/errors';\nimport { Encoded } from './utils/encoder';\n\ninterface Message {\n payload: Object;\n source: Source.Middleware | Source.Node;\n subscription: 'KeyBlocks' | 'MicroBlocks' | 'Transactions' | 'Object';\n target?: string;\n}\n\nenum Source {\n Middleware = 'mdw',\n Node = 'node',\n All = 'all',\n}\n\nexport class MiddlewareSubscriberError extends BaseError {\n constructor(message: string) {\n super(message);\n this.name = 'MiddlewareSubscriberError';\n }\n}\n\nexport class MiddlewareSubscriberDisconnected extends MiddlewareSubscriberError {\n constructor(readonly closeEvent: WebSocket.CloseEvent) {\n super('Connection closed');\n this.name = 'MiddlewareSubscriberDisconnected';\n }\n}\n\nexport default class MiddlewareSubscriber {\n #subscriptions: Array<\n readonly [target: string, s: Source, cb: (p?: Object, e?: Error) => void]\n > = [];\n\n #requestQueue: Array<[isSubscribe: boolean, target: string]> = [];\n\n #webSocket?: WebSocket;\n\n get webSocket(): WebSocket | undefined {\n return this.#webSocket;\n }\n\n get #targets(): Set<string> {\n return new Set(this.#subscriptions.map(([target]) => target));\n }\n\n #sendMessage(message: any): void {\n if (this.#webSocket == null) throw new UnexpectedTsError();\n this.#webSocket.send(JSON.stringify(message));\n }\n\n #sendSubscribe(isSubscribe: boolean, target: string): void {\n if (this.#webSocket == null) return;\n const payload = ['KeyBlocks', 'MicroBlocks', 'Transactions'].includes(target)\n ? target : 'Object';\n this.#sendMessage({\n op: isSubscribe ? 'Subscribe' : 'Unsubscribe',\n payload,\n ...payload === 'Object' && { target },\n });\n this.#requestQueue.push([isSubscribe, target]);\n }\n\n #emit(condition: (target: string, source: Source) => boolean, p?: Object, e?: Error): void {\n this.#subscriptions\n .filter(([target, source]) => condition(target, source))\n .forEach(([, , cb]) => cb(p, e));\n }\n\n constructor(readonly url: string) {\n }\n\n #disconnect(onlyReset = false): void {\n if (this.#webSocket == null) return;\n if (!onlyReset) this.#webSocket.close();\n Object.assign(this.#webSocket, {\n onopen: undefined,\n onerror: undefined,\n onmessage: undefined,\n });\n this.#webSocket = undefined;\n }\n\n async reconnect(): Promise<void> {\n this.#disconnect();\n this.#webSocket = await new Promise((resolve) => {\n const webSocket = new WebSocket(this.url);\n Object.assign(webSocket, {\n onopen: () => resolve(webSocket),\n onerror: (errorEvent: WebSocket.ErrorEvent) => {\n this.#emit(() => true, undefined, errorEvent.error);\n },\n onmessage: (event: WebSocket.MessageEvent) => {\n if (typeof event.data !== 'string') {\n throw new InternalError(`Unknown incoming message type: ${typeof event.data}`);\n }\n this.#messageHandler(JSON.parse(event.data));\n },\n onclose: (event: WebSocket.CloseEvent) => {\n this.#emit(() => true, undefined, new MiddlewareSubscriberDisconnected(event));\n this.#disconnect(true);\n },\n });\n });\n await Promise.all([...this.#targets].map((target) => this.#sendSubscribe(true, target)));\n }\n\n #messageHandler(message: string | string[] | Message): void {\n if (typeof message === 'string' || Array.isArray(message)) {\n const request = this.#requestQueue.shift();\n if (request == null) throw new InternalError('Request queue is empty');\n const [isSubscribe, target] = request;\n let error;\n if (typeof message === 'string') error = new MiddlewareSubscriberError(message);\n if (message.includes(target) !== isSubscribe) {\n error = new InternalError(`Expected ${target} to be${isSubscribe ? '' : ' not'} included into ${message}`);\n }\n if (error != null) this.#emit((t) => target === t, undefined, error);\n return;\n }\n this.#emit(\n (target, source) => (target === message.subscription || target === message.target)\n && (source === message.source || source === Source.All),\n message.payload,\n );\n }\n\n #subscribe(target: string, source: Source, cb: (p?: Object, e?: Error) => void): () => void {\n const subscription = [target, source, cb] as const;\n if (this.#targets.size === 0) this.reconnect();\n if (!this.#targets.has(target)) this.#sendSubscribe(true, target);\n this.#subscriptions.push(subscription);\n return () => {\n this.#subscriptions = this.#subscriptions.filter((item) => item !== subscription);\n if (!this.#targets.has(target)) this.#sendSubscribe(false, target);\n if (this.#targets.size === 0) this.#disconnect();\n };\n }\n\n // TODO: replace p?: any with a proper type definition\n\n subscribeKeyBlocks(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('KeyBlocks', Source.Middleware, cb);\n }\n\n subscribeKeyBlocksNode(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('KeyBlocks', Source.Node, cb);\n }\n\n subscribeKeyBlocksAll(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('KeyBlocks', Source.All, cb);\n }\n\n subscribeMicroBlocks(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('MicroBlocks', Source.Middleware, cb);\n }\n\n subscribeMicroBlocksNode(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('MicroBlocks', Source.Node, cb);\n }\n\n subscribeMicroBlocksAll(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('MicroBlocks', Source.All, cb);\n }\n\n subscribeTransactions(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('Transactions', Source.Middleware, cb);\n }\n\n subscribeTransactionsNode(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('Transactions', Source.Node, cb);\n }\n\n subscribeTransactionsAll(cb: (p?: any, e?: Error) => void): () => void {\n return this.#subscribe('Transactions', Source.All, cb);\n }\n\n subscribeObject(\n target: Encoded.KeyBlockHash | Encoded.Channel | Encoded.ContractAddress\n | Encoded.OracleAddress | Encoded.OracleQueryId | Encoded.AccountAddress\n | Encoded.Name | `${string}.chain`,\n cb: (p?: any, e?: Error) => void,\n ): () => void {\n return this.#subscribe(target, Source.Middleware, cb);\n }\n\n subscribeObjectNode(\n target: Encoded.KeyBlockHash | Encoded.Channel | Encoded.ContractAddress\n | Encoded.OracleAddress | Encoded.OracleQueryId | Encoded.AccountAddress\n | Encoded.Name | `${string}.chain`,\n cb: (p?: any, e?: Error) => void,\n ): () => void {\n return this.#subscribe(target, Source.Node, cb);\n }\n\n subscribeObjectAll(\n target: Encoded.KeyBlockHash | Encoded.Channel | Encoded.ContractAddress\n | Encoded.OracleAddress | Encoded.OracleQueryId | Encoded.AccountAddress\n | Encoded.Name | `${string}.chain`,\n cb: (p?: any, e?: Error) => void,\n ): () => void {\n return this.#subscribe(target, Source.All, cb);\n }\n}\n"],"mappings":";;;;;;AAAA;AACA,OAAOA,SAAS,MAAM,eAAe;AAAC,SAC7BC,SAAS,EAAEC,iBAAiB,EAAEC,aAAa;AAAA,IAU/CC,MAAM,0BAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAAA,OAANA,MAAM;AAAA,EAANA,MAAM;AAMX,OAAO,MAAMC,yBAAyB,SAASJ,SAAS,CAAC;EACvDK,WAAWA,CAACC,OAAe,EAAE;IAC3B,KAAK,CAACA,OAAO,CAAC;IACd,IAAI,CAACC,IAAI,GAAG,2BAA2B;EACzC;AACF;AAEA,OAAO,MAAMC,gCAAgC,SAASJ,yBAAyB,CAAC;EAC9EC,WAAWA,CAAUI,UAAgC,EAAE;IACrD,KAAK,CAAC,mBAAmB,CAAC;IAAC,KADRA,UAAgC,GAAhCA,U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AAjB,cAAA,EAAAyC,eAAA,EAAAtB,IAAA,CAAJ,IAAI,EAAgB,KAAK,EAAEqB,MAAM;IACjE,IAAIjC,qBAAA,KAAI,EAAAV,QAAA,EAAU0F,IAAI,KAAK,CAAC,EAAEtE,sBAAA,KAAI,EAAAf,WAAA,EAAAgB,YAAA,EAAAC,IAAA,CAAJ,IAAI;EACpC,CAAC;AACH"}
package/es/Node.d.ts CHANGED
@@ -14,7 +14,7 @@ export type TransformNodeType<Type> = Type extends (...args: infer Args) => infe
14
14
  type NodeTransformedApi = new (...args: ConstructorParameters<typeof NodeApi>) => {
15
15
  [Name in keyof InstanceType<typeof NodeApi>]: Name extends 'pipeline' | 'sendRequest' | 'sendOperationRequest' ? NodeApi[Name] : TransformNodeType<NodeApi[Name]>;
16
16
  };
17
- export interface NodeInfo {
17
+ interface NodeInfo {
18
18
  url: string;
19
19
  nodeNetworkId: string;
20
20
  version: string;
package/es/Node.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Node.mjs","names":["BigNumber","genRequestQueuesPolicy","genCombineGetRequestsPolicy","genErrorFormatterPolicy","genVersionCheckPolicy","genRetryOnFailurePolicy","Node","NodeApi","mapObject","bigIntPropertyNames","numberPropertyNames","_mapData","WeakSet","_encodeArg","_decodeRes","NodeTransformed","constructor","arguments","_classPrivateMethodInitSpec","sendOperationRequest","operationArguments","operationSpec","args","_ref","key","value","_classPrivateMethodGet","_encodeArg2","call","_decodeRes2","_mapData2","data","transform","Array","isArray","map","d","_ref6","some","k","bigInt","number","toFixed","toString","BigInt","_networkIdPromise","WeakMap","url","ignoreVersion","retryCount","retryOverallDelay","options","length","undefined","allowInsecureConnection","additionalPolicies","body","reason","_classPrivateFieldInitSpec","writable","statusPromise","getStatus","versionPromise","then","_ref2","nodeVersion","error","_classPrivateFieldSet","_ref3","networkId","pipeline","addPolicy","intAsString","getNetworkId","_classPrivateFieldGet2","_classPrivateFieldGet","_ref4","Error","getNodeInfo","version","nodeNetworkId","protocols","topBlockHeight","consensusProtocolVersion","filter","_ref5","effectiveAtHeight","reduce","acc","p","$host"],"sources":["../src/Node.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 { Node as NodeApi, NodeOptionalParams, ErrorModel } from './apis/node';\nimport { mapObject } from './utils/other';\nimport { Encoded } from './utils/encoder';\nimport { ConsensusProtocolVersion } from './tx/builder/constants';\n\nconst bigIntPropertyNames = [\n 'balance', 'queryFee', 'fee', 'amount', 'nameFee', 'channelAmount',\n 'initiatorAmount', 'responderAmount', 'channelReserve', 'initiatorAmountFinal',\n 'responderAmountFinal', 'gasPrice', 'deposit',\n] as const;\n\nconst numberPropertyNames = [\n 'time', 'gas', 'gasUsed', 'nameSalt',\n 'nonce', 'nextNonce', 'height', 'blockHeight', 'topBlockHeight',\n 'ttl', 'nameTtl', 'clientTtl',\n 'inbound', 'outbound', 'peerCount', 'pendingTransactionsCount', 'effectiveAtHeight',\n 'version', 'solutions', 'round',\n] as const;\n\nclass NodeTransformed extends NodeApi {\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 TransformNodeType<Type> =\n Type extends (...args: infer Args) => infer Ret\n ? (...args: TransformNodeType<Args>) => TransformNodeType<Ret>\n : Type extends [infer Item, ...infer Rest]\n ? [TransformNodeType<Item>, ...TransformNodeType<Rest>]\n : Type extends Array<infer Item>\n ? Array<TransformNodeType<Item>>\n : Type extends Promise<infer T>\n ? Promise<TransformNodeType<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 : TransformNodeType<Type[Property]>\n }\n : Type;\ntype NodeTransformedApi = new (...args: ConstructorParameters<typeof NodeApi>) => {\n [Name in keyof InstanceType<typeof NodeApi>]:\n Name extends 'pipeline' | 'sendRequest' | 'sendOperationRequest'\n ? NodeApi[Name] : TransformNodeType<NodeApi[Name]>\n};\n\nexport interface NodeInfo {\n url: string;\n nodeNetworkId: string;\n version: string;\n consensusProtocolVersion: ConsensusProtocolVersion;\n}\n\nexport default class Node extends (NodeTransformed as unknown as NodeTransformedApi) {\n #networkIdPromise?: Promise<string | Error>;\n\n /**\n * @param url - Url for node 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 }: NodeOptionalParams & {\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: ErrorModel) => ` ${body.reason}`),\n ],\n ...options,\n });\n if (!ignoreVersion) {\n const statusPromise = this.getStatus();\n const versionPromise = statusPromise.then(({ nodeVersion }) => nodeVersion, (error) => error);\n this.#networkIdPromise = statusPromise.then(({ networkId }) => networkId, (error) => error);\n this.pipeline.addPolicy(\n genVersionCheckPolicy('node', '/v3/status', versionPromise, '6.2.0', '7.0.0'),\n );\n }\n this.intAsString = true;\n }\n\n async getNetworkId(): Promise<string> {\n this.#networkIdPromise ??= this.getStatus().then(({ networkId }) => networkId);\n const networkId = await this.#networkIdPromise;\n if (networkId instanceof Error) throw networkId;\n return networkId;\n }\n\n async getNodeInfo(): Promise<NodeInfo> {\n const {\n nodeVersion: version,\n networkId: nodeNetworkId,\n protocols,\n topBlockHeight,\n } = await this.getStatus();\n const consensusProtocolVersion = protocols\n .filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)\n .reduce(\n (acc, p) => (p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc),\n { effectiveAtHeight: -1, version: 0 },\n )\n .version;\n return {\n url: this.$host,\n nodeNetworkId,\n version,\n consensusProtocolVersion,\n };\n }\n}\n"],"mappings":";;;;;;AAAA;AACA,OAAOA,SAAS,MAAM,cAAc;AAAC,SAGnCC,sBAAsB,EAAEC,2BAA2B,EAAEC,uBAAuB,EAC5EC,qBAAqB,EAAEC,uBAAuB;AAAA,SAEvCC,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,IAAC;QAAEC;MAAkB,CAAC,GAAAD,KAAA;MAAA,OAAKH,cAAc,IAAII,iBAAiB;IAAA,EAAC,CACtEC,MAAM,CACL,CAACC,GAAG,EAAEC,CAAC,KAAMA,CAAC,CAACH,iBAAiB,GAAGE,GAAG,CAACF,iBAAiB,GAAGG,CAAC,GAAGD,GAAI,EACnE;MAAEF,iBAAiB,EAAE,CAAC,CAAC;MAAEP,OAAO,EAAE;IAAE,CAAC,CACtC,CACAA,OAAO;IACV,OAAO;MACLhC,GAAG,EAAE,IAAI,CAAC2C,KAAK;MACfV,aAAa;MACbD,OAAO;MACPI;IACF,CAAC;EACH;AACF"}
1
+ {"version":3,"file":"Node.mjs","names":["BigNumber","genRequestQueuesPolicy","genCombineGetRequestsPolicy","genErrorFormatterPolicy","genVersionCheckPolicy","genRetryOnFailurePolicy","Node","NodeApi","mapObject","bigIntPropertyNames","numberPropertyNames","_mapData","WeakSet","_encodeArg","_decodeRes","NodeTransformed","constructor","arguments","_classPrivateMethodInitSpec","sendOperationRequest","operationArguments","operationSpec","args","_ref","key","value","_classPrivateMethodGet","_encodeArg2","call","_decodeRes2","_mapData2","data","transform","Array","isArray","map","d","_ref6","some","k","bigInt","number","toFixed","toString","BigInt","_networkIdPromise","WeakMap","url","ignoreVersion","retryCount","retryOverallDelay","options","length","undefined","allowInsecureConnection","additionalPolicies","body","reason","_classPrivateFieldInitSpec","writable","statusPromise","getStatus","versionPromise","then","_ref2","nodeVersion","error","_classPrivateFieldSet","_ref3","networkId","pipeline","addPolicy","intAsString","getNetworkId","_classPrivateFieldGet2","_classPrivateFieldGet","_ref4","Error","getNodeInfo","version","nodeNetworkId","protocols","topBlockHeight","consensusProtocolVersion","filter","_ref5","effectiveAtHeight","reduce","acc","p","$host"],"sources":["../src/Node.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 { Node as NodeApi, NodeOptionalParams, ErrorModel } from './apis/node';\nimport { mapObject } from './utils/other';\nimport { Encoded } from './utils/encoder';\nimport { ConsensusProtocolVersion } from './tx/builder/constants';\n\nconst bigIntPropertyNames = [\n 'balance', 'queryFee', 'fee', 'amount', 'nameFee', 'channelAmount',\n 'initiatorAmount', 'responderAmount', 'channelReserve', 'initiatorAmountFinal',\n 'responderAmountFinal', 'gasPrice', 'deposit',\n] as const;\n\nconst numberPropertyNames = [\n 'time', 'gas', 'gasUsed', 'nameSalt',\n 'nonce', 'nextNonce', 'height', 'blockHeight', 'topBlockHeight',\n 'ttl', 'nameTtl', 'clientTtl',\n 'inbound', 'outbound', 'peerCount', 'pendingTransactionsCount', 'effectiveAtHeight',\n 'version', 'solutions', 'round',\n] as const;\n\nclass NodeTransformed extends NodeApi {\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 TransformNodeType<Type> =\n Type extends (...args: infer Args) => infer Ret\n ? (...args: TransformNodeType<Args>) => TransformNodeType<Ret>\n : Type extends [infer Item, ...infer Rest]\n ? [TransformNodeType<Item>, ...TransformNodeType<Rest>]\n : Type extends Array<infer Item>\n ? Array<TransformNodeType<Item>>\n : Type extends Promise<infer T>\n ? Promise<TransformNodeType<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 : TransformNodeType<Type[Property]>\n }\n : Type;\ntype NodeTransformedApi = new (...args: ConstructorParameters<typeof NodeApi>) => {\n [Name in keyof InstanceType<typeof NodeApi>]:\n Name extends 'pipeline' | 'sendRequest' | 'sendOperationRequest'\n ? NodeApi[Name] : TransformNodeType<NodeApi[Name]>\n};\n\ninterface NodeInfo {\n url: string;\n nodeNetworkId: string;\n version: string;\n consensusProtocolVersion: ConsensusProtocolVersion;\n}\n\nexport default class Node extends (NodeTransformed as unknown as NodeTransformedApi) {\n #networkIdPromise?: Promise<string | Error>;\n\n /**\n * @param url - Url for node 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 }: NodeOptionalParams & {\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: ErrorModel) => ` ${body.reason}`),\n ],\n ...options,\n });\n if (!ignoreVersion) {\n const statusPromise = this.getStatus();\n const versionPromise = statusPromise.then(({ nodeVersion }) => nodeVersion, (error) => error);\n this.#networkIdPromise = statusPromise.then(({ networkId }) => networkId, (error) => error);\n this.pipeline.addPolicy(\n genVersionCheckPolicy('node', '/v3/status', versionPromise, '6.2.0', '7.0.0'),\n );\n }\n this.intAsString = true;\n }\n\n async getNetworkId(): Promise<string> {\n this.#networkIdPromise ??= this.getStatus().then(({ networkId }) => networkId);\n const networkId = await this.#networkIdPromise;\n if (networkId instanceof Error) throw networkId;\n return networkId;\n }\n\n async getNodeInfo(): Promise<NodeInfo> {\n const {\n nodeVersion: version,\n networkId: nodeNetworkId,\n protocols,\n topBlockHeight,\n } = await this.getStatus();\n const consensusProtocolVersion = protocols\n .filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)\n .reduce(\n (acc, p) => (p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc),\n { effectiveAtHeight: -1, version: 0 },\n )\n .version;\n return {\n url: this.$host,\n nodeNetworkId,\n version,\n consensusProtocolVersion,\n };\n }\n}\n"],"mappings":";;;;;;AAAA;AACA,OAAOA,SAAS,MAAM,cAAc;AAAC,SAGnCC,sBAAsB,EAAEC,2BAA2B,EAAEC,uBAAuB,EAC5EC,qBAAqB,EAAEC,uBAAuB;AAAA,SAEvCC,IAAI,IAAIC,OAAO;AAAA,SACfC,SAAS;AAIlB,MAAMC,mBAAmB,GAAG,CAC1B,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAClE,iBAAiB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,sBAAsB,EAC9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iBAAiB,GAAGE,GAAG,CAACF,iBAAiB,GAAGG,CAAC,GAAGD,GAAI,EACnE;MAAEF,iBAAiB,EAAE,CAAC,CAAC;MAAEP,OAAO,EAAE;IAAE,CACtC,CAAC,CACAA,OAAO;IACV,OAAO;MACLhC,GAAG,EAAE,IAAI,CAAC2C,KAAK;MACfV,aAAa;MACbD,OAAO;MACPI;IACF,CAAC;EACH;AACF"}
@@ -1,7 +1,8 @@
1
1
  import { Encoded } from '../utils/encoder';
2
2
  import Node from '../Node';
3
3
  import CompilerBase from '../contract/compiler/Base';
4
- import { Int } from '../tx/builder/constants';
4
+ import { AensName, Int } from '../tx/builder/constants';
5
+ import { AciValue, Domain } from '../utils/typed-data';
5
6
  interface AuthData {
6
7
  fee?: Int;
7
8
  gasLimit?: number;
@@ -36,17 +37,70 @@ export default abstract class AccountBase {
36
37
  * Sign message
37
38
  * @param message - Message to sign
38
39
  * @param options - Options
39
- * @returns Signature as hex string of Uint8Array
40
+ * @returns Signature
40
41
  */
41
42
  abstract signMessage(message: string, options?: {
42
43
  aeppOrigin?: string;
43
44
  aeppRpcClientId?: string;
44
45
  }): Promise<Uint8Array>;
46
+ /**
47
+ * Sign typed data
48
+ * @param type - Type of data to sign
49
+ * @param data - Encoded data to sign
50
+ * @param options - Options
51
+ * @returns Signature
52
+ */
53
+ signTypedData(data: Encoded.ContractBytearray, aci: AciValue, options?: Domain & {
54
+ aeppOrigin?: string;
55
+ aeppRpcClientId?: string;
56
+ }): Promise<Encoded.Signature>;
57
+ /**
58
+ * Sign delegation of AENS, oracle operations to a contract
59
+ * @param contractAddress - Address of a contract to delegate permissions to
60
+ * @param options - Options
61
+ * @returns Signature
62
+ */
63
+ signDelegationToContract(contractAddress: Encoded.ContractAddress, options?: {
64
+ networkId?: string;
65
+ aeppOrigin?: string;
66
+ aeppRpcClientId?: string;
67
+ }): Promise<Encoded.Signature>;
68
+ /**
69
+ * Sign delegation of an AENS name to a contract
70
+ * @param contractAddress - Address of a contract to delegate permissions to
71
+ * @param name - AENS name to manage by a contract
72
+ * @param options - Options
73
+ * @returns Signature
74
+ */
75
+ signNameDelegationToContract(contractAddress: Encoded.ContractAddress, name: AensName, options?: {
76
+ networkId?: string;
77
+ aeppOrigin?: string;
78
+ aeppRpcClientId?: string;
79
+ }): Promise<Encoded.Signature>;
80
+ /**
81
+ * Sign delegation of oracle query to a contract
82
+ *
83
+ * Warning! Implementations needs to ensure that decoded oracle query id is not equal to decoded
84
+ * current account address unless https://github.com/aeternity/aesophia/issues/475 is fixed.
85
+ *
86
+ * Warning! Implementations needs to ensure that oracle query and contract exists unless
87
+ * https://github.com/aeternity/aesophia/issues/474 is fixed.
88
+ *
89
+ * @param contractAddress - Address of a contract to delegate permissions to
90
+ * @param oracleQueryId - Oracle query ID to reply by a contract
91
+ * @param options - Options
92
+ * @returns Signature
93
+ */
94
+ signOracleQueryDelegationToContract(contractAddress: Encoded.ContractAddress, oracleQueryId: Encoded.OracleQueryId, options?: {
95
+ networkId?: string;
96
+ aeppOrigin?: string;
97
+ aeppRpcClientId?: string;
98
+ }): Promise<Encoded.Signature>;
45
99
  /**
46
100
  * Sign data blob
47
101
  * @param data - Data blob to sign
48
102
  * @param options - Options
49
- * @returns Signed data blob
103
+ * @returns Signature
50
104
  */
51
105
  abstract sign(data: string | Uint8Array, options?: any): Promise<Uint8Array>;
52
106
  /**
@@ -1,6 +1,100 @@
1
+ import { NotImplementedError } from "../utils/errors.mjs";
1
2
  /**
2
3
  * Account is one of the three basic building blocks of an
3
4
  * {@link AeSdk} and provides access to a signing key pair.
4
5
  */
5
- export default class AccountBase {}
6
+ export default class AccountBase {
7
+ /**
8
+ * Sign encoded transaction
9
+ * @param tx - Transaction to sign
10
+ * @param options - Options
11
+ * @param options.innerTx - Sign as inner transaction for PayingFor
12
+ * @param options.authData - Object with gaMeta params
13
+ * @returns Signed transaction
14
+ */
15
+
16
+ /**
17
+ * Sign message
18
+ * @param message - Message to sign
19
+ * @param options - Options
20
+ * @returns Signature
21
+ */
22
+
23
+ /**
24
+ * Sign typed data
25
+ * @param type - Type of data to sign
26
+ * @param data - Encoded data to sign
27
+ * @param options - Options
28
+ * @returns Signature
29
+ */
30
+ // TODO: make abstract in the next major release
31
+ // eslint-disable-next-line class-methods-use-this
32
+ async signTypedData( /* eslint-disable @typescript-eslint/no-unused-vars */
33
+ data, aci, options
34
+ /* eslint-enable @typescript-eslint/no-unused-vars */) {
35
+ throw new NotImplementedError('signTypedData method');
36
+ }
37
+
38
+ /**
39
+ * Sign delegation of AENS, oracle operations to a contract
40
+ * @param contractAddress - Address of a contract to delegate permissions to
41
+ * @param options - Options
42
+ * @returns Signature
43
+ */
44
+ // TODO: make abstract in the next major release
45
+ // eslint-disable-next-line class-methods-use-this
46
+ async signDelegationToContract( /* eslint-disable @typescript-eslint/no-unused-vars */
47
+ contractAddress, options
48
+ /* eslint-enable @typescript-eslint/no-unused-vars */) {
49
+ throw new NotImplementedError('signDelegationToContract method');
50
+ }
51
+
52
+ /**
53
+ * Sign delegation of an AENS name to a contract
54
+ * @param contractAddress - Address of a contract to delegate permissions to
55
+ * @param name - AENS name to manage by a contract
56
+ * @param options - Options
57
+ * @returns Signature
58
+ */
59
+ // TODO: make abstract in the next major release
60
+ // eslint-disable-next-line class-methods-use-this
61
+ async signNameDelegationToContract( /* eslint-disable @typescript-eslint/no-unused-vars */
62
+ contractAddress, name, options
63
+ /* eslint-enable @typescript-eslint/no-unused-vars */) {
64
+ throw new NotImplementedError('signNameDelegationToContract method');
65
+ }
66
+
67
+ /**
68
+ * Sign delegation of oracle query to a contract
69
+ *
70
+ * Warning! Implementations needs to ensure that decoded oracle query id is not equal to decoded
71
+ * current account address unless https://github.com/aeternity/aesophia/issues/475 is fixed.
72
+ *
73
+ * Warning! Implementations needs to ensure that oracle query and contract exists unless
74
+ * https://github.com/aeternity/aesophia/issues/474 is fixed.
75
+ *
76
+ * @param contractAddress - Address of a contract to delegate permissions to
77
+ * @param oracleQueryId - Oracle query ID to reply by a contract
78
+ * @param options - Options
79
+ * @returns Signature
80
+ */
81
+ // TODO: make abstract in the next major release
82
+ // eslint-disable-next-line class-methods-use-this
83
+ async signOracleQueryDelegationToContract( /* eslint-disable @typescript-eslint/no-unused-vars */
84
+ contractAddress, oracleQueryId, options
85
+ /* eslint-enable @typescript-eslint/no-unused-vars */) {
86
+ throw new NotImplementedError('signOracleQueryDelegationToContract method');
87
+ }
88
+
89
+ /**
90
+ * Sign data blob
91
+ * @param data - Data blob to sign
92
+ * @param options - Options
93
+ * @returns Signature
94
+ */
95
+
96
+ /**
97
+ * Account address
98
+ */
99
+ }
6
100
  //# sourceMappingURL=Base.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Base.mjs","names":["AccountBase"],"sources":["../../src/account/Base.ts"],"sourcesContent":["import { Encoded } from '../utils/encoder';\nimport Node from '../Node';\nimport CompilerBase from '../contract/compiler/Base';\nimport { Int } from '../tx/builder/constants';\n\ninterface AuthData {\n fee?: Int;\n gasLimit?: number;\n gasPrice?: Int;\n callData?: Encoded.ContractBytearray;\n sourceCode?: string;\n args?: any[];\n}\n\n/**\n * Account is one of the three basic building blocks of an\n * {@link AeSdk} and provides access to a signing key pair.\n */\nexport default abstract class AccountBase {\n /**\n * Sign encoded transaction\n * @param tx - Transaction to sign\n * @param options - Options\n * @param options.innerTx - Sign as inner transaction for PayingFor\n * @param options.authData - Object with gaMeta params\n * @returns Signed transaction\n */\n abstract signTransaction(\n tx: Encoded.Transaction,\n options: {\n innerTx?: boolean;\n networkId?: string;\n authData?: AuthData | ((tx: Encoded.Transaction) => Promise<AuthData>);\n onNode?: Node;\n onCompiler?: CompilerBase;\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Encoded.Transaction>;\n\n /**\n * Sign message\n * @param message - Message to sign\n * @param options - Options\n * @returns Signature as hex string of Uint8Array\n */\n abstract signMessage(\n message: string,\n options?: {\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Uint8Array>;\n\n /**\n * Sign data blob\n * @param data - Data blob to sign\n * @param options - Options\n * @returns Signed data blob\n */\n abstract sign(data: string | Uint8Array, options?: any): Promise<Uint8Array>;\n\n /**\n * Account address\n */\n readonly address: Encoded.AccountAddress;\n}\n"],"mappings":"AAcA;AACA;AACA;AACA;AACA,eAAe,MAAeA,WAAW,CAAC"}
1
+ {"version":3,"file":"Base.mjs","names":["NotImplementedError","AccountBase","signTypedData","data","aci","options","signDelegationToContract","contractAddress","signNameDelegationToContract","name","signOracleQueryDelegationToContract","oracleQueryId"],"sources":["../../src/account/Base.ts"],"sourcesContent":["import { Encoded } from '../utils/encoder';\nimport Node from '../Node';\nimport CompilerBase from '../contract/compiler/Base';\nimport { AensName, Int } from '../tx/builder/constants';\nimport { AciValue, Domain } from '../utils/typed-data';\nimport { NotImplementedError } from '../utils/errors';\n\ninterface AuthData {\n fee?: Int;\n gasLimit?: number;\n gasPrice?: Int;\n callData?: Encoded.ContractBytearray;\n sourceCode?: string;\n args?: any[];\n}\n\n/**\n * Account is one of the three basic building blocks of an\n * {@link AeSdk} and provides access to a signing key pair.\n */\nexport default abstract class AccountBase {\n /**\n * Sign encoded transaction\n * @param tx - Transaction to sign\n * @param options - Options\n * @param options.innerTx - Sign as inner transaction for PayingFor\n * @param options.authData - Object with gaMeta params\n * @returns Signed transaction\n */\n abstract signTransaction(\n tx: Encoded.Transaction,\n options: {\n innerTx?: boolean;\n networkId?: string;\n authData?: AuthData | ((tx: Encoded.Transaction) => Promise<AuthData>);\n onNode?: Node;\n onCompiler?: CompilerBase;\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Encoded.Transaction>;\n\n /**\n * Sign message\n * @param message - Message to sign\n * @param options - Options\n * @returns Signature\n */\n abstract signMessage(\n message: string,\n options?: {\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n ): Promise<Uint8Array>;\n\n /**\n * Sign typed data\n * @param type - Type of data to sign\n * @param data - Encoded data to sign\n * @param options - Options\n * @returns Signature\n */\n // TODO: make abstract in the next major release\n // eslint-disable-next-line class-methods-use-this\n async signTypedData(\n /* eslint-disable @typescript-eslint/no-unused-vars */\n data: Encoded.ContractBytearray,\n aci: AciValue,\n options?: Domain & {\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n /* eslint-enable @typescript-eslint/no-unused-vars */\n ): Promise<Encoded.Signature> {\n throw new NotImplementedError('signTypedData method');\n }\n\n /**\n * Sign delegation of AENS, oracle operations to a contract\n * @param contractAddress - Address of a contract to delegate permissions to\n * @param options - Options\n * @returns Signature\n */\n // TODO: make abstract in the next major release\n // eslint-disable-next-line class-methods-use-this\n async signDelegationToContract(\n /* eslint-disable @typescript-eslint/no-unused-vars */\n contractAddress: Encoded.ContractAddress,\n options?: {\n networkId?: string;\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n /* eslint-enable @typescript-eslint/no-unused-vars */\n ): Promise<Encoded.Signature> {\n throw new NotImplementedError('signDelegationToContract method');\n }\n\n /**\n * Sign delegation of an AENS name to a contract\n * @param contractAddress - Address of a contract to delegate permissions to\n * @param name - AENS name to manage by a contract\n * @param options - Options\n * @returns Signature\n */\n // TODO: make abstract in the next major release\n // eslint-disable-next-line class-methods-use-this\n async signNameDelegationToContract(\n /* eslint-disable @typescript-eslint/no-unused-vars */\n contractAddress: Encoded.ContractAddress,\n name: AensName,\n options?: {\n networkId?: string;\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n /* eslint-enable @typescript-eslint/no-unused-vars */\n ): Promise<Encoded.Signature> {\n throw new NotImplementedError('signNameDelegationToContract method');\n }\n\n /**\n * Sign delegation of oracle query to a contract\n *\n * Warning! Implementations needs to ensure that decoded oracle query id is not equal to decoded\n * current account address unless https://github.com/aeternity/aesophia/issues/475 is fixed.\n *\n * Warning! Implementations needs to ensure that oracle query and contract exists unless\n * https://github.com/aeternity/aesophia/issues/474 is fixed.\n *\n * @param contractAddress - Address of a contract to delegate permissions to\n * @param oracleQueryId - Oracle query ID to reply by a contract\n * @param options - Options\n * @returns Signature\n */\n // TODO: make abstract in the next major release\n // eslint-disable-next-line class-methods-use-this\n async signOracleQueryDelegationToContract(\n /* eslint-disable @typescript-eslint/no-unused-vars */\n contractAddress: Encoded.ContractAddress,\n oracleQueryId: Encoded.OracleQueryId,\n options?: {\n networkId?: string;\n aeppOrigin?: string;\n aeppRpcClientId?: string;\n },\n /* eslint-enable @typescript-eslint/no-unused-vars */\n ): Promise<Encoded.Signature> {\n throw new NotImplementedError('signOracleQueryDelegationToContract method');\n }\n\n /**\n * Sign data blob\n * @param data - Data blob to sign\n * @param options - Options\n * @returns Signature\n */\n abstract sign(data: string | Uint8Array, options?: any): Promise<Uint8Array>;\n\n /**\n * Account address\n */\n readonly address!: Encoded.AccountAddress;\n}\n"],"mappings":"SAKSA,mBAAmB;AAW5B;AACA;AACA;AACA;AACA,eAAe,MAAeC,WAAW,CAAC;EACxC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;;EAcE;AACF;AACA;AACA;AACA;AACA;;EASE;AACF;AACA;AACA;AACA;AACA;AACA;EACE;EACA;EACA,MAAMC,aAAaA,CAAA,CACjB;EACAC,IAA+B,EAC/BC,GAAa,EACbC;EAIA,uDAC4B;IAC5B,MAAM,IAAIL,mBAAmB,CAAC,sBAAsB,CAAC;EACvD;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE;EACA;EACA,MAAMM,wBAAwBA,CAAA,CAC5B;EACAC,eAAwC,EACxCF;EAKA,uDAC4B;IAC5B,MAAM,IAAIL,mBAAmB,CAAC,iCAAiC,CAAC;EAClE;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACE;EACA;EACA,MAAMQ,4BAA4BA,CAAA,CAChC;EACAD,eAAwC,EACxCE,IAAc,EACdJ;EAKA,uDAC4B;IAC5B,MAAM,IAAIL,mBAAmB,CAAC,qCAAqC,CAAC;EACtE;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE;EACA;EACA,MAAMU,mCAAmCA,CAAA,CACvC;EACAH,eAAwC,EACxCI,aAAoC,EACpCN;EAKA,uDAC4B;IAC5B,MAAM,IAAIL,mBAAmB,CAAC,4CAA4C,CAAC;EAC7E;;EAEA;AACF;AACA;AACA;AACA;AACA;;EAGE;AACF;AACA;AAEA"}
@@ -12,5 +12,9 @@ export default class AccountGeneralized extends AccountBase {
12
12
  constructor(address: Encoded.AccountAddress);
13
13
  sign(): Promise<Uint8Array>;
14
14
  signMessage(): Promise<Uint8Array>;
15
+ signTypedData(): Promise<Encoded.Signature>;
16
+ signDelegationToContract(): Promise<Encoded.Signature>;
17
+ signNameDelegationToContract(): Promise<Encoded.Signature>;
18
+ signOracleQueryDelegationToContract(): Promise<Encoded.Signature>;
15
19
  signTransaction(tx: Encoded.Transaction, { authData, onCompiler, onNode }: Parameters<AccountBase['signTransaction']>[1]): Promise<Encoded.Transaction>;
16
20
  }
@@ -36,6 +36,26 @@ export default class AccountGeneralized extends AccountBase {
36
36
  async signMessage() {
37
37
  throw new NotImplementedError('Can\'t sign using generalized account');
38
38
  }
39
+
40
+ // eslint-disable-next-line class-methods-use-this
41
+ async signTypedData() {
42
+ throw new NotImplementedError('Can\'t sign using generalized account');
43
+ }
44
+
45
+ // eslint-disable-next-line class-methods-use-this
46
+ async signDelegationToContract() {
47
+ throw new NotImplementedError('signing delegation to contract using generalized account');
48
+ }
49
+
50
+ // eslint-disable-next-line class-methods-use-this
51
+ async signNameDelegationToContract() {
52
+ throw new NotImplementedError('signing delegation to contract using generalized account');
53
+ }
54
+
55
+ // eslint-disable-next-line class-methods-use-this
56
+ async signOracleQueryDelegationToContract() {
57
+ throw new NotImplementedError('signing delegation to contract using generalized account');
58
+ }
39
59
  async signTransaction(tx, _ref) {
40
60
  let {
41
61
  authData,
@@ -1 +1 @@
1
- {"version":3,"file":"Generalized.mjs","names":["AccountBase","ArgumentError","InternalError","InvalidAuthDataError","NotImplementedError","decode","getAccount","Contract","buildTxAsync","buildTx","Tag","_authFun","WeakMap","AccountGeneralized","constructor","address","_classPrivateFieldInitSpec","writable","value","sign","signMessage","signTransaction","tx","_ref","authData","onCompiler","onNode","callData","sourceCode","args","fee","gasLimit","gasPrice","authCallData","_classPrivateFieldGet","account","kind","_classPrivateFieldSet","authFun","contract","initialize","_calldata","encode","_name","gaMetaTx","tag","GaMetaTx","SignedTx","encodedTx","signatures","gaId"],"sources":["../../src/account/Generalized.ts"],"sourcesContent":["import AccountBase from './Base';\nimport {\n ArgumentError,\n InternalError,\n InvalidAuthDataError,\n NotImplementedError,\n} from '../utils/errors';\nimport { decode, Encoded } from '../utils/encoder';\nimport { getAccount } from '../chain';\nimport Contract from '../contract/Contract';\nimport { buildTxAsync, buildTx } from '../tx/builder';\nimport { Tag } from '../tx/builder/constants';\n\n/**\n * Generalized account class\n */\nexport default class AccountGeneralized extends AccountBase {\n override readonly address: Encoded.AccountAddress;\n\n #authFun?: string;\n\n /**\n * @param address - Address of generalized account\n */\n constructor(address: Encoded.AccountAddress) {\n super();\n decode(address);\n this.address = address;\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async sign(): Promise<Uint8Array> {\n throw new NotImplementedError('Can\\'t sign using generalized account');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signMessage(): Promise<Uint8Array> {\n throw new NotImplementedError('Can\\'t sign using generalized account');\n }\n\n override async signTransaction(\n tx: Encoded.Transaction,\n { authData, onCompiler, onNode }: Parameters<AccountBase['signTransaction']>[1],\n ): Promise<Encoded.Transaction> {\n if (authData == null || onCompiler == null || onNode == null) {\n throw new ArgumentError('authData, onCompiler, onNode', 'provided', null);\n }\n const {\n callData, sourceCode, args, fee, gasLimit, gasPrice,\n } = typeof authData === 'function' ? await authData(tx) : authData;\n\n const authCallData = callData ?? await (async () => {\n if (this.#authFun == null) {\n const account = await getAccount(this.address, { onNode });\n if (account.kind !== 'generalized') {\n throw new ArgumentError('account kind', 'generalized', account.kind);\n }\n this.#authFun = account.authFun;\n }\n if (this.#authFun == null) {\n throw new InternalError('Account in generalised, but authFun not provided');\n }\n\n if (sourceCode == null || args == null) {\n throw new InvalidAuthDataError('Auth data must contain sourceCode and args or callData.');\n }\n const contract = await Contract.initialize({ onCompiler, onNode, sourceCode });\n return contract._calldata.encode(contract._name, this.#authFun, args);\n })();\n\n const gaMetaTx = await buildTxAsync({\n tag: Tag.GaMetaTx,\n tx: { tag: Tag.SignedTx, encodedTx: decode(tx), signatures: [] },\n gaId: this.address,\n authData: authCallData,\n fee,\n gasLimit,\n gasPrice,\n onNode,\n });\n return buildTx({ tag: Tag.SignedTx, encodedTx: decode(gaMetaTx), signatures: [] });\n }\n}\n"],"mappings":";;;;OAAOA,WAAW;AAAA,SAEhBC,aAAa,EACbC,aAAa,EACbC,oBAAoB,EACpBC,mBAAmB;AAAA,SAEZC,MAAM;AAAA,SACNC,UAAU;AAAA,OACZC,QAAQ;AAAA,SACNC,YAAY,EAAEC,OAAO;AAAA,SACrBC,GAAG;AAEZ;AACA;AACA;AAFA,IAAAC,QAAA,oBAAAC,OAAA;AAGA,eAAe,MAAMC,kBAAkB,SAASb,WAAW,CAAC;EAK1D;AACF;AACA;EACEc,WAAWA,CAACC,OAA+B,EAAE;IAC3C,KAAK,EAAE;IAACC,0BAAA,OAAAL,QAAA;MAAAM,QAAA;MAAAC,KAAA;IAAA;IACRb,MAAM,CAACU,OAAO,CAAC;IACf,IAAI,CAACA,OAAO,GAAGA,OAAO;EACxB;;EAEA;EACA,MAAeI,IAAIA,CAAA,EAAwB;IACzC,MAAM,IAAIf,mBAAmB,CAAC,uCAAuC,CAAC;EACxE;;EAEA;EACA,MAAegB,WAAWA,CAAA,EAAwB;IAChD,MAAM,IAAIhB,mBAAmB,CAAC,uCAAuC,CAAC;EACxE;EAEA,MAAeiB,eAAeA,CAC5BC,EAAuB,EAAAC,IAAA,EAEO;IAAA,IAD9B;MAAEC,QAAQ;MAAEC,UAAU;MAAEC;IAAsD,CAAC,GAAAH,IAAA;IAE/E,IAAIC,QAAQ,IAAI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AAWkB,IAAI,CAAC;IACvE,CAAC,GAAG;IAEJ,MAAMe,QAAQ,GAAG,MAAMpC,YAAY,CAAC;MAClCqC,GAAG,EAAEnC,GAAG,CAACoC,QAAQ;MACjBxB,EAAE,EAAE;QAAEuB,GAAG,EAAEnC,GAAG,CAACqC,QAAQ;QAAEC,SAAS,EAAE3C,MAAM,CAACiB,EAAE,CAAC;QAAE2B,UAAU,EAAE;MAAG,CAAC;MAChEC,IAAI,EAAE,IAAI,CAACnC,OAAO;MAClBS,QAAQ,EAAES,YAAY;MACtBH,GAAG;MACHC,QAAQ;MACRC,QAAQ;MACRN;IACF,CAAC,CAAC;IACF,OAAOjB,OAAO,CAAC;MAAEoC,GAAG,EAAEnC,GAAG,CAACqC,QAAQ;MAAEC,SAAS,EAAE3C,MAAM,CAACuC,QAAQ,CAAC;MAAEK,UAAU,EAAE;IAAG,CAAC,CAAC;EACpF;AACF"}
1
+ {"version":3,"file":"Generalized.mjs","names":["AccountBase","ArgumentError","InternalError","InvalidAuthDataError","NotImplementedError","decode","getAccount","Contract","buildTxAsync","buildTx","Tag","_authFun","WeakMap","AccountGeneralized","constructor","address","_classPrivateFieldInitSpec","writable","value","sign","signMessage","signTypedData","signDelegationToContract","signNameDelegationToContract","signOracleQueryDelegationToContract","signTransaction","tx","_ref","authData","onCompiler","onNode","callData","sourceCode","args","fee","gasLimit","gasPrice","authCallData","_classPrivateFieldGet","account","kind","_classPrivateFieldSet","authFun","contract","initialize","_calldata","encode","_name","gaMetaTx","tag","GaMetaTx","SignedTx","encodedTx","signatures","gaId"],"sources":["../../src/account/Generalized.ts"],"sourcesContent":["import AccountBase from './Base';\nimport {\n ArgumentError,\n InternalError,\n InvalidAuthDataError,\n NotImplementedError,\n} from '../utils/errors';\nimport { decode, Encoded } from '../utils/encoder';\nimport { getAccount } from '../chain';\nimport Contract from '../contract/Contract';\nimport { buildTxAsync, buildTx } from '../tx/builder';\nimport { Tag } from '../tx/builder/constants';\n\n/**\n * Generalized account class\n */\nexport default class AccountGeneralized extends AccountBase {\n override readonly address: Encoded.AccountAddress;\n\n #authFun?: string;\n\n /**\n * @param address - Address of generalized account\n */\n constructor(address: Encoded.AccountAddress) {\n super();\n decode(address);\n this.address = address;\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async sign(): Promise<Uint8Array> {\n throw new NotImplementedError('Can\\'t sign using generalized account');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signMessage(): Promise<Uint8Array> {\n throw new NotImplementedError('Can\\'t sign using generalized account');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signTypedData(): Promise<Encoded.Signature> {\n throw new NotImplementedError('Can\\'t sign using generalized account');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signDelegationToContract(): Promise<Encoded.Signature> {\n throw new NotImplementedError('signing delegation to contract using generalized account');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signNameDelegationToContract(): Promise<Encoded.Signature> {\n throw new NotImplementedError('signing delegation to contract using generalized account');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signOracleQueryDelegationToContract(): Promise<Encoded.Signature> {\n throw new NotImplementedError('signing delegation to contract using generalized account');\n }\n\n override async signTransaction(\n tx: Encoded.Transaction,\n { authData, onCompiler, onNode }: Parameters<AccountBase['signTransaction']>[1],\n ): Promise<Encoded.Transaction> {\n if (authData == null || onCompiler == null || onNode == null) {\n throw new ArgumentError('authData, onCompiler, onNode', 'provided', null);\n }\n const {\n callData, sourceCode, args, fee, gasLimit, gasPrice,\n } = typeof authData === 'function' ? await authData(tx) : authData;\n\n const authCallData = callData ?? await (async () => {\n if (this.#authFun == null) {\n const account = await getAccount(this.address, { onNode });\n if (account.kind !== 'generalized') {\n throw new ArgumentError('account kind', 'generalized', account.kind);\n }\n this.#authFun = account.authFun;\n }\n if (this.#authFun == null) {\n throw new InternalError('Account in generalised, but authFun not provided');\n }\n\n if (sourceCode == null || args == null) {\n throw new InvalidAuthDataError('Auth data must contain sourceCode and args or callData.');\n }\n const contract = await Contract.initialize({ onCompiler, onNode, sourceCode });\n return contract._calldata.encode(contract._name, this.#authFun, args);\n })();\n\n const gaMetaTx = await buildTxAsync({\n tag: Tag.GaMetaTx,\n tx: { tag: Tag.SignedTx, encodedTx: decode(tx), signatures: [] },\n gaId: this.address,\n authData: authCallData,\n fee,\n gasLimit,\n gasPrice,\n onNode,\n });\n return buildTx({ tag: Tag.SignedTx, encodedTx: decode(gaMetaTx), signatures: [] });\n }\n}\n"],"mappings":";;;;OAAOA,WAAW;AAAA,SAEhBC,aAAa,EACbC,aAAa,EACbC,oBAAoB,EACpBC,mBAAmB;AAAA,SAEZC,MAAM;AAAA,SACNC,UAAU;AAAA,OACZC,QAAQ;AAAA,SACNC,YAAY,EAAEC,OAAO;AAAA,SACrBC,GAAG;AAEZ;AACA;AACA;AAFA,IAAAC,QAAA,oBAAAC,OAAA;AAGA,eAAe,MAAMC,kBAAkB,SAASb,WAAW,CAAC;EAK1D;AACF;AACA;EACEc,WAAWA,CAACC,OAA+B,EAAE;IAC3C,KAAK,CAAC,CAAC;IAACC,0BAAA,OAAAL,QAAA;MAAAM,QAAA;MAAAC,KAAA;IAAA;IACRb,MAAM,CAACU,OAAO,CAAC;IACf,IAAI,CAACA,OAAO,GAAGA,OAAO;EACxB;;EAEA;EACA,MAAeI,IAAIA,CAAA,EAAwB;IACzC,MAAM,IAAIf,mBAAmB,CAAC,uCAAuC,CAAC;EACxE;;EAEA;EACA,MAAegB,WAAWA,CAAA,EAAwB;IAChD,MAAM,IAAIhB,mBAAmB,CAAC,uCAAuC,CAAC;EACxE;;EAEA;EACA,MAAeiB,aAAaA,CAAA,EAA+B;IACzD,MAAM,IAAIjB,mBAAmB,CAAC,uCAAuC,CAAC;EACxE;;EAEA;EACA,MAAekB,wBAAwBA,CAAA,EAA+B;IACpE,MAAM,IAAIlB,mBAAmB,CAAC,0DAA0D,CAAC;EAC3F;;EAEA;EACA,MAAemB,4BAA4BA,CAAA,EAA+B;IACxE,MAAM,IAAInB,mB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AAI,EAAE;QACtC,MAAM,IAAI9B,oBAAoB,CAAC,yDAAyD,CAAC;MAC3F;MACA,MAAMwC,QAAQ,GAAG,MAAMpC,QAAQ,CAACqC,UAAU,CAAC;QAAEf,UAAU;QAAEC,MAAM;QAAEE;MAAW,CAAC,CAAC;MAC9E,OAAOW,QAAQ,CAACE,SAAS,CAACC,MAAM,CAACH,QAAQ,CAACI,KAAK,EAAAT,qBAAA,CAAE,IAAI,EAAA3B,QAAA,GAAWsB,IAAI,CAAC;IACvE,CAAC,EAAE,CAAC;IAEJ,MAAMe,QAAQ,GAAG,MAAMxC,YAAY,CAAC;MAClCyC,GAAG,EAAEvC,GAAG,CAACwC,QAAQ;MACjBxB,EAAE,EAAE;QAAEuB,GAAG,EAAEvC,GAAG,CAACyC,QAAQ;QAAEC,SAAS,EAAE/C,MAAM,CAACqB,EAAE,CAAC;QAAE2B,UAAU,EAAE;MAAG,CAAC;MAChEC,IAAI,EAAE,IAAI,CAACvC,OAAO;MAClBa,QAAQ,EAAES,YAAY;MACtBH,GAAG;MACHC,QAAQ;MACRC,QAAQ;MACRN;IACF,CAAC,CAAC;IACF,OAAOrB,OAAO,CAAC;MAAEwC,GAAG,EAAEvC,GAAG,CAACyC,QAAQ;MAAEC,SAAS,EAAE/C,MAAM,CAAC2C,QAAQ,CAAC;MAAEK,UAAU,EAAE;IAAG,CAAC,CAAC;EACpF;AACF"}
@@ -20,6 +20,10 @@ export default class AccountLedger extends AccountBase {
20
20
  */
21
21
  constructor(transport: Transport, index: number, address: Encoded.AccountAddress);
22
22
  sign(): Promise<Uint8Array>;
23
+ signTypedData(): Promise<Encoded.Signature>;
24
+ signDelegationToContract(): Promise<Encoded.Signature>;
25
+ signNameDelegationToContract(): Promise<Encoded.Signature>;
26
+ signOracleQueryDelegationToContract(): Promise<Encoded.Signature>;
23
27
  signTransaction(tx: Encoded.Transaction, { innerTx, networkId }?: {
24
28
  innerTx?: boolean;
25
29
  networkId?: string;
@@ -35,6 +35,26 @@ export default class AccountLedger extends AccountBase {
35
35
  async sign() {
36
36
  throw new NotImplementedError('RAW signing using Ledger HW');
37
37
  }
38
+
39
+ // eslint-disable-next-line class-methods-use-this
40
+ async signTypedData() {
41
+ throw new NotImplementedError('Typed data signing using Ledger HW');
42
+ }
43
+
44
+ // eslint-disable-next-line class-methods-use-this
45
+ async signDelegationToContract() {
46
+ throw new NotImplementedError('signing delegation to contract using Ledger HW');
47
+ }
48
+
49
+ // eslint-disable-next-line class-methods-use-this
50
+ async signNameDelegationToContract() {
51
+ throw new NotImplementedError('signing delegation to contract using Ledger HW');
52
+ }
53
+
54
+ // eslint-disable-next-line class-methods-use-this
55
+ async signOracleQueryDelegationToContract() {
56
+ throw new NotImplementedError('signing delegation to contract using Ledger HW');
57
+ }
38
58
  async signTransaction(tx) {
39
59
  let {
40
60
  innerTx,