@aeternity/aepp-sdk 12.0.0 → 12.1.2

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 (283) hide show
  1. package/dist/aepp-sdk.browser-script.js +1 -1
  2. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -15
  3. package/dist/aepp-sdk.browser-script.js.map +1 -1
  4. package/dist/aepp-sdk.browser.js +2 -1
  5. package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
  6. package/dist/aepp-sdk.browser.js.map +1 -1
  7. package/dist/aepp-sdk.js +20765 -1
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/AeSdk.d.ts +7 -7
  10. package/es/AeSdk.mjs.map +1 -1
  11. package/es/AeSdkAepp.d.ts +4 -3
  12. package/es/AeSdkAepp.mjs +2 -1
  13. package/es/AeSdkAepp.mjs.map +1 -1
  14. package/es/AeSdkBase.d.ts +22 -21
  15. package/es/AeSdkBase.mjs +25 -21
  16. package/es/AeSdkBase.mjs.map +1 -1
  17. package/es/AeSdkWallet.d.ts +4 -3
  18. package/es/AeSdkWallet.mjs +5 -1
  19. package/es/AeSdkWallet.mjs.map +1 -1
  20. package/es/Node.d.ts +7 -10
  21. package/es/Node.mjs +63 -57
  22. package/es/Node.mjs.map +1 -1
  23. package/es/account/Base.d.ts +7 -4
  24. package/es/account/Base.mjs +3 -3
  25. package/es/account/Base.mjs.map +1 -1
  26. package/es/account/Memory.d.ts +5 -4
  27. package/es/account/Memory.mjs +24 -2
  28. package/es/account/Memory.mjs.map +1 -1
  29. package/es/account/Rpc.d.ts +6 -6
  30. package/es/account/Rpc.mjs +3 -2
  31. package/es/account/Rpc.mjs.map +1 -1
  32. package/es/aens.d.ts +27 -14
  33. package/es/aens.mjs +27 -21
  34. package/es/aens.mjs.map +1 -1
  35. package/es/aepp-wallet-communication/connection/Browser.d.ts +2 -1
  36. package/es/aepp-wallet-communication/connection/Browser.mjs +5 -2
  37. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
  38. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
  39. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +1 -0
  40. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
  41. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -0
  42. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +5 -1
  43. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
  44. package/es/aepp-wallet-communication/connection-proxy.d.ts +1 -0
  45. package/es/aepp-wallet-communication/connection-proxy.mjs +1 -0
  46. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
  47. package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +1 -0
  48. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -5
  49. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
  50. package/es/aepp-wallet-communication/rpc/types.d.ts +8 -8
  51. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
  52. package/es/aepp-wallet-communication/schema.d.ts +17 -2
  53. package/es/aepp-wallet-communication/schema.mjs +54 -17
  54. package/es/aepp-wallet-communication/schema.mjs.map +1 -1
  55. package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -1
  56. package/es/aepp-wallet-communication/wallet-detector.mjs +2 -3
  57. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
  58. package/es/apis/node/models/index.d.ts +6 -2
  59. package/es/apis/node/models/index.mjs.map +1 -1
  60. package/es/apis/node/models/mappers.mjs +4 -2
  61. package/es/apis/node/models/mappers.mjs.map +1 -1
  62. package/es/chain.d.ts +92 -64
  63. package/es/chain.mjs +190 -154
  64. package/es/chain.mjs.map +1 -1
  65. package/es/channel/handlers.d.ts +3 -3
  66. package/es/channel/handlers.mjs +42 -44
  67. package/es/channel/handlers.mjs.map +1 -1
  68. package/es/channel/index.d.ts +43 -52
  69. package/es/channel/index.mjs +46 -49
  70. package/es/channel/index.mjs.map +1 -1
  71. package/es/channel/internal.d.ts +16 -15
  72. package/es/channel/internal.mjs +67 -62
  73. package/es/channel/internal.mjs.map +1 -1
  74. package/es/contract/Compiler.d.ts +1 -0
  75. package/es/contract/Compiler.mjs +5 -4
  76. package/es/contract/Compiler.mjs.map +1 -1
  77. package/es/contract/aci.d.ts +17 -15
  78. package/es/contract/aci.mjs +58 -45
  79. package/es/contract/aci.mjs.map +1 -1
  80. package/es/contract/ga.d.ts +16 -15
  81. package/es/contract/ga.mjs +12 -7
  82. package/es/contract/ga.mjs.map +1 -1
  83. package/es/contract/methods.d.ts +9 -6
  84. package/es/contract/methods.mjs +9 -6
  85. package/es/contract/methods.mjs.map +1 -1
  86. package/es/deprecated/index.d.ts +143 -0
  87. package/es/deprecated/index.mjs +162 -0
  88. package/es/deprecated/index.mjs.map +1 -0
  89. package/es/deprecated/methods.d.ts +18 -0
  90. package/es/deprecated/methods.mjs +26 -0
  91. package/es/deprecated/methods.mjs.map +1 -0
  92. package/es/index.d.ts +4 -1
  93. package/es/index.mjs +4 -1
  94. package/es/index.mjs.map +1 -1
  95. package/es/oracle.d.ts +69 -62
  96. package/es/oracle.mjs +121 -103
  97. package/es/oracle.mjs.map +1 -1
  98. package/es/spend.d.ts +16 -15
  99. package/es/spend.mjs +19 -30
  100. package/es/spend.mjs.map +1 -1
  101. package/es/tx/builder/address.d.ts +25 -0
  102. package/es/tx/builder/address.mjs +45 -0
  103. package/es/tx/builder/address.mjs.map +1 -0
  104. package/es/tx/builder/constants.d.ts +55 -26
  105. package/es/tx/builder/constants.mjs +60 -38
  106. package/es/tx/builder/constants.mjs.map +1 -1
  107. package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
  108. package/es/tx/builder/field-types/coin-amount.mjs +26 -0
  109. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
  110. package/es/tx/builder/field-types/deposit.d.ts +15 -0
  111. package/es/tx/builder/field-types/deposit.mjs +19 -0
  112. package/es/tx/builder/field-types/deposit.mjs.map +1 -0
  113. package/es/tx/builder/field-types/fee.d.ts +25 -0
  114. package/es/tx/{min-fee.mjs → builder/field-types/fee.mjs} +62 -60
  115. package/es/tx/builder/field-types/fee.mjs.map +1 -0
  116. package/es/tx/builder/field-types/field.d.ts +6 -0
  117. package/es/tx/builder/field-types/field.mjs +15 -0
  118. package/es/tx/builder/field-types/field.mjs.map +1 -0
  119. package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
  120. package/es/tx/builder/field-types/gas-limit.mjs +33 -0
  121. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
  122. package/es/tx/builder/field-types/gas-price.d.ts +8 -0
  123. package/es/tx/builder/field-types/gas-price.mjs +18 -0
  124. package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
  125. package/es/tx/builder/field-types/index.d.ts +70 -0
  126. package/es/tx/builder/field-types/index.mjs +25 -0
  127. package/es/tx/builder/field-types/index.mjs.map +1 -0
  128. package/es/tx/builder/field-types/name-fee.d.ts +20 -0
  129. package/es/tx/builder/field-types/name-fee.mjs +24 -0
  130. package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
  131. package/es/tx/builder/field-types/name-id.d.ts +14 -0
  132. package/es/tx/builder/field-types/name-id.mjs +19 -0
  133. package/es/tx/builder/field-types/name-id.mjs.map +1 -0
  134. package/es/tx/builder/field-types/name.d.ts +13 -0
  135. package/es/tx/builder/field-types/name.mjs +18 -0
  136. package/es/tx/builder/field-types/name.mjs.map +1 -0
  137. package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
  138. package/es/tx/builder/field-types/short-u-int.mjs +12 -0
  139. package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
  140. package/es/tx/builder/field-types/u-int.d.ts +8 -0
  141. package/es/tx/builder/field-types/u-int.mjs +14 -0
  142. package/es/tx/builder/field-types/u-int.mjs.map +1 -0
  143. package/es/tx/builder/helpers.d.ts +27 -33
  144. package/es/tx/builder/helpers.mjs +41 -47
  145. package/es/tx/builder/helpers.mjs.map +1 -1
  146. package/es/tx/builder/index.d.ts +25 -12
  147. package/es/tx/builder/index.mjs +74 -83
  148. package/es/tx/builder/index.mjs.map +1 -1
  149. package/es/tx/builder/schema.d.ts +995 -144
  150. package/es/tx/builder/schema.mjs +121 -170
  151. package/es/tx/builder/schema.mjs.map +1 -1
  152. package/es/tx/index.d.ts +28 -27
  153. package/es/tx/index.mjs +97 -117
  154. package/es/tx/index.mjs.map +1 -1
  155. package/es/tx/validator.d.ts +4 -3
  156. package/es/tx/validator.mjs +79 -92
  157. package/es/tx/validator.mjs.map +1 -1
  158. package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -1
  159. package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -1
  160. package/es/typings/bip32-path/index.d.mjs.map +1 -1
  161. package/es/typings/blakejs/index.d.mjs.map +1 -1
  162. package/es/typings/sha-js/index.d.mjs +2 -0
  163. package/es/typings/sha-js/index.d.mjs.map +1 -0
  164. package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -1
  165. package/es/utils/amount-formatter.d.ts +9 -9
  166. package/es/utils/amount-formatter.mjs +17 -17
  167. package/es/utils/amount-formatter.mjs.map +1 -1
  168. package/es/utils/autorest.mjs +7 -7
  169. package/es/utils/autorest.mjs.map +1 -1
  170. package/es/utils/bignumber.mjs +2 -1
  171. package/es/utils/bignumber.mjs.map +1 -1
  172. package/es/utils/bytes.mjs +1 -1
  173. package/es/utils/bytes.mjs.map +1 -1
  174. package/es/utils/crypto.d.ts +8 -23
  175. package/es/utils/crypto.mjs +15 -41
  176. package/es/utils/crypto.mjs.map +1 -1
  177. package/es/utils/encoder-types.d.ts +61 -0
  178. package/es/utils/encoder-types.mjs +36 -0
  179. package/es/utils/encoder-types.mjs.map +1 -0
  180. package/es/utils/encoder.d.ts +6 -7
  181. package/es/utils/encoder.mjs +42 -26
  182. package/es/utils/encoder.mjs.map +1 -1
  183. package/es/utils/errors.d.ts +1 -11
  184. package/es/utils/errors.mjs +4 -20
  185. package/es/utils/errors.mjs.map +1 -1
  186. package/es/utils/hd-wallet.d.ts +18 -2
  187. package/es/utils/hd-wallet.mjs +64 -34
  188. package/es/utils/hd-wallet.mjs.map +1 -1
  189. package/es/utils/json-big.mjs +2 -2
  190. package/es/utils/json-big.mjs.map +1 -1
  191. package/es/utils/keystore.mjs +4 -2
  192. package/es/utils/keystore.mjs.map +1 -1
  193. package/es/utils/mptree.d.ts +2 -2
  194. package/es/utils/mptree.mjs +11 -6
  195. package/es/utils/mptree.mjs.map +1 -1
  196. package/es/utils/other.d.ts +8 -2
  197. package/es/utils/other.mjs +15 -3
  198. package/es/utils/other.mjs.map +1 -1
  199. package/es/utils/semver-satisfies.d.ts +1 -1
  200. package/es/utils/semver-satisfies.mjs +2 -2
  201. package/es/utils/semver-satisfies.mjs.map +1 -1
  202. package/es/utils/string.mjs.map +1 -1
  203. package/package.json +36 -34
  204. package/src/AeSdk.ts +30 -27
  205. package/src/AeSdkAepp.ts +93 -84
  206. package/src/AeSdkBase.ts +148 -130
  207. package/src/AeSdkWallet.ts +172 -156
  208. package/src/Node.ts +108 -102
  209. package/src/account/Base.ts +42 -32
  210. package/src/account/Memory.ts +45 -30
  211. package/src/account/Rpc.ts +32 -30
  212. package/src/aens.ts +124 -108
  213. package/src/aepp-wallet-communication/connection/Browser.ts +18 -15
  214. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +22 -21
  215. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +63 -52
  216. package/src/aepp-wallet-communication/connection-proxy.ts +8 -7
  217. package/src/aepp-wallet-communication/rpc/RpcClient.ts +67 -61
  218. package/src/aepp-wallet-communication/rpc/types.ts +32 -32
  219. package/src/aepp-wallet-communication/schema.ts +117 -74
  220. package/src/aepp-wallet-communication/wallet-detector.ts +29 -28
  221. package/src/apis/node/code-model-v4.yaml +54 -20
  222. package/src/apis/node/models/index.ts +6 -2
  223. package/src/apis/node/models/mappers.ts +4 -2
  224. package/src/chain.ts +286 -228
  225. package/src/channel/handlers.ts +424 -372
  226. package/src/channel/index.ts +285 -251
  227. package/src/channel/internal.ts +248 -232
  228. package/src/contract/Compiler.ts +22 -21
  229. package/src/contract/aci.ts +267 -258
  230. package/src/contract/ga.ts +93 -72
  231. package/src/contract/methods.ts +32 -27
  232. package/src/deprecated/index.ts +172 -0
  233. package/src/deprecated/methods.ts +25 -0
  234. package/src/index.ts +37 -32
  235. package/src/oracle.ts +211 -189
  236. package/src/spend.ts +82 -70
  237. package/src/tx/builder/address.ts +50 -0
  238. package/src/tx/builder/constants.ts +82 -52
  239. package/src/tx/builder/field-types/coin-amount.ts +27 -0
  240. package/src/tx/builder/field-types/deposit.ts +21 -0
  241. package/src/tx/builder/field-types/fee.ts +143 -0
  242. package/src/tx/builder/field-types/field.ts +9 -0
  243. package/src/tx/builder/field-types/gas-limit.ts +41 -0
  244. package/src/tx/builder/field-types/gas-price.ts +16 -0
  245. package/src/tx/builder/field-types/index.ts +45 -0
  246. package/src/tx/builder/field-types/name-fee.ts +32 -0
  247. package/src/tx/builder/field-types/name-id.ts +20 -0
  248. package/src/tx/builder/field-types/name.ts +18 -0
  249. package/src/tx/builder/field-types/short-u-int.ts +11 -0
  250. package/src/tx/builder/field-types/u-int.ts +16 -0
  251. package/src/tx/builder/helpers.ts +112 -117
  252. package/src/tx/builder/index.ts +203 -197
  253. package/src/tx/builder/schema.ts +421 -465
  254. package/src/tx/index.ts +128 -135
  255. package/src/tx/validator.ts +165 -161
  256. package/src/typings/@aeternity__argon2-browser/index.d.ts +1 -1
  257. package/src/typings/@aeternity__uuid/index.d.ts +3 -1
  258. package/src/typings/bip32-path/index.d.ts +6 -6
  259. package/src/typings/blakejs/index.d.ts +4 -32
  260. package/src/typings/sha-js/index.d.ts +5 -0
  261. package/src/typings/tweetnacl-auth/index.d.ts +2 -2
  262. package/src/utils/amount-formatter.ts +41 -41
  263. package/src/utils/autorest.ts +57 -54
  264. package/src/utils/bignumber.ts +7 -6
  265. package/src/utils/bytes.ts +19 -19
  266. package/src/utils/crypto.ts +82 -94
  267. package/src/utils/encoder-types.ts +63 -0
  268. package/src/utils/encoder.ts +104 -56
  269. package/src/utils/errors.ts +246 -264
  270. package/src/utils/hd-wallet.ts +114 -82
  271. package/src/utils/json-big.ts +16 -15
  272. package/src/utils/keystore.ts +65 -62
  273. package/src/utils/mptree.ts +59 -56
  274. package/src/utils/other.ts +26 -18
  275. package/src/utils/semver-satisfies.ts +15 -11
  276. package/src/utils/string.ts +10 -10
  277. package/es/tx/builder/field-types.d.ts +0 -62
  278. package/es/tx/builder/field-types.mjs +0 -126
  279. package/es/tx/builder/field-types.mjs.map +0 -1
  280. package/es/tx/min-fee.d.ts +0 -20
  281. package/es/tx/min-fee.mjs.map +0 -1
  282. package/src/tx/builder/field-types.ts +0 -111
  283. package/src/tx/min-fee.ts +0 -136
@@ -15,331 +15,347 @@
15
15
  * PERFORMANCE OF THIS SOFTWARE.
16
16
  */
17
17
 
18
- import { w3cwebsocket as W3CWebSocket } from 'websocket'
19
- import { EventEmitter } from 'events'
20
- import BigNumber from 'bignumber.js'
21
- import Channel from '.'
22
- import JsonBig from '../utils/json-big'
23
- import { pascalToSnake } from '../utils/string'
24
- import { EncodedData } from '../utils/encoder'
25
- import { ChannelCallError, ChannelPingTimedOutError, UnknownChannelStateError } from '../utils/errors'
18
+ import { w3cwebsocket as W3CWebSocket } from 'websocket';
19
+ import { EventEmitter } from 'events';
20
+ import BigNumber from 'bignumber.js';
21
+ import type Channel from '.';
22
+ import JsonBig from '../utils/json-big';
23
+ import { pascalToSnake } from '../utils/string';
24
+ import { Encoded } from '../utils/encoder';
25
+ import {
26
+ BaseError, ChannelCallError, ChannelPingTimedOutError, UnknownChannelStateError,
27
+ } from '../utils/errors';
26
28
 
27
29
  interface ChannelAction {
28
- guard: (channel: Channel, state?: ChannelFsm) => boolean
29
- action: (channel: Channel, state?: ChannelFsm) => ChannelFsm
30
+ guard: (channel: Channel, state?: ChannelFsm) => boolean;
31
+ action: (channel: Channel, state?: ChannelFsm) => ChannelFsm;
30
32
  }
31
33
 
32
- export type SignTxWithTag = (tag: string, tx: EncodedData<'tx'>, options?: object) => Promise<EncodedData<'tx'>>
34
+ export type SignTxWithTag = (tag: string, tx: Encoded.Transaction, options?: object) => (
35
+ Promise<Encoded.Transaction>
36
+ );
33
37
  // TODO: SignTx shouldn't return number or null
34
- export type SignTx = (tx: EncodedData<'tx'>, options?: object) => Promise<EncodedData<'tx'> | number | null>
38
+ export type SignTx = (tx: Encoded.Transaction, options?: object) => (
39
+ Promise<Encoded.Transaction | number | null>
40
+ );
35
41
 
36
42
  export interface ChannelOptions {
37
- existingFsmId?: string
38
- url: string
39
- role: 'initiator' | 'responder'
40
- initiatorId: EncodedData<'ak'>
41
- responderId: EncodedData<'ak'>
42
- pushAmount: number
43
- initiatorAmount: BigNumber
44
- responderAmount: BigNumber
45
- channelReserve?: BigNumber | number
46
- signedTx?: string
47
- ttl?: number
48
- host: string
49
- port: number
50
- lockPeriod: number
51
- existingChannelId?: string
52
- offChainTx?: string
53
- reconnectTx?: string
54
- timeoutIdle?: number
55
- timeoutFundingCreate?: number
56
- timeoutFundingSign?: number
57
- timeoutFundingLock?: number
58
- timeoutSign?: number
59
- timeoutAccept?: number
60
- timeoutInitialized?: number
61
- timeoutAwaitingOpen?: number
62
- statePassword?: string
63
- debug: boolean
64
- sign: SignTxWithTag
65
- offchainTx?: string
43
+ existingFsmId?: string;
44
+ url: string;
45
+ role: 'initiator' | 'responder';
46
+ initiatorId: Encoded.AccountAddress;
47
+ responderId: Encoded.AccountAddress;
48
+ pushAmount: number;
49
+ initiatorAmount: BigNumber;
50
+ responderAmount: BigNumber;
51
+ channelReserve?: BigNumber | number;
52
+ signedTx?: string;
53
+ ttl?: number;
54
+ host: string;
55
+ port: number;
56
+ lockPeriod: number;
57
+ existingChannelId?: string;
58
+ offChainTx?: string;
59
+ reconnectTx?: string;
60
+ timeoutIdle?: number;
61
+ timeoutFundingCreate?: number;
62
+ timeoutFundingSign?: number;
63
+ timeoutFundingLock?: number;
64
+ timeoutSign?: number;
65
+ timeoutAccept?: number;
66
+ timeoutInitialized?: number;
67
+ timeoutAwaitingOpen?: number;
68
+ statePassword?: string;
69
+ debug: boolean;
70
+ sign: SignTxWithTag;
71
+ offchainTx?: string;
66
72
  }
67
73
 
68
74
  export interface ChannelHandler extends Function {
69
- enter?: Function
75
+ enter?: Function;
70
76
  }
71
77
 
72
78
  export interface ChannelState {
73
- signedTx: any
74
- resolve: Function
75
- reject: Function
76
- sign: SignTx
77
- handler?: ChannelHandler
78
- onOnChainTx?: Function
79
- onOwnWithdrawLocked?: Function
80
- onWithdrawLocked?: Function
81
- onOwnDepositLocked?: Function
82
- onDepositLocked?: Function
83
- closeTx?: string
79
+ signedTx: any;
80
+ resolve: (r?: any) => void;
81
+ reject: (e: BaseError) => void;
82
+ sign: SignTx;
83
+ handler?: ChannelHandler;
84
+ onOnChainTx?: (tx: Encoded.Transaction) => void;
85
+ onOwnWithdrawLocked?: () => void;
86
+ onWithdrawLocked?: () => void;
87
+ onOwnDepositLocked?: () => void;
88
+ onDepositLocked?: () => void;
89
+ closeTx?: string;
84
90
  }
85
91
 
86
92
  export interface ChannelFsm {
87
- handler: ChannelHandler
93
+ handler: ChannelHandler;
88
94
  state?: ChannelState | {
89
- resolve: Function
90
- reject: Function
91
- }
95
+ resolve: Function;
96
+ reject: Function;
97
+ };
92
98
  }
93
99
 
94
100
  export interface ChannelMessage {
95
- id?: number
96
- jsonrpc: string
97
- method: string
98
- params: any
99
- payload?: any
100
- data?: any
101
- error?: ChannelMessageError
101
+ id?: number;
102
+ jsonrpc: string;
103
+ method: string;
104
+ params: any;
105
+ payload?: any;
106
+ data?: any;
107
+ error?: ChannelMessageError;
102
108
  }
103
109
 
104
110
  interface ChannelMessageError {
105
- code: number
106
- message: string
111
+ code: number;
112
+ message: string;
107
113
  data: [{
108
- message: string
109
- code: number
110
- }]
111
- request: ChannelMessage
114
+ message: string;
115
+ code: number;
116
+ }];
117
+ request: ChannelMessage;
112
118
  }
113
119
 
114
120
  // Send ping message every 10 seconds
115
- const PING_TIMEOUT_MS = 10000
121
+ const PING_TIMEOUT_MS = 10000;
116
122
  // Close connection if pong message is not received within 5 seconds
117
- const PONG_TIMEOUT_MS = 5000
123
+ const PONG_TIMEOUT_MS = 5000;
118
124
 
119
125
  // TODO: move to Channel instance to avoid is-null checks and for easier debugging
120
- export const options = new WeakMap<Channel, ChannelOptions>()
121
- export const status = new WeakMap<Channel, string>()
122
- export const state = new WeakMap<Channel, EncodedData<'tx'>>()
123
- const fsm = new WeakMap<Channel, ChannelFsm>()
124
- const websockets = new WeakMap<Channel, W3CWebSocket>()
125
- export const eventEmitters = new WeakMap<Channel, EventEmitter>()
126
- const messageQueue = new WeakMap<Channel, string[]>()
127
- const messageQueueLocked = new WeakMap<Channel, boolean>()
128
- const actionQueue = new WeakMap<Channel, ChannelAction[]>()
129
- const actionQueueLocked = new WeakMap<Channel, boolean>()
130
- const sequence = new WeakMap<Channel, number>()
131
- export const channelId = new WeakMap<Channel, string>()
132
- const rpcCallbacks = new WeakMap<Channel, Map<number, Function>>()
133
- const pingTimeoutId = new WeakMap<Channel, NodeJS.Timeout>()
134
- const pongTimeoutId = new WeakMap<Channel, NodeJS.Timeout>()
135
- export const fsmId = new WeakMap<Channel, string>()
126
+ export const options = new WeakMap<Channel, ChannelOptions>();
127
+ export const status = new WeakMap<Channel, string>();
128
+ export const state = new WeakMap<Channel, Encoded.Transaction>();
129
+ const fsm = new WeakMap<Channel, ChannelFsm>();
130
+ const websockets = new WeakMap<Channel, W3CWebSocket>();
131
+ export const eventEmitters = new WeakMap<Channel, EventEmitter>();
132
+ const messageQueue = new WeakMap<Channel, string[]>();
133
+ const messageQueueLocked = new WeakMap<Channel, boolean>();
134
+ const actionQueue = new WeakMap<Channel, ChannelAction[]>();
135
+ const actionQueueLocked = new WeakMap<Channel, boolean>();
136
+ const sequence = new WeakMap<Channel, number>();
137
+ export const channelId = new WeakMap<Channel, string>();
138
+ const rpcCallbacks = new WeakMap<Channel, Map<number, Function>>();
139
+ const pingTimeoutId = new WeakMap<Channel, NodeJS.Timeout>();
140
+ const pongTimeoutId = new WeakMap<Channel, NodeJS.Timeout>();
141
+ export const fsmId = new WeakMap<Channel, string>();
136
142
 
137
- export function emit (channel: Channel, ...args: any[]): void {
138
- const [eventName, ...rest] = args
139
- eventEmitters.get(channel)?.emit(eventName, ...rest)
143
+ export function emit(channel: Channel, ...args: any[]): void {
144
+ const [eventName, ...rest] = args;
145
+ eventEmitters.get(channel)?.emit(eventName, ...rest);
140
146
  }
141
147
 
142
- function enterState (channel: Channel, nextState: ChannelFsm): void {
148
+ function enterState(channel: Channel, nextState: ChannelFsm): void {
143
149
  if (nextState == null) {
144
- throw new UnknownChannelStateError()
150
+ throw new UnknownChannelStateError();
145
151
  }
146
- fsm.set(channel, nextState)
152
+ fsm.set(channel, nextState);
147
153
  if (nextState?.handler?.enter != null) {
148
- nextState.handler.enter(channel)
154
+ nextState.handler.enter(channel);
149
155
  }
150
- void dequeueAction(channel)
156
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
157
+ void dequeueAction(channel);
151
158
  }
152
159
 
153
- export function changeStatus (channel: Channel, newStatus: string): void {
154
- const prevStatus = status.get(channel)
160
+ export function changeStatus(channel: Channel, newStatus: string): void {
161
+ const prevStatus = status.get(channel);
155
162
  if (newStatus !== prevStatus) {
156
- status.set(channel, newStatus)
157
- emit(channel, 'statusChanged', newStatus)
163
+ status.set(channel, newStatus);
164
+ emit(channel, 'statusChanged', newStatus);
158
165
  }
159
166
  }
160
167
 
161
- export function changeState (channel: Channel, newState: EncodedData<'tx'>): void {
162
- state.set(channel, newState)
163
- emit(channel, 'stateChanged', newState)
168
+ export function changeState(channel: Channel, newState: Encoded.Transaction): void {
169
+ state.set(channel, newState);
170
+ emit(channel, 'stateChanged', newState);
164
171
  }
165
172
 
166
- export function send (channel: Channel, message: ChannelMessage): void {
167
- const debug: boolean = options.get(channel)?.debug ?? false
168
- if (debug) console.log('Send message: ', message)
169
-
170
- websockets.get(channel)?.send(JsonBig.stringify(message))
171
- }
173
+ export function send(channel: Channel, message: ChannelMessage): void {
174
+ const debug: boolean = options.get(channel)?.debug ?? false;
175
+ if (debug) console.log('Send message: ', message);
172
176
 
173
- export function enqueueAction (channel: Channel, guard: ChannelAction['guard'], action: ChannelAction['action']): void {
174
- const queue = actionQueue.get(channel) ?? []
175
- actionQueue.set(channel, [
176
- ...queue,
177
- { guard, action }
178
- ])
179
- void dequeueAction(channel)
177
+ websockets.get(channel)?.send(JsonBig.stringify(message));
180
178
  }
181
179
 
182
- async function dequeueAction (channel: Channel): Promise<void> {
183
- const locked = actionQueueLocked.get(channel)
184
- const queue = actionQueue.get(channel) ?? []
180
+ async function dequeueAction(channel: Channel): Promise<void> {
181
+ const locked = actionQueueLocked.get(channel);
182
+ const queue = actionQueue.get(channel) ?? [];
185
183
  if (Boolean(locked) || queue.length === 0) {
186
- return
184
+ return;
187
185
  }
188
- const state = fsm.get(channel)
189
- if (state == null) return
190
- const index = queue.findIndex((action: ChannelAction) => action.guard(channel, state))
186
+ const singleFsm = fsm.get(channel);
187
+ if (singleFsm == null) return;
188
+ const index = queue.findIndex((action: ChannelAction) => action.guard(channel, singleFsm));
191
189
  if (index === -1) {
192
- return
190
+ return;
193
191
  }
194
- actionQueue.set(channel, queue.filter((_: ChannelAction, i: number) => index !== i))
195
- actionQueueLocked.set(channel, true)
196
- const nextState: ChannelFsm = await Promise.resolve(queue[index].action(channel, state))
197
- actionQueueLocked.set(channel, false)
198
- enterState(channel, nextState)
192
+ actionQueue.set(channel, queue.filter((_: ChannelAction, i: number) => index !== i));
193
+ actionQueueLocked.set(channel, true);
194
+ const nextState: ChannelFsm = await Promise.resolve(queue[index].action(channel, singleFsm));
195
+ actionQueueLocked.set(channel, false);
196
+ enterState(channel, nextState);
199
197
  }
200
198
 
201
- async function handleMessage (channel: Channel, message: string): Promise<void> {
202
- const fsmState = fsm.get(channel)
203
- if (fsmState == null) throw new UnknownChannelStateError()
204
- const { handler, state } = fsmState
205
- enterState(channel, await Promise.resolve(handler(channel, message, state)))
199
+ export function enqueueAction(
200
+ channel: Channel,
201
+ guard: ChannelAction['guard'],
202
+ action: ChannelAction['action'],
203
+ ): void {
204
+ const queue = actionQueue.get(channel) ?? [];
205
+ actionQueue.set(channel, [
206
+ ...queue,
207
+ { guard, action },
208
+ ]);
209
+ void dequeueAction(channel);
206
210
  }
207
211
 
208
- async function dequeueMessage (channel: Channel): Promise<void> {
209
- const locked: boolean = messageQueueLocked.get(channel) ?? false
210
- if (locked) return
211
- const messages: string[] = messageQueue.get(channel) ?? []
212
- if (messages.length === 0) return
213
- messageQueueLocked.set(channel, true)
212
+ async function handleMessage(channel: Channel, message: string): Promise<void> {
213
+ const fsmState = fsm.get(channel);
214
+ if (fsmState == null) throw new UnknownChannelStateError();
215
+ const { handler, state: st } = fsmState;
216
+ enterState(channel, await Promise.resolve(handler(channel, message, st)));
217
+ }
218
+
219
+ async function dequeueMessage(channel: Channel): Promise<void> {
220
+ const locked: boolean = messageQueueLocked.get(channel) ?? false;
221
+ if (locked) return;
222
+ const messages: string[] = messageQueue.get(channel) ?? [];
223
+ if (messages.length === 0) return;
224
+ messageQueueLocked.set(channel, true);
214
225
  while (messages.length > 0) {
215
- const message: string = messages.shift() ?? ''
226
+ const message: string = messages.shift() ?? '';
216
227
  try {
217
- await handleMessage(channel, message)
228
+ await handleMessage(channel, message);
218
229
  } catch (error) {
219
- console.error('Error handling incoming message:')
220
- console.error(message)
221
- console.error(error)
230
+ console.error('Error handling incoming message:');
231
+ console.error(message);
232
+ console.error(error);
222
233
  }
223
234
  }
224
- messageQueueLocked.set(channel, false)
235
+ messageQueueLocked.set(channel, false);
236
+ }
237
+
238
+ export function disconnect(channel: Channel): void {
239
+ websockets.get(channel)?.close();
240
+ const pingTimeoutIdValue = pingTimeoutId.get(channel);
241
+ const pongTimeoutIdValue = pongTimeoutId.get(channel);
242
+ if (pingTimeoutIdValue != null) clearTimeout(pingTimeoutIdValue);
243
+ if (pongTimeoutIdValue != null) clearTimeout(pongTimeoutIdValue);
225
244
  }
226
245
 
227
- function ping (channel: Channel): void {
228
- const pingTimeoutIdValue = pingTimeoutId.get(channel)
229
- const pongTimeoutIdValue = pongTimeoutId.get(channel)
230
- if (pingTimeoutIdValue != null) clearTimeout(pingTimeoutIdValue)
231
- if (pongTimeoutIdValue != null) clearTimeout(pongTimeoutIdValue)
246
+ function ping(channel: Channel): void {
247
+ const pingTimeoutIdValue = pingTimeoutId.get(channel);
248
+ const pongTimeoutIdValue = pongTimeoutId.get(channel);
249
+ if (pingTimeoutIdValue != null) clearTimeout(pingTimeoutIdValue);
250
+ if (pongTimeoutIdValue != null) clearTimeout(pongTimeoutIdValue);
232
251
  pingTimeoutId.set(channel, setTimeout(() => {
233
252
  send(channel, {
234
253
  jsonrpc: '2.0',
235
254
  method: 'channels.system',
236
255
  params: {
237
- action: 'ping'
238
- }
239
- })
256
+ action: 'ping',
257
+ },
258
+ });
240
259
  pongTimeoutId.set(channel, setTimeout(() => {
241
- disconnect(channel)
242
- emit(channel, 'error', new ChannelPingTimedOutError())
243
- }, PONG_TIMEOUT_MS))
244
- }, PING_TIMEOUT_MS))
260
+ disconnect(channel);
261
+ emit(channel, 'error', new ChannelPingTimedOutError());
262
+ }, PONG_TIMEOUT_MS));
263
+ }, PING_TIMEOUT_MS));
245
264
  }
246
265
 
247
- function onMessage (channel: Channel, data: string): void {
248
- const message = JsonBig.parse(data)
249
- const debug: boolean = options.get(channel)?.debug ?? false
250
- if (debug) console.log('Receive message: ', message)
266
+ function onMessage(channel: Channel, data: string): void {
267
+ const message = JsonBig.parse(data);
268
+ const debug: boolean = options.get(channel)?.debug ?? false;
269
+ if (debug) console.log('Receive message: ', message);
251
270
  if (message.id != null) {
252
- const callback = rpcCallbacks.get(channel)?.get(message.id)
271
+ const callback = rpcCallbacks.get(channel)?.get(message.id);
253
272
  try {
254
- callback?.(message)
273
+ callback?.(message);
255
274
  } finally {
256
- rpcCallbacks.get(channel)?.delete(message.id)
275
+ rpcCallbacks.get(channel)?.delete(message.id);
257
276
  }
258
- return
277
+ return;
259
278
  }
260
279
  if (message.method === 'channels.message') {
261
- emit(channel, 'message', message.params.data.message)
262
- return
280
+ emit(channel, 'message', message.params.data.message);
281
+ return;
263
282
  }
264
283
  if (message.method === 'channels.system.pong') {
265
284
  if (
266
- (message.params.channel_id === channelId.get(channel)) ||
285
+ (message.params.channel_id === channelId.get(channel))
267
286
  // Skip channelId check if channelId is not known yet
268
- (channelId.get(channel) == null)
287
+ || (channelId.get(channel) == null)
269
288
  ) {
270
- ping(channel)
289
+ ping(channel);
271
290
  }
272
- return
291
+ return;
273
292
  }
274
- messageQueue.get(channel)?.push(message)
275
- void dequeueMessage(channel)
293
+ messageQueue.get(channel)?.push(message);
294
+ void dequeueMessage(channel);
276
295
  }
277
296
 
278
- export async function call (channel: Channel, method: string, params: any): Promise<any> {
279
- return await new Promise((resolve, reject) => {
280
- const currentSequence: number = sequence.get(channel) ?? 0
281
- const id = sequence.set(channel, currentSequence + 1).get(channel) ?? 1
282
- rpcCallbacks.get(channel)?.set(id, (message: {
283
- result: PromiseLike<any>
284
- error?: ChannelMessageError }) => {
285
- if (message.result != null) return resolve(message.result)
286
- if (message.error != null) {
287
- const [{ message: details } = { message: '' }] = message.error.data ?? []
288
- return reject(new ChannelCallError(message.error.message + details))
289
- }
290
- })
291
- send(channel, { jsonrpc: '2.0', method, id, params })
292
- })
293
- }
294
-
295
- export function disconnect (channel: Channel): void {
296
- websockets.get(channel)?.close()
297
- const pingTimeoutIdValue = pingTimeoutId.get(channel)
298
- const pongTimeoutIdValue = pongTimeoutId.get(channel)
299
- if (pingTimeoutIdValue != null) clearTimeout(pingTimeoutIdValue)
300
- if (pongTimeoutIdValue != null) clearTimeout(pongTimeoutIdValue)
297
+ export async function call(channel: Channel, method: string, params: any): Promise<any> {
298
+ return new Promise((resolve, reject) => {
299
+ const currentSequence: number = sequence.get(channel) ?? 0;
300
+ const id = sequence.set(channel, currentSequence + 1).get(channel) ?? 1;
301
+ rpcCallbacks.get(channel)?.set(
302
+ id,
303
+ (message: { result: PromiseLike<any>; error?: ChannelMessageError }) => {
304
+ if (message.error != null) {
305
+ const [{ message: details } = { message: '' }] = message.error.data ?? [];
306
+ return reject(new ChannelCallError(message.error.message + details));
307
+ }
308
+ return resolve(message.result);
309
+ },
310
+ );
311
+ send(channel, {
312
+ jsonrpc: '2.0', method, id, params,
313
+ });
314
+ });
301
315
  }
302
316
 
303
- export async function initialize (
317
+ export async function initialize(
304
318
  channel: Channel,
305
319
  connectionHandler: Function,
306
320
  openHandler: Function,
307
- { url, ...channelOptions }: ChannelOptions
321
+ { url, ...channelOptions }: ChannelOptions,
308
322
  ): Promise<void> {
309
- options.set(channel, { url, ...channelOptions })
310
- fsm.set(channel, { handler: connectionHandler })
311
- eventEmitters.set(channel, new EventEmitter())
312
- sequence.set(channel, 0)
313
- rpcCallbacks.set(channel, new Map())
314
- messageQueue.set(channel, [])
323
+ options.set(channel, { url, ...channelOptions });
324
+ fsm.set(channel, { handler: connectionHandler });
325
+ eventEmitters.set(channel, new EventEmitter());
326
+ sequence.set(channel, 0);
327
+ rpcCallbacks.set(channel, new Map());
328
+ messageQueue.set(channel, []);
315
329
 
316
- const wsUrl = new URL(url)
330
+ const wsUrl = new URL(url);
317
331
  Object.entries(channelOptions)
318
332
  .filter(([key]) => !['sign', 'debug'].includes(key))
319
- .forEach(([key, value]) => wsUrl.searchParams.set(pascalToSnake(key), value))
320
- wsUrl.searchParams.set('protocol', 'json-rpc')
321
- changeStatus(channel, 'connecting')
322
- const ws = new W3CWebSocket(wsUrl.toString())
323
- await new Promise<void>((resolve, reject) => Object.assign(ws, {
324
- onerror: reject,
325
- onopen: async () => {
326
- resolve()
327
- changeStatus(channel, 'connected')
328
- if (channelOptions.reconnectTx != null) {
329
- enterState(channel, { handler: openHandler })
330
- const signedTx = (await call(channel, 'channels.get.offchain_state', {})).signed_tx
331
- changeState(channel, signedTx)
332
- }
333
- ping(channel)
334
- },
335
- onclose: () => {
336
- changeStatus(channel, 'disconnected')
337
- const pingTimeoutIdValue = pingTimeoutId.get(channel)
338
- const pongTimeoutIdValue = pongTimeoutId.get(channel)
339
- if (pingTimeoutIdValue != null) clearTimeout(pingTimeoutIdValue)
340
- if (pongTimeoutIdValue != null) clearTimeout(pongTimeoutIdValue)
341
- },
342
- onmessage: ({ data }: {data: string}) => onMessage(channel, data)
343
- }))
344
- websockets.set(channel, ws)
333
+ .forEach(([key, value]) => wsUrl.searchParams.set(pascalToSnake(key), value));
334
+ wsUrl.searchParams.set('protocol', 'json-rpc');
335
+ changeStatus(channel, 'connecting');
336
+ const ws = new W3CWebSocket(wsUrl.toString());
337
+ await new Promise<void>((resolve, reject) => {
338
+ Object.assign(ws, {
339
+ onerror: reject,
340
+ onopen: async () => {
341
+ resolve();
342
+ changeStatus(channel, 'connected');
343
+ if (channelOptions.reconnectTx != null) {
344
+ enterState(channel, { handler: openHandler });
345
+ const signedTx = (await call(channel, 'channels.get.offchain_state', {})).signed_tx;
346
+ changeState(channel, signedTx);
347
+ }
348
+ ping(channel);
349
+ },
350
+ onclose: () => {
351
+ changeStatus(channel, 'disconnected');
352
+ const pingTimeoutIdValue = pingTimeoutId.get(channel);
353
+ const pongTimeoutIdValue = pongTimeoutId.get(channel);
354
+ if (pingTimeoutIdValue != null) clearTimeout(pingTimeoutIdValue);
355
+ if (pongTimeoutIdValue != null) clearTimeout(pongTimeoutIdValue);
356
+ },
357
+ onmessage: ({ data }: { data: string }) => onMessage(channel, data),
358
+ });
359
+ });
360
+ websockets.set(channel, ws);
345
361
  }
@@ -14,18 +14,19 @@
14
14
  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
15
  * PERFORMANCE OF THIS SOFTWARE.
16
16
  */
17
- import { Compiler as CompilerApi, ErrorModel, CompilerError } from '../apis/compiler'
18
- import { genErrorFormatterPolicy, genVersionCheckPolicy } from '../utils/autorest'
17
+ import { Compiler as CompilerApi, ErrorModel, CompilerError } from '../apis/compiler';
18
+ import { genErrorFormatterPolicy, genVersionCheckPolicy } from '../utils/autorest';
19
19
 
20
20
  type GeneralCompilerError = ErrorModel & {
21
- info?: object
22
- parameter?: string
23
- }
21
+ info?: object;
22
+ parameter?: string;
23
+ };
24
24
 
25
25
  /**
26
26
  * Contract Compiler
27
27
  *
28
28
  * This class include api call's related to contract compiler functionality.
29
+ * @category contract
29
30
  * @example Compiler('COMPILER_URL')
30
31
  */
31
32
  export default class Compiler extends CompilerApi {
@@ -34,33 +35,33 @@ export default class Compiler extends CompilerApi {
34
35
  * @param options - Options
35
36
  * @param options.ignoreVersion - Don't check compiler version
36
37
  */
37
- constructor (compilerUrl: string, { ignoreVersion }: { ignoreVersion?: boolean } = {}) {
38
+ constructor(compilerUrl: string, { ignoreVersion }: { ignoreVersion?: boolean } = {}) {
38
39
  super(compilerUrl, {
39
40
  allowInsecureConnection: true,
40
41
  additionalPolicies: [
41
42
  genErrorFormatterPolicy((body: GeneralCompilerError | CompilerError[]) => {
42
- let message = ''
43
+ let message = '';
43
44
  if ('reason' in body) {
44
- message += ' ' + body.reason +
45
- (body.parameter != null ? ` in ${body.parameter}` : '') +
45
+ message += ` ${body.reason
46
+ }${body.parameter != null ? ` in ${body.parameter}` : ''
46
47
  // TODO: revising after improving documentation https://github.com/aeternity/aesophia_http/issues/78
47
- (body.info != null ? ` (${JSON.stringify(body.info)})` : '')
48
+ }${body.info != null ? ` (${JSON.stringify(body.info)})` : ''}`;
48
49
  }
49
50
  if (Array.isArray(body)) {
50
- message += '\n' + body
51
- .map(e => `${e.type}:${e.pos.line}:${e.pos.col}: ${e.message}${e.context != null ? `(${e.context})` : ''}`)
52
- .map(e => e.trim()) // TODO: remove after fixing https://github.com/aeternity/aesophia_http/issues/80
53
- .join('\n')
51
+ message += `\n${body
52
+ .map((e) => `${e.type}:${e.pos.line}:${e.pos.col}: ${e.message}${e.context != null ? `(${e.context})` : ''}`)
53
+ .map((e) => e.trim()) // TODO: remove after fixing https://github.com/aeternity/aesophia_http/issues/80
54
+ .join('\n')}`;
54
55
  }
55
- return message
56
- })
57
- ]
58
- })
56
+ return message;
57
+ }),
58
+ ],
59
+ });
59
60
  if (ignoreVersion !== true) {
60
- const versionPromise = this.aPIVersion().then(({ apiVersion }) => apiVersion)
61
+ const versionPromise = this.aPIVersion().then(({ apiVersion }) => apiVersion);
61
62
  this.pipeline.addPolicy(
62
- genVersionCheckPolicy('compiler', '/api-version', versionPromise, '6.1.0', '7.0.0')
63
- )
63
+ genVersionCheckPolicy('compiler', '/api-version', versionPromise, '6.1.0', '7.0.0'),
64
+ );
64
65
  }
65
66
  }
66
67
  }