@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,141 @@
1
+ // eslint-disable-next-line max-classes-per-file
2
+ import BigNumber from 'bignumber.js';
3
+ import { OperationArguments, OperationSpec } from '@azure/core-client';
4
+ import {
5
+ genRequestQueuesPolicy, genCombineGetRequestsPolicy, genErrorFormatterPolicy,
6
+ genVersionCheckPolicy, genRetryOnFailurePolicy,
7
+ } from './utils/autorest';
8
+ import { Middleware as MiddlewareApi, MiddlewareOptionalParams, ErrorResponse } from './apis/middleware';
9
+ import { mapObject } from './utils/other';
10
+ import { Encoded } from './utils/encoder';
11
+ import { ConsensusProtocolVersion } from './tx/builder/constants';
12
+
13
+ const bigIntPropertyNames = [] as const;
14
+
15
+ const numberPropertyNames = [] as const;
16
+
17
+ class MiddlewareTransformed extends MiddlewareApi {
18
+ override async sendOperationRequest(
19
+ operationArguments: OperationArguments,
20
+ operationSpec: OperationSpec,
21
+ ): Promise<any> {
22
+ const args = mapObject(
23
+ operationArguments,
24
+ ([key, value]) => [key, this.#encodeArg(value)],
25
+ ) as OperationArguments;
26
+ return this.#decodeRes(await super.sendOperationRequest(args, operationSpec));
27
+ }
28
+
29
+ #mapData(data: any, transform: {
30
+ bigInt: (v: any) => any;
31
+ number: (v: any) => any;
32
+ }): unknown {
33
+ if (Array.isArray(data)) return data.map((d) => this.#mapData(d, transform));
34
+ if (data != null && typeof data === 'object') {
35
+ return mapObject(data, ([key, value]) => {
36
+ if (value == null) return [key, value];
37
+ if (bigIntPropertyNames.some((k) => k === key)) return [key, transform.bigInt(value)];
38
+ if (numberPropertyNames.some((k) => k === key)) return [key, transform.number(value)];
39
+ return [key, this.#mapData(value, transform)];
40
+ });
41
+ }
42
+ return data;
43
+ }
44
+
45
+ #encodeArg(data: any): any {
46
+ return this.#mapData(data, {
47
+ bigInt: (value) => {
48
+ if (value instanceof BigNumber) return value.toFixed();
49
+ return value.toString();
50
+ },
51
+ number: (value) => value.toString(),
52
+ });
53
+ }
54
+
55
+ #decodeRes(data: any): any {
56
+ return this.#mapData(data, {
57
+ bigInt: (value) => BigInt(value),
58
+ number: (value) => +value,
59
+ });
60
+ }
61
+ }
62
+
63
+ type BigIntPropertyNames = typeof bigIntPropertyNames[number];
64
+ type NumberPropertyNames = typeof numberPropertyNames[number];
65
+ type PreserveOptional<NewType, OrigType> =
66
+ OrigType extends undefined ? NewType | undefined : NewType;
67
+ export type TransformMiddlewareType<Type> =
68
+ Type extends (...args: infer Args) => infer Ret
69
+ ? (...args: TransformMiddlewareType<Args>) => TransformMiddlewareType<Ret>
70
+ : Type extends [infer Item, ...infer Rest]
71
+ ? [TransformMiddlewareType<Item>, ...TransformMiddlewareType<Rest>]
72
+ : Type extends Array<infer Item>
73
+ ? Array<TransformMiddlewareType<Item>>
74
+ : Type extends Promise<infer T>
75
+ ? Promise<TransformMiddlewareType<T>>
76
+ : Type extends { [P in any]: any }
77
+ ? {
78
+ [Property in keyof Type]:
79
+ Property extends BigIntPropertyNames
80
+ ? PreserveOptional<bigint, Type[Property]>
81
+ : Property extends NumberPropertyNames
82
+ ? PreserveOptional<number, Type[Property]>
83
+ : Property extends 'txHash'
84
+ ? PreserveOptional<Encoded.TxHash, Type[Property]>
85
+ : Property extends 'bytecode'
86
+ ? PreserveOptional<Encoded.ContractBytearray, Type[Property]>
87
+ : TransformMiddlewareType<Type[Property]>
88
+ }
89
+ : Type;
90
+ type MiddlewareTransformedApi = new (...args: ConstructorParameters<typeof MiddlewareApi>) => {
91
+ [Name in keyof InstanceType<typeof MiddlewareApi>]:
92
+ Name extends 'pipeline' | 'sendRequest' | 'sendOperationRequest'
93
+ ? MiddlewareApi[Name] : TransformMiddlewareType<MiddlewareApi[Name]>
94
+ };
95
+
96
+ export interface MiddlewareInfo {
97
+ url: string;
98
+ nodeNetworkId: string;
99
+ version: string;
100
+ consensusProtocolVersion: ConsensusProtocolVersion;
101
+ }
102
+
103
+ export default class Middleware
104
+ extends (MiddlewareTransformed as unknown as MiddlewareTransformedApi) {
105
+ /**
106
+ * @param url - Url for middleware API
107
+ * @param options - Options
108
+ * @param options.ignoreVersion - Don't check node version
109
+ * @param options.retryCount - Amount of extra requests to do in case of failure
110
+ * @param options.retryOverallDelay - Time in ms to wait between all retries
111
+ */
112
+ constructor(
113
+ url: string,
114
+ {
115
+ ignoreVersion = false, retryCount = 3, retryOverallDelay = 800, ...options
116
+ }: MiddlewareOptionalParams & {
117
+ ignoreVersion?: boolean;
118
+ retryCount?: number;
119
+ retryOverallDelay?: number;
120
+ } = {},
121
+ ) {
122
+ // eslint-disable-next-line constructor-super
123
+ super(url, {
124
+ allowInsecureConnection: true,
125
+ additionalPolicies: [
126
+ genRequestQueuesPolicy(),
127
+ genCombineGetRequestsPolicy(),
128
+ genRetryOnFailurePolicy(retryCount, retryOverallDelay),
129
+ genErrorFormatterPolicy((body: ErrorResponse) => ` ${body.error}`),
130
+ ],
131
+ ...options,
132
+ });
133
+ if (!ignoreVersion) {
134
+ const statusPromise = this.getStatus();
135
+ const versionPromise = statusPromise.then(({ mdwVersion }) => mdwVersion, (error) => error);
136
+ this.pipeline.addPolicy(
137
+ genVersionCheckPolicy('middleware', '/v2/status', versionPromise, '1.47.0', '2.0.0'),
138
+ );
139
+ }
140
+ }
141
+ }
@@ -0,0 +1,207 @@
1
+ /* eslint-disable max-classes-per-file */
2
+ import WebSocket from 'isomorphic-ws';
3
+ import { BaseError, UnexpectedTsError, InternalError } from './utils/errors';
4
+ import { Encoded } from './utils/encoder';
5
+
6
+ interface Message {
7
+ payload: Object;
8
+ source: Source.Middleware | Source.Node;
9
+ subscription: 'KeyBlocks' | 'MicroBlocks' | 'Transactions' | 'Object';
10
+ target?: string;
11
+ }
12
+
13
+ enum Source {
14
+ Middleware = 'mdw',
15
+ Node = 'node',
16
+ All = 'all',
17
+ }
18
+
19
+ export class MiddlewareSubscriberError extends BaseError {
20
+ constructor(message: string) {
21
+ super(message);
22
+ this.name = 'MiddlewareSubscriberError';
23
+ }
24
+ }
25
+
26
+ export class MiddlewareSubscriberDisconnected extends MiddlewareSubscriberError {
27
+ constructor(readonly closeEvent: WebSocket.CloseEvent) {
28
+ super('Connection closed');
29
+ this.name = 'MiddlewareSubscriberDisconnected';
30
+ }
31
+ }
32
+
33
+ export default class MiddlewareSubscriber {
34
+ #subscriptions: Array<
35
+ readonly [target: string, s: Source, cb: (p?: Object, e?: Error) => void]
36
+ > = [];
37
+
38
+ #requestQueue: Array<[isSubscribe: boolean, target: string]> = [];
39
+
40
+ #webSocket?: WebSocket;
41
+
42
+ get webSocket(): WebSocket | undefined {
43
+ return this.#webSocket;
44
+ }
45
+
46
+ get #targets(): Set<string> {
47
+ return new Set(this.#subscriptions.map(([target]) => target));
48
+ }
49
+
50
+ #sendMessage(message: any): void {
51
+ if (this.#webSocket == null) throw new UnexpectedTsError();
52
+ this.#webSocket.send(JSON.stringify(message));
53
+ }
54
+
55
+ #sendSubscribe(isSubscribe: boolean, target: string): void {
56
+ if (this.#webSocket == null) return;
57
+ const payload = ['KeyBlocks', 'MicroBlocks', 'Transactions'].includes(target)
58
+ ? target : 'Object';
59
+ this.#sendMessage({
60
+ op: isSubscribe ? 'Subscribe' : 'Unsubscribe',
61
+ payload,
62
+ ...payload === 'Object' && { target },
63
+ });
64
+ this.#requestQueue.push([isSubscribe, target]);
65
+ }
66
+
67
+ #emit(condition: (target: string, source: Source) => boolean, p?: Object, e?: Error): void {
68
+ this.#subscriptions
69
+ .filter(([target, source]) => condition(target, source))
70
+ .forEach(([, , cb]) => cb(p, e));
71
+ }
72
+
73
+ constructor(readonly url: string) {
74
+ }
75
+
76
+ #disconnect(onlyReset = false): void {
77
+ if (this.#webSocket == null) return;
78
+ if (!onlyReset) this.#webSocket.close();
79
+ Object.assign(this.#webSocket, {
80
+ onopen: undefined,
81
+ onerror: undefined,
82
+ onmessage: undefined,
83
+ });
84
+ this.#webSocket = undefined;
85
+ }
86
+
87
+ async reconnect(): Promise<void> {
88
+ this.#disconnect();
89
+ this.#webSocket = await new Promise((resolve) => {
90
+ const webSocket = new WebSocket(this.url);
91
+ Object.assign(webSocket, {
92
+ onopen: () => resolve(webSocket),
93
+ onerror: (errorEvent: WebSocket.ErrorEvent) => {
94
+ this.#emit(() => true, undefined, errorEvent.error);
95
+ },
96
+ onmessage: (event: WebSocket.MessageEvent) => {
97
+ if (typeof event.data !== 'string') {
98
+ throw new InternalError(`Unknown incoming message type: ${typeof event.data}`);
99
+ }
100
+ this.#messageHandler(JSON.parse(event.data));
101
+ },
102
+ onclose: (event: WebSocket.CloseEvent) => {
103
+ this.#emit(() => true, undefined, new MiddlewareSubscriberDisconnected(event));
104
+ this.#disconnect(true);
105
+ },
106
+ });
107
+ });
108
+ await Promise.all([...this.#targets].map((target) => this.#sendSubscribe(true, target)));
109
+ }
110
+
111
+ #messageHandler(message: string | string[] | Message): void {
112
+ if (typeof message === 'string' || Array.isArray(message)) {
113
+ const request = this.#requestQueue.shift();
114
+ if (request == null) throw new InternalError('Request queue is empty');
115
+ const [isSubscribe, target] = request;
116
+ let error;
117
+ if (typeof message === 'string') error = new MiddlewareSubscriberError(message);
118
+ if (message.includes(target) !== isSubscribe) {
119
+ error = new InternalError(`Expected ${target} to be${isSubscribe ? '' : ' not'} included into ${message}`);
120
+ }
121
+ if (error != null) this.#emit((t) => target === t, undefined, error);
122
+ return;
123
+ }
124
+ this.#emit(
125
+ (target, source) => (target === message.subscription || target === message.target)
126
+ && (source === message.source || source === Source.All),
127
+ message.payload,
128
+ );
129
+ }
130
+
131
+ #subscribe(target: string, source: Source, cb: (p?: Object, e?: Error) => void): () => void {
132
+ const subscription = [target, source, cb] as const;
133
+ if (this.#targets.size === 0) this.reconnect();
134
+ if (!this.#targets.has(target)) this.#sendSubscribe(true, target);
135
+ this.#subscriptions.push(subscription);
136
+ return () => {
137
+ this.#subscriptions = this.#subscriptions.filter((item) => item !== subscription);
138
+ if (!this.#targets.has(target)) this.#sendSubscribe(false, target);
139
+ if (this.#targets.size === 0) this.#disconnect();
140
+ };
141
+ }
142
+
143
+ // TODO: replace p?: any with a proper type definition
144
+
145
+ subscribeKeyBlocks(cb: (p?: any, e?: Error) => void): () => void {
146
+ return this.#subscribe('KeyBlocks', Source.Middleware, cb);
147
+ }
148
+
149
+ subscribeKeyBlocksNode(cb: (p?: any, e?: Error) => void): () => void {
150
+ return this.#subscribe('KeyBlocks', Source.Node, cb);
151
+ }
152
+
153
+ subscribeKeyBlocksAll(cb: (p?: any, e?: Error) => void): () => void {
154
+ return this.#subscribe('KeyBlocks', Source.All, cb);
155
+ }
156
+
157
+ subscribeMicroBlocks(cb: (p?: any, e?: Error) => void): () => void {
158
+ return this.#subscribe('MicroBlocks', Source.Middleware, cb);
159
+ }
160
+
161
+ subscribeMicroBlocksNode(cb: (p?: any, e?: Error) => void): () => void {
162
+ return this.#subscribe('MicroBlocks', Source.Node, cb);
163
+ }
164
+
165
+ subscribeMicroBlocksAll(cb: (p?: any, e?: Error) => void): () => void {
166
+ return this.#subscribe('MicroBlocks', Source.All, cb);
167
+ }
168
+
169
+ subscribeTransactions(cb: (p?: any, e?: Error) => void): () => void {
170
+ return this.#subscribe('Transactions', Source.Middleware, cb);
171
+ }
172
+
173
+ subscribeTransactionsNode(cb: (p?: any, e?: Error) => void): () => void {
174
+ return this.#subscribe('Transactions', Source.Node, cb);
175
+ }
176
+
177
+ subscribeTransactionsAll(cb: (p?: any, e?: Error) => void): () => void {
178
+ return this.#subscribe('Transactions', Source.All, cb);
179
+ }
180
+
181
+ subscribeObject(
182
+ target: Encoded.KeyBlockHash | Encoded.Channel | Encoded.ContractAddress
183
+ | Encoded.OracleAddress | Encoded.OracleQueryId | Encoded.AccountAddress
184
+ | Encoded.Name | `${string}.chain`,
185
+ cb: (p?: any, e?: Error) => void,
186
+ ): () => void {
187
+ return this.#subscribe(target, Source.Middleware, cb);
188
+ }
189
+
190
+ subscribeObjectNode(
191
+ target: Encoded.KeyBlockHash | Encoded.Channel | Encoded.ContractAddress
192
+ | Encoded.OracleAddress | Encoded.OracleQueryId | Encoded.AccountAddress
193
+ | Encoded.Name | `${string}.chain`,
194
+ cb: (p?: any, e?: Error) => void,
195
+ ): () => void {
196
+ return this.#subscribe(target, Source.Node, cb);
197
+ }
198
+
199
+ subscribeObjectAll(
200
+ target: Encoded.KeyBlockHash | Encoded.Channel | Encoded.ContractAddress
201
+ | Encoded.OracleAddress | Encoded.OracleQueryId | Encoded.AccountAddress
202
+ | Encoded.Name | `${string}.chain`,
203
+ cb: (p?: any, e?: Error) => void,
204
+ ): () => void {
205
+ return this.#subscribe(target, Source.All, cb);
206
+ }
207
+ }
package/src/Node.ts CHANGED
@@ -103,7 +103,7 @@ type NodeTransformedApi = new (...args: ConstructorParameters<typeof NodeApi>) =
103
103
  ? NodeApi[Name] : TransformNodeType<NodeApi[Name]>
104
104
  };
105
105
 
106
- export interface NodeInfo {
106
+ interface NodeInfo {
107
107
  url: string;
108
108
  nodeNetworkId: string;
109
109
  version: string;
@@ -1,7 +1,9 @@
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';
6
+ import { NotImplementedError } from '../utils/errors';
5
7
 
6
8
  interface AuthData {
7
9
  fee?: Int;
@@ -42,7 +44,7 @@ export default abstract class AccountBase {
42
44
  * Sign message
43
45
  * @param message - Message to sign
44
46
  * @param options - Options
45
- * @returns Signature as hex string of Uint8Array
47
+ * @returns Signature
46
48
  */
47
49
  abstract signMessage(
48
50
  message: string,
@@ -52,16 +54,112 @@ export default abstract class AccountBase {
52
54
  },
53
55
  ): Promise<Uint8Array>;
54
56
 
57
+ /**
58
+ * Sign typed data
59
+ * @param type - Type of data to sign
60
+ * @param data - Encoded data to sign
61
+ * @param options - Options
62
+ * @returns Signature
63
+ */
64
+ // TODO: make abstract in the next major release
65
+ // eslint-disable-next-line class-methods-use-this
66
+ async signTypedData(
67
+ /* eslint-disable @typescript-eslint/no-unused-vars */
68
+ data: Encoded.ContractBytearray,
69
+ aci: AciValue,
70
+ options?: Domain & {
71
+ aeppOrigin?: string;
72
+ aeppRpcClientId?: string;
73
+ },
74
+ /* eslint-enable @typescript-eslint/no-unused-vars */
75
+ ): Promise<Encoded.Signature> {
76
+ throw new NotImplementedError('signTypedData method');
77
+ }
78
+
79
+ /**
80
+ * Sign delegation of AENS, oracle operations to a contract
81
+ * @param contractAddress - Address of a contract to delegate permissions to
82
+ * @param options - Options
83
+ * @returns Signature
84
+ */
85
+ // TODO: make abstract in the next major release
86
+ // eslint-disable-next-line class-methods-use-this
87
+ async signDelegationToContract(
88
+ /* eslint-disable @typescript-eslint/no-unused-vars */
89
+ contractAddress: Encoded.ContractAddress,
90
+ options?: {
91
+ networkId?: string;
92
+ aeppOrigin?: string;
93
+ aeppRpcClientId?: string;
94
+ },
95
+ /* eslint-enable @typescript-eslint/no-unused-vars */
96
+ ): Promise<Encoded.Signature> {
97
+ throw new NotImplementedError('signDelegationToContract method');
98
+ }
99
+
100
+ /**
101
+ * Sign delegation of an AENS name to a contract
102
+ * @param contractAddress - Address of a contract to delegate permissions to
103
+ * @param name - AENS name to manage by a contract
104
+ * @param options - Options
105
+ * @returns Signature
106
+ */
107
+ // TODO: make abstract in the next major release
108
+ // eslint-disable-next-line class-methods-use-this
109
+ async signNameDelegationToContract(
110
+ /* eslint-disable @typescript-eslint/no-unused-vars */
111
+ contractAddress: Encoded.ContractAddress,
112
+ name: AensName,
113
+ options?: {
114
+ networkId?: string;
115
+ aeppOrigin?: string;
116
+ aeppRpcClientId?: string;
117
+ },
118
+ /* eslint-enable @typescript-eslint/no-unused-vars */
119
+ ): Promise<Encoded.Signature> {
120
+ throw new NotImplementedError('signNameDelegationToContract method');
121
+ }
122
+
123
+ /**
124
+ * Sign delegation of oracle query to a contract
125
+ *
126
+ * Warning! Implementations needs to ensure that decoded oracle query id is not equal to decoded
127
+ * current account address unless https://github.com/aeternity/aesophia/issues/475 is fixed.
128
+ *
129
+ * Warning! Implementations needs to ensure that oracle query and contract exists unless
130
+ * https://github.com/aeternity/aesophia/issues/474 is fixed.
131
+ *
132
+ * @param contractAddress - Address of a contract to delegate permissions to
133
+ * @param oracleQueryId - Oracle query ID to reply by a contract
134
+ * @param options - Options
135
+ * @returns Signature
136
+ */
137
+ // TODO: make abstract in the next major release
138
+ // eslint-disable-next-line class-methods-use-this
139
+ async signOracleQueryDelegationToContract(
140
+ /* eslint-disable @typescript-eslint/no-unused-vars */
141
+ contractAddress: Encoded.ContractAddress,
142
+ oracleQueryId: Encoded.OracleQueryId,
143
+ options?: {
144
+ networkId?: string;
145
+ aeppOrigin?: string;
146
+ aeppRpcClientId?: string;
147
+ },
148
+ /* eslint-enable @typescript-eslint/no-unused-vars */
149
+ ): Promise<Encoded.Signature> {
150
+ throw new NotImplementedError('signOracleQueryDelegationToContract method');
151
+ }
152
+
55
153
  /**
56
154
  * Sign data blob
57
155
  * @param data - Data blob to sign
58
156
  * @param options - Options
59
- * @returns Signed data blob
157
+ * @returns Signature
60
158
  */
61
159
  abstract sign(data: string | Uint8Array, options?: any): Promise<Uint8Array>;
62
160
 
63
161
  /**
64
162
  * Account address
65
163
  */
66
- readonly address: Encoded.AccountAddress;
164
+ readonly address!: Encoded.AccountAddress;
67
165
  }
@@ -38,6 +38,26 @@ export default class AccountGeneralized extends AccountBase {
38
38
  throw new NotImplementedError('Can\'t sign using generalized account');
39
39
  }
40
40
 
41
+ // eslint-disable-next-line class-methods-use-this
42
+ override async signTypedData(): Promise<Encoded.Signature> {
43
+ throw new NotImplementedError('Can\'t sign using generalized account');
44
+ }
45
+
46
+ // eslint-disable-next-line class-methods-use-this
47
+ override async signDelegationToContract(): Promise<Encoded.Signature> {
48
+ throw new NotImplementedError('signing delegation to contract using generalized account');
49
+ }
50
+
51
+ // eslint-disable-next-line class-methods-use-this
52
+ override async signNameDelegationToContract(): Promise<Encoded.Signature> {
53
+ throw new NotImplementedError('signing delegation to contract using generalized account');
54
+ }
55
+
56
+ // eslint-disable-next-line class-methods-use-this
57
+ override async signOracleQueryDelegationToContract(): Promise<Encoded.Signature> {
58
+ throw new NotImplementedError('signing delegation to contract using generalized account');
59
+ }
60
+
41
61
  override async signTransaction(
42
62
  tx: Encoded.Transaction,
43
63
  { authData, onCompiler, onNode }: Parameters<AccountBase['signTransaction']>[1],
@@ -40,6 +40,26 @@ export default class AccountLedger extends AccountBase {
40
40
  throw new NotImplementedError('RAW signing using Ledger HW');
41
41
  }
42
42
 
43
+ // eslint-disable-next-line class-methods-use-this
44
+ override async signTypedData(): Promise<Encoded.Signature> {
45
+ throw new NotImplementedError('Typed data signing using Ledger HW');
46
+ }
47
+
48
+ // eslint-disable-next-line class-methods-use-this
49
+ override async signDelegationToContract(): Promise<Encoded.Signature> {
50
+ throw new NotImplementedError('signing delegation to contract using Ledger HW');
51
+ }
52
+
53
+ // eslint-disable-next-line class-methods-use-this
54
+ override async signNameDelegationToContract(): Promise<Encoded.Signature> {
55
+ throw new NotImplementedError('signing delegation to contract using Ledger HW');
56
+ }
57
+
58
+ // eslint-disable-next-line class-methods-use-this
59
+ override async signOracleQueryDelegationToContract(): Promise<Encoded.Signature> {
60
+ throw new NotImplementedError('signing delegation to contract using Ledger HW');
61
+ }
62
+
43
63
  override async signTransaction(
44
64
  tx: Encoded.Transaction,
45
65
  { innerTx, networkId }: { innerTx?: boolean; networkId?: string } = {},
@@ -7,8 +7,10 @@ import {
7
7
  decode, encode, Encoded, Encoding,
8
8
  } from '../utils/encoder';
9
9
  import { concatBuffers } from '../utils/other';
10
+ import { hashTypedData, AciValue } from '../utils/typed-data';
10
11
  import { buildTx } from '../tx/builder';
11
- import { Tag } from '../tx/builder/constants';
12
+ import { Tag, AensName } from '../tx/builder/constants';
13
+ import { produceNameId } from '../tx/builder/helpers';
12
14
 
13
15
  const secretKeys = new WeakMap();
14
16
 
@@ -74,4 +76,69 @@ export default class AccountMemory extends AccountBase {
74
76
  override async signMessage(message: string, options?: any): Promise<Uint8Array> {
75
77
  return this.sign(messageToHash(message), options);
76
78
  }
79
+
80
+ override async signTypedData(
81
+ data: Encoded.ContractBytearray,
82
+ aci: AciValue,
83
+ {
84
+ name, version, networkId, contractAddress, ...options
85
+ }: Parameters<AccountBase['signTypedData']>[2] = {},
86
+ ): Promise<Encoded.Signature> {
87
+ const dHash = hashTypedData(data, aci, {
88
+ name, version, networkId, contractAddress,
89
+ });
90
+ const signature = await this.sign(dHash, options);
91
+ return encode(signature, Encoding.Signature);
92
+ }
93
+
94
+ override async signDelegationToContract(
95
+ contractAddress: Encoded.ContractAddress,
96
+ { networkId }: { networkId?: string } = {},
97
+ ): Promise<Encoded.Signature> {
98
+ if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);
99
+ const payload = concatBuffers([
100
+ Buffer.from(networkId),
101
+ decode(this.address),
102
+ decode(contractAddress),
103
+ ]);
104
+ const signature = await this.sign(payload);
105
+ return encode(signature, Encoding.Signature);
106
+ }
107
+
108
+ override async signNameDelegationToContract(
109
+ contractAddress: Encoded.ContractAddress,
110
+ name: AensName,
111
+ { networkId }: { networkId?: string } = {},
112
+ ): Promise<Encoded.Signature> {
113
+ if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);
114
+ const payload = concatBuffers([
115
+ Buffer.from(networkId),
116
+ decode(this.address),
117
+ decode(produceNameId(name)),
118
+ decode(contractAddress),
119
+ ]);
120
+ const signature = await this.sign(payload);
121
+ return encode(signature, Encoding.Signature);
122
+ }
123
+
124
+ override async signOracleQueryDelegationToContract(
125
+ contractAddress: Encoded.ContractAddress,
126
+ oracleQueryId: Encoded.OracleQueryId,
127
+ { networkId }: { networkId?: string } = {},
128
+ ): Promise<Encoded.Signature> {
129
+ const oracleQueryIdDecoded = decode(oracleQueryId);
130
+ const addressDecoded = decode(this.address);
131
+ // TODO: remove after fixing https://github.com/aeternity/aesophia/issues/475
132
+ if (oracleQueryIdDecoded.compare(addressDecoded) === 0) {
133
+ throw new ArgumentError('oracleQueryId', 'not equal to account address', oracleQueryId);
134
+ }
135
+ if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);
136
+ const payload = concatBuffers([
137
+ Buffer.from(networkId),
138
+ oracleQueryIdDecoded,
139
+ decode(contractAddress),
140
+ ]);
141
+ const signature = await this.sign(payload);
142
+ return encode(signature, Encoding.Signature);
143
+ }
77
144
  }