@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
@@ -14,11 +14,11 @@
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 BigNumber from 'bignumber.js'
18
- import { snakeToPascal } from '../utils/string'
19
- import { buildTx, unpackTx } from '../tx/builder'
20
- import { TX_TYPE } from '../tx/builder/schema'
21
- import * as handlers from './handlers'
17
+ import BigNumber from 'bignumber.js';
18
+ import { snakeToPascal } from '../utils/string';
19
+ import { buildTx, unpackTx } from '../tx/builder';
20
+ import { MIN_GAS_PRICE, Tag } from '../tx/builder/constants';
21
+ import * as handlers from './handlers';
22
22
  import {
23
23
  eventEmitters,
24
24
  status as channelStatus,
@@ -33,42 +33,43 @@ import {
33
33
  SignTx,
34
34
  ChannelOptions,
35
35
  ChannelState,
36
- ChannelMessage
37
- } from './internal'
38
- import { UnknownChannelStateError, ChannelError } from '../utils/errors'
39
- import { EncodedData } from '../utils/encoder'
36
+ } from './internal';
37
+ import { UnknownChannelStateError, ChannelError } from '../utils/errors';
38
+ import { Encoded } from '../utils/encoder';
39
+ import { ContractCallReturnType } from '../apis/node';
40
+ import { pause } from '../utils/other';
40
41
 
41
- function snakeToPascalObjKeys<Type> (obj: object): Type {
42
+ function snakeToPascalObjKeys<Type>(obj: object): Type {
42
43
  return Object.entries(obj).reduce((result, [key, val]) => ({
43
44
  ...result,
44
- [snakeToPascal(key)]: val
45
- }), {}) as Type
45
+ [snakeToPascal(key)]: val,
46
+ }), {}) as Type;
46
47
  }
47
48
 
48
- type EventCallback = (...args: any[]) => void
49
+ type EventCallback = (...args: any[]) => void;
49
50
 
50
51
  interface CallContractOptions {
51
- amount?: number | BigNumber
52
- callData?: string
53
- abiVersion?: number
54
- contract?: string
55
- returnValue?: any
56
- gasUsed?: number | BigNumber
57
- gasPrice?: number | BigNumber
58
- height?: number
59
- callerNonce?: number
60
- log?: any
61
- returnType?: string
52
+ amount?: number | BigNumber;
53
+ callData?: Encoded.ContractBytearray;
54
+ abiVersion?: number;
55
+ contract?: Encoded.ContractAddress;
56
+ returnValue?: any;
57
+ gasUsed?: number | BigNumber;
58
+ gasPrice?: number | BigNumber;
59
+ height?: number;
60
+ callerNonce?: number;
61
+ log?: any;
62
+ returnType?: ContractCallReturnType;
62
63
  }
63
64
 
64
65
  interface Contract {
65
- abiVersion: number
66
- active: boolean
67
- deposit: number | BigNumber
68
- id: string
69
- ownerId: string
70
- referrerIds: string[]
71
- vmVersion: number
66
+ abiVersion: number;
67
+ active: boolean;
68
+ deposit: number | BigNumber;
69
+ id: string;
70
+ ownerId: string;
71
+ referrerIds: string[];
72
+ vmVersion: number;
72
73
  }
73
74
 
74
75
  /**
@@ -139,15 +140,15 @@ export default class Channel {
139
140
  * @param options.debug=false - Log websocket communication
140
141
  * @param options.sign - Function which verifies and signs transactions
141
142
  */
142
- static async initialize (options: ChannelOptions): Promise<Channel> {
143
- const channel = new Channel()
143
+ static async initialize(options: ChannelOptions): Promise<Channel> {
144
+ const channel = new Channel();
144
145
  await initialize(
145
146
  channel,
146
147
  options.existingFsmId != null ? handlers.awaitingReconnection : handlers.awaitingConnection,
147
148
  handlers.channelOpen,
148
- options
149
- )
150
- return channel
149
+ options,
150
+ );
151
+ return channel;
151
152
  }
152
153
 
153
154
  /**
@@ -168,10 +169,10 @@ export default class Channel {
168
169
  * @param callback - Callback function
169
170
  */
170
171
  // TODO define specific callback type depending on the event name
171
- on (eventName: string, callback: EventCallback): void {
172
- const eventEmitter = eventEmitters.get(this)
173
- if (eventEmitter == null) throw new UnknownChannelStateError()
174
- eventEmitter.on(eventName, callback)
172
+ on(eventName: string, callback: EventCallback): void {
173
+ const eventEmitter = eventEmitters.get(this);
174
+ if (eventEmitter == null) throw new UnknownChannelStateError();
175
+ eventEmitter.on(eventName, callback);
175
176
  }
176
177
 
177
178
  /**
@@ -179,34 +180,34 @@ export default class Channel {
179
180
  * @param eventName - Event name
180
181
  * @param callback - Callback function
181
182
  */
182
- off (eventName: string, callback: EventCallback): void {
183
- const eventEmitter = eventEmitters.get(this)
184
- if (eventEmitter == null) throw new UnknownChannelStateError()
185
- eventEmitter.removeListener(eventName, callback)
183
+ off(eventName: string, callback: EventCallback): void {
184
+ const eventEmitter = eventEmitters.get(this);
185
+ if (eventEmitter == null) throw new UnknownChannelStateError();
186
+ eventEmitter.removeListener(eventName, callback);
186
187
  }
187
188
 
188
189
  /**
189
190
  * Close the connection
190
191
  */
191
- disconnect (): void {
192
- return channelDisconnect(this)
192
+ disconnect(): void {
193
+ return channelDisconnect(this);
193
194
  }
194
195
 
195
196
  /**
196
197
  * Get current status
197
198
  *
198
199
  */
199
- status (): string {
200
- const status = channelStatus.get(this)
201
- if (status == null) throw new UnknownChannelStateError()
202
- return status
200
+ status(): string {
201
+ const status = channelStatus.get(this);
202
+ if (status == null) throw new UnknownChannelStateError();
203
+ return status;
203
204
  }
204
205
 
205
206
  /**
206
207
  * Get current state
207
208
  */
208
- async state (): Promise<ChannelState> {
209
- return await snakeToPascalObjKeys(await call(this, 'channels.get.offchain_state', {}))
209
+ async state(): Promise<ChannelState> {
210
+ return snakeToPascalObjKeys(await call(this, 'channels.get.offchain_state', {}));
210
211
  }
211
212
 
212
213
  /**
@@ -216,21 +217,21 @@ export default class Channel {
216
217
  * it will return `null`.
217
218
  *
218
219
  */
219
- round (): number | null {
220
- const state = channelState.get(this)
220
+ round(): number | null {
221
+ const state = channelState.get(this);
221
222
  if (state == null) {
222
- return null
223
+ return null;
223
224
  }
224
- const { txType, tx } = unpackTx(state, TX_TYPE.signed).tx.encodedTx
225
+ const { txType, tx } = unpackTx(state, Tag.SignedTx).tx.encodedTx;
225
226
  switch (txType) {
226
- case TX_TYPE.channelCreate:
227
- return 1
228
- case TX_TYPE.channelOffChain:
229
- case TX_TYPE.channelWithdraw:
230
- case TX_TYPE.channelDeposit:
231
- return +tx.round
227
+ case Tag.ChannelCreateTx:
228
+ return 1;
229
+ case Tag.ChannelOffChainTx:
230
+ case Tag.ChannelWithdrawTx:
231
+ case Tag.ChannelDepositTx:
232
+ return tx.round;
232
233
  default:
233
- return null
234
+ return null;
234
235
  }
235
236
  }
236
237
 
@@ -238,20 +239,20 @@ export default class Channel {
238
239
  * Get channel id
239
240
  *
240
241
  */
241
- id (): string {
242
- const id = channelId.get(this)
243
- if (id == null) throw new ChannelError('Channel is not initialized')
244
- return id
242
+ id(): string {
243
+ const id = channelId.get(this);
244
+ if (id == null) throw new ChannelError('Channel is not initialized');
245
+ return id;
245
246
  }
246
247
 
247
248
  /**
248
249
  * Get channel's fsm id
249
250
  *
250
251
  */
251
- fsmId (): string {
252
- const id = channelFsmId.get(this)
253
- if (id == null) throw new ChannelError('Channel is not initialized')
254
- return id
252
+ fsmId(): string {
253
+ const id = channelFsmId.get(this);
254
+ if (id == null) throw new ChannelError('Channel is not initialized');
255
+ return id;
255
256
  }
256
257
 
257
258
  /**
@@ -261,7 +262,7 @@ export default class Channel {
261
262
  * The update is a change to be applied on top of the latest state.
262
263
  *
263
264
  * Sender and receiver are the channel parties. Both the initiator and responder
264
- * can take those roles. Any public key outside of the channel is considered invalid.
265
+ * can take those roles. Any public key outside the channel is considered invalid.
265
266
  *
266
267
  * @param from - Sender's public address
267
268
  * @param to - Receiver's public address
@@ -283,38 +284,41 @@ export default class Channel {
283
284
  * )
284
285
  * ```
285
286
  */
286
- async update (
287
- from: string,
288
- to: string,
287
+ async update(
288
+ from: Encoded.AccountAddress,
289
+ to: Encoded.AccountAddress,
289
290
  amount: number | BigNumber,
290
291
  sign: SignTx,
291
- metadata: string[] = []): Promise<{
292
- accepted: boolean
293
- signedTx?: string
294
- errorCode?: number
295
- errorMessage?: string
292
+ metadata: string[] = [],
293
+ ): Promise<{
294
+ accepted: boolean;
295
+ signedTx?: Encoded.Transaction;
296
+ errorCode?: number;
297
+ errorMessage?: string;
296
298
  }> {
297
- return await new Promise((resolve, reject) => {
299
+ return new Promise((resolve, reject) => {
298
300
  enqueueAction(
299
301
  this,
300
302
  (_channel, state) => state?.handler === handlers.channelOpen,
301
- (channel, _state) => {
303
+ (channel) => {
302
304
  send(channel, {
303
305
  jsonrpc: '2.0',
304
306
  method: 'channels.update.new',
305
- params: { from, to, amount, meta: metadata }
306
- })
307
+ params: {
308
+ from, to, amount, meta: metadata,
309
+ },
310
+ });
307
311
  return {
308
312
  handler: handlers.awaitingOffChainTx,
309
313
  state: {
310
314
  resolve,
311
315
  reject,
312
- sign
313
- }
314
- }
315
- }
316
- )
317
- })
316
+ sign,
317
+ },
318
+ };
319
+ },
320
+ );
321
+ });
318
322
  }
319
323
 
320
324
  /**
@@ -337,16 +341,19 @@ export default class Channel {
337
341
  * }).then(poi => console.log(poi))
338
342
  * ```
339
343
  */
340
- async poi (
341
- { accounts, contracts }: { accounts: string[], contracts?: string[] }
342
- ): Promise<EncodedData<'pi'>> {
343
- return (await call(this, 'channels.get.poi', { accounts, contracts })).poi
344
+ async poi(
345
+ { accounts, contracts }: {
346
+ accounts: Encoded.AccountAddress[];
347
+ contracts?: Encoded.ContractAddress[];
348
+ },
349
+ ): Promise<Encoded.Poi> {
350
+ return (await call(this, 'channels.get.poi', { accounts, contracts })).poi;
344
351
  }
345
352
 
346
353
  /**
347
354
  * Get balances
348
355
  *
349
- * The accounts paramcontains a list of addresses to fetch balances of.
356
+ * The accounts param contains a list of addresses to fetch balances of.
350
357
  * Those can be either account balances or a contract ones, encoded as an account addresses.
351
358
  *
352
359
  * If a certain account address had not being found in the state tree - it is simply
@@ -364,14 +371,16 @@ export default class Channel {
364
371
  * )
365
372
  * ```
366
373
  */
367
- async balances (accounts: Array<EncodedData<'ak'>>): Promise<{ [key: EncodedData<'ak'>]: string }> {
374
+ async balances(
375
+ accounts: Encoded.AccountAddress[],
376
+ ): Promise<{ [key: Encoded.AccountAddress]: string }> {
368
377
  return Object.fromEntries(
369
378
  (await call(this, 'channels.get.balances', { accounts }))
370
379
  .map((item: {
371
- account: EncodedData<'ak'>
372
- balance: string
373
- }) => [item.account, item.balance])
374
- )
380
+ account: Encoded.AccountAddress;
381
+ balance: string;
382
+ }) => [item.account, item.balance]),
383
+ );
375
384
  }
376
385
 
377
386
  /**
@@ -394,19 +403,20 @@ export default class Channel {
394
403
  * })
395
404
  * ```
396
405
  */
397
- async leave (): Promise<{ channelId: string, signedTx: string }> {
398
- return await new Promise((resolve, reject) => {
406
+ async leave(): Promise<{ channelId: string; signedTx: Encoded.Transaction }> {
407
+ return new Promise((resolve, reject) => {
399
408
  enqueueAction(
400
409
  this,
401
410
  (channel, state) => state?.handler === handlers.channelOpen,
402
- (channel, _state) => {
403
- send(channel, { jsonrpc: '2.0', method: 'channels.leave', params: {} })
411
+ (channel) => {
412
+ send(channel, { jsonrpc: '2.0', method: 'channels.leave', params: {} });
404
413
  return {
405
414
  handler: handlers.awaitingLeave,
406
- state: { resolve, reject }
407
- }
408
- })
409
- })
415
+ state: { resolve, reject },
416
+ };
417
+ },
418
+ );
419
+ });
410
420
  }
411
421
 
412
422
  /**
@@ -423,24 +433,24 @@ export default class Channel {
423
433
  * ).then(tx => console.log('on_chain_tx', tx))
424
434
  * ```
425
435
  */
426
- async shutdown (sign: Function): Promise<string> {
427
- return await new Promise((resolve, reject) => {
436
+ async shutdown(sign: Function): Promise<Encoded.Transaction> {
437
+ return new Promise((resolve, reject) => {
428
438
  enqueueAction(
429
439
  this,
430
440
  (_channel, state) => state?.handler === handlers.channelOpen,
431
441
  (channel) => {
432
- send(channel, { jsonrpc: '2.0', method: 'channels.shutdown', params: {} })
442
+ send(channel, { jsonrpc: '2.0', method: 'channels.shutdown', params: {} });
433
443
  return {
434
444
  handler: handlers.awaitingShutdownTx,
435
445
  state: {
436
446
  sign,
437
447
  resolve,
438
- reject
439
- }
440
- }
441
- }
442
- )
443
- })
448
+ reject,
449
+ },
450
+ };
451
+ },
452
+ );
453
+ });
444
454
  }
445
455
 
446
456
  /**
@@ -492,18 +502,18 @@ export default class Channel {
492
502
  * })
493
503
  * ```
494
504
  */
495
- async withdraw (
505
+ async withdraw(
496
506
  amount: number | BigNumber,
497
507
  sign: SignTx,
498
508
  { onOnChainTx, onOwnWithdrawLocked, onWithdrawLocked }:
499
- { onOnChainTx?: Function, onOwnWithdrawLocked?: Function, onWithdrawLocked?: Function } = {}
500
- ): Promise<{ accepted: boolean, signedTx: string }> {
501
- return await new Promise((resolve, reject) => {
509
+ Pick<ChannelState, 'onOnChainTx' | 'onOwnWithdrawLocked' | 'onWithdrawLocked'> = {},
510
+ ): Promise<{ accepted: boolean; signedTx: Encoded.Transaction }> {
511
+ return new Promise((resolve, reject) => {
502
512
  enqueueAction(
503
513
  this,
504
514
  (_channel, state) => state?.handler === handlers.channelOpen,
505
515
  (channel) => {
506
- send(channel, { jsonrpc: '2.0', method: 'channels.withdraw', params: { amount } })
516
+ send(channel, { jsonrpc: '2.0', method: 'channels.withdraw', params: { amount } });
507
517
  return {
508
518
  handler: handlers.awaitingWithdrawTx,
509
519
  state: {
@@ -512,12 +522,12 @@ export default class Channel {
512
522
  reject,
513
523
  onOnChainTx,
514
524
  onOwnWithdrawLocked,
515
- onWithdrawLocked
516
- }
517
- }
518
- }
519
- )
520
- })
525
+ onWithdrawLocked,
526
+ },
527
+ };
528
+ },
529
+ );
530
+ });
521
531
  }
522
532
 
523
533
  /**
@@ -570,18 +580,18 @@ export default class Channel {
570
580
  * })
571
581
  * ```
572
582
  */
573
- async deposit (
583
+ async deposit(
574
584
  amount: number | BigNumber,
575
585
  sign: SignTx,
576
586
  { onOnChainTx, onOwnDepositLocked, onDepositLocked }:
577
- { onOnChainTx?: Function, onOwnDepositLocked?: Function, onDepositLocked?: Function } = {}
578
- ): Promise<{ accepted: boolean, state: ChannelState }> {
579
- return await new Promise((resolve, reject) => {
587
+ Pick<ChannelState, 'onOnChainTx' | 'onOwnDepositLocked' | 'onDepositLocked'> = {},
588
+ ): Promise<{ accepted: boolean; state: ChannelState }> {
589
+ return new Promise((resolve, reject) => {
580
590
  enqueueAction(
581
591
  this,
582
592
  (_channel, state) => state?.handler === handlers.channelOpen,
583
593
  (channel) => {
584
- send(channel, { jsonrpc: '2.0', method: 'channels.deposit', params: { amount } })
594
+ send(channel, { jsonrpc: '2.0', method: 'channels.deposit', params: { amount } });
585
595
  return {
586
596
  handler: handlers.awaitingDepositTx,
587
597
  state: {
@@ -590,12 +600,12 @@ export default class Channel {
590
600
  reject,
591
601
  onOnChainTx,
592
602
  onOwnDepositLocked,
593
- onDepositLocked
594
- }
595
- }
596
- }
597
- )
598
- })
603
+ onDepositLocked,
604
+ },
605
+ };
606
+ },
607
+ );
608
+ });
599
609
  }
600
610
 
601
611
  /**
@@ -632,17 +642,21 @@ export default class Channel {
632
642
  * })
633
643
  * ```
634
644
  */
635
- async createContract (
636
- { code, callData, deposit, vmVersion, abiVersion }: {
637
- code: string
638
- callData: string
639
- deposit: number | BigNumber
640
- vmVersion: number
641
- abiVersion: number
645
+ async createContract(
646
+ {
647
+ code, callData, deposit, vmVersion, abiVersion,
648
+ }: {
649
+ code: Encoded.ContractBytearray;
650
+ callData: Encoded.ContractBytearray;
651
+ deposit: number | BigNumber;
652
+ vmVersion: number;
653
+ abiVersion: number;
642
654
  },
643
- sign: SignTx
644
- ): Promise<{ accepted: boolean, signedTx: string, address: string }> {
645
- return await new Promise((resolve, reject) => {
655
+ sign: SignTx,
656
+ ): Promise<{
657
+ accepted: boolean; signedTx: Encoded.Transaction; address: Encoded.ContractAddress;
658
+ }> {
659
+ return new Promise((resolve, reject) => {
646
660
  enqueueAction(
647
661
  this,
648
662
  (_channel, state) => state?.handler === handlers.channelOpen,
@@ -655,20 +669,20 @@ export default class Channel {
655
669
  call_data: callData,
656
670
  deposit,
657
671
  vm_version: vmVersion,
658
- abi_version: abiVersion
659
- }
660
- })
672
+ abi_version: abiVersion,
673
+ },
674
+ });
661
675
  return {
662
676
  handler: handlers.awaitingNewContractTx,
663
677
  state: {
664
678
  sign,
665
679
  resolve,
666
- reject
667
- }
668
- }
669
- }
670
- )
671
- })
680
+ reject,
681
+ },
682
+ };
683
+ },
684
+ );
685
+ });
672
686
  }
673
687
 
674
688
  /**
@@ -709,11 +723,13 @@ export default class Channel {
709
723
  * })
710
724
  * ```
711
725
  */
712
- async callContract (
713
- { amount, callData, contract, abiVersion }: CallContractOptions,
714
- sign: SignTx
715
- ): Promise<{ accepted: boolean, signedTx: string }> {
716
- return await new Promise((resolve, reject) => {
726
+ async callContract(
727
+ {
728
+ amount, callData, contract, abiVersion,
729
+ }: CallContractOptions,
730
+ sign: SignTx,
731
+ ): Promise<{ accepted: boolean; signedTx: Encoded.Transaction }> {
732
+ return new Promise((resolve, reject) => {
717
733
  enqueueAction(
718
734
  this,
719
735
  (_channel, state) => state?.handler === handlers.channelOpen,
@@ -725,16 +741,16 @@ export default class Channel {
725
741
  amount,
726
742
  call_data: callData,
727
743
  contract_id: contract,
728
- abi_version: abiVersion
729
- }
730
- })
744
+ abi_version: abiVersion,
745
+ },
746
+ });
731
747
  return {
732
748
  handler: handlers.awaitingCallContractUpdateTx,
733
- state: { resolve, reject, sign }
734
- }
735
- }
736
- )
737
- })
749
+ state: { resolve, reject, sign },
750
+ };
751
+ },
752
+ );
753
+ });
738
754
  }
739
755
 
740
756
  /**
@@ -766,19 +782,25 @@ export default class Channel {
766
782
  * })
767
783
  * ```
768
784
  */
769
- async forceProgress (
770
- { amount, callData, contract, abiVersion, gasLimit = 1000000, gasPrice = 1000000000 }: {
771
- amount: number
772
- callData: string
773
- contract: string
774
- abiVersion: number
775
- gasLimit?: number
776
- gasPrice?: number
785
+ async forceProgress(
786
+ {
787
+ amount, callData, contract, abiVersion, gasLimit = 1000000, gasPrice = MIN_GAS_PRICE,
788
+ }: {
789
+ amount: number;
790
+ callData: Encoded.ContractBytearray;
791
+ contract: Encoded.ContractAddress;
792
+ abiVersion: number;
793
+ gasLimit?: number;
794
+ gasPrice?: number;
777
795
  },
778
796
  sign: SignTx,
779
- { onOnChainTx }: { onOnChainTx?: Function } = {}
780
- ): Promise<{ accepted: boolean, signedTx: string, tx: EncodedData<'tx'> | Uint8Array }> {
781
- return await new Promise((resolve, reject) => {
797
+ { onOnChainTx }: Pick<ChannelState, 'onOnChainTx'> = {},
798
+ ): Promise<{
799
+ accepted: boolean;
800
+ signedTx: Encoded.Transaction;
801
+ tx: Encoded.Transaction | Uint8Array;
802
+ }> {
803
+ return new Promise((resolve, reject) => {
782
804
  enqueueAction(
783
805
  this,
784
806
  (_channel, state) => state?.handler === handlers.channelOpen,
@@ -792,16 +814,18 @@ export default class Channel {
792
814
  contract_id: contract,
793
815
  abi_version: abiVersion,
794
816
  gas_price: gasPrice,
795
- gas: gasLimit
796
- }
797
- })
817
+ gas: gasLimit,
818
+ },
819
+ });
798
820
  return {
799
821
  handler: handlers.awaitingCallContractForceProgressUpdate,
800
- state: { resolve, reject, sign, onOnChainTx }
801
- }
802
- }
803
- )
804
- })
822
+ state: {
823
+ resolve, reject, sign, onOnChainTx,
824
+ },
825
+ };
826
+ },
827
+ );
828
+ });
805
829
  }
806
830
 
807
831
  /**
@@ -811,7 +835,7 @@ export default class Channel {
811
835
  * dry-run a contract call. It takes the exact same arguments as a call would
812
836
  * and returns the call object.
813
837
  *
814
- * The call is executed in the channel's state but it does not impact the state
838
+ * The call is executed in the channel's state, but it does not impact the state
815
839
  * whatsoever. It uses as an environment the latest channel's state and the current
816
840
  * top of the blockchain as seen by the node.
817
841
  *
@@ -833,16 +857,22 @@ export default class Channel {
833
857
  * })
834
858
  * ```
835
859
  */
836
- async callContractStatic (
837
- { amount, callData, contract, abiVersion }:
838
- { amount: number, callData: string, contract: string, abiVersion: number }
860
+ async callContractStatic(
861
+ {
862
+ amount, callData, contract, abiVersion,
863
+ }: {
864
+ amount: number;
865
+ callData: Encoded.ContractBytearray;
866
+ contract: Encoded.ContractAddress;
867
+ abiVersion: number;
868
+ },
839
869
  ): Promise<CallContractOptions> {
840
- return await snakeToPascalObjKeys(await call(this, 'channels.dry_run.call_contract', {
870
+ return snakeToPascalObjKeys(await call(this, 'channels.dry_run.call_contract', {
841
871
  amount,
842
872
  call_data: callData,
843
873
  contract_id: contract,
844
- abi_version: abiVersion
845
- }))
874
+ abi_version: abiVersion,
875
+ }));
846
876
  }
847
877
 
848
878
  /**
@@ -866,27 +896,31 @@ export default class Channel {
866
896
  * })
867
897
  * ```
868
898
  */
869
- async getContractCall (
870
- { caller, contract, round }: { caller: string, contract: string, round: number }
899
+ async getContractCall(
900
+ { caller, contract, round }: {
901
+ caller: Encoded.AccountAddress;
902
+ contract: Encoded.ContractAddress;
903
+ round: number;
904
+ },
871
905
  ): Promise<{
872
- returnType: string
873
- returnValue: string
874
- gasPrice: number | BigNumber
875
- gasUsed: number | BigNumber
876
- height: number
877
- log: string
906
+ returnType: ContractCallReturnType;
907
+ returnValue: string;
908
+ gasPrice: number | BigNumber;
909
+ gasUsed: number | BigNumber;
910
+ height: number;
911
+ log: string;
878
912
  }> {
879
- return await snakeToPascalObjKeys(
913
+ return snakeToPascalObjKeys(
880
914
  await call(this, 'channels.get.contract_call', {
881
915
  caller_id: caller,
882
916
  contract_id: contract,
883
- round
884
- })
885
- )
917
+ round,
918
+ }),
919
+ );
886
920
  }
887
921
 
888
922
  /**
889
- * Get contract latest state
923
+ * Get the latest contract state
890
924
  *
891
925
  * @param contract - Address of the contract
892
926
  * @example
@@ -898,14 +932,14 @@ export default class Channel {
898
932
  * })
899
933
  * ```
900
934
  */
901
- async getContractState (
902
- contract: string
903
- ): Promise<{ contract: Contract, contractState: object }> {
904
- const result = await call(this, 'channels.get.contract', { pubkey: contract })
905
- return await snakeToPascalObjKeys({
935
+ async getContractState(
936
+ contract: Encoded.ContractAddress,
937
+ ): Promise<{ contract: Contract; contractState: object }> {
938
+ const result = await call(this, 'channels.get.contract', { pubkey: contract });
939
+ return snakeToPascalObjKeys({
906
940
  ...result,
907
- contract: snakeToPascalObjKeys(result.contract)
908
- })
941
+ contract: snakeToPascalObjKeys(result.contract),
942
+ });
909
943
  }
910
944
 
911
945
  /**
@@ -916,8 +950,8 @@ export default class Channel {
916
950
  * This cleans up all locally stored contract calls and those will no longer be available for
917
951
  * fetching and inspection.
918
952
  */
919
- async cleanContractCalls (): Promise<void> {
920
- return await new Promise((resolve, reject) => {
953
+ async cleanContractCalls(): Promise<void> {
954
+ return new Promise((resolve, reject) => {
921
955
  enqueueAction(
922
956
  this,
923
957
  (_channel, state) => state?.handler === handlers.channelOpen,
@@ -925,15 +959,15 @@ export default class Channel {
925
959
  send(channel, {
926
960
  jsonrpc: '2.0',
927
961
  method: 'channels.clean_contract_calls',
928
- params: {}
929
- })
962
+ params: {},
963
+ });
930
964
  return {
931
965
  handler: handlers.awaitingCallsPruned,
932
- state: { resolve, reject }
933
- }
934
- }
935
- )
936
- })
966
+ state: { resolve, reject },
967
+ };
968
+ },
969
+ );
970
+ });
937
971
  }
938
972
 
939
973
  /**
@@ -955,37 +989,37 @@ export default class Channel {
955
989
  * )
956
990
  * ```
957
991
  */
958
- sendMessage (message: string | ChannelMessage, recipient: string): void {
959
- let info = message
960
- if (typeof message === 'object') {
961
- info = JSON.stringify(message)
992
+ async sendMessage(
993
+ message: string | object,
994
+ recipient: Encoded.AccountAddress,
995
+ ): Promise<void> {
996
+ const info = typeof message === 'object' ? JSON.stringify(message) : message;
997
+ if (this.status() === 'connecting') {
998
+ await new Promise<void>((resolve) => {
999
+ const onStatusChanged = (status: string): void => {
1000
+ if (status === 'connecting') return;
1001
+ resolve();
1002
+ this.off('statusChanged', onStatusChanged);
1003
+ };
1004
+ this.on('statusChanged', onStatusChanged);
1005
+ });
1006
+ // For some reason we can't immediately send a message when connection is
1007
+ // established. Thus we wait 500ms which seems to work.
1008
+ await pause(500);
962
1009
  }
963
- const doSend = (channel: Channel): void => send(channel, {
1010
+ send(this, {
964
1011
  jsonrpc: '2.0',
965
1012
  method: 'channels.message',
966
- params: { info, to: recipient }
967
- })
968
- if (this.status() === 'connecting') {
969
- const onStatusChanged = (status: string): void => {
970
- if (status !== 'connecting') {
971
- // For some reason we can't immediately send a message when connection is
972
- // established. Thus we wait 500ms which seems to work.
973
- setTimeout(() => doSend(this), 500)
974
- this.off('statusChanged', onStatusChanged)
975
- }
976
- }
977
- this.on('statusChanged', onStatusChanged)
978
- } else {
979
- doSend(this)
980
- }
1013
+ params: { info, to: recipient },
1014
+ });
981
1015
  }
982
1016
 
983
- static async reconnect (options: ChannelOptions, txParams: any): Promise<Channel> {
984
- const { sign } = options
1017
+ static async reconnect(options: ChannelOptions, txParams: any): Promise<Channel> {
1018
+ const { sign } = options;
985
1019
 
986
- return await Channel.initialize({
1020
+ return Channel.initialize({
987
1021
  ...options,
988
- reconnectTx: await sign('reconnect', buildTx(txParams, TX_TYPE.channelReconnect).tx)
989
- })
1022
+ reconnectTx: await sign('reconnect', buildTx(txParams, Tag.ChannelClientReconnectTx).tx),
1023
+ });
990
1024
  }
991
1025
  }