@aeternity/aepp-sdk 10.0.0-beta.1 → 11.0.1

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 (250) hide show
  1. package/README.md +15 -14
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -27
  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 +1 -1
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/account/{base.js → base.mjs} +23 -11
  10. package/es/account/base.mjs.map +1 -0
  11. package/es/account/{memory.js → memory.mjs} +29 -14
  12. package/es/account/memory.mjs.map +1 -0
  13. package/es/account/{multiple.js → multiple.mjs} +14 -11
  14. package/es/account/multiple.mjs.map +1 -0
  15. package/es/ae/{aens.js → aens.mjs} +69 -59
  16. package/es/ae/aens.mjs.map +1 -0
  17. package/es/ae/{aepp.js → aepp.mjs} +9 -9
  18. package/es/ae/aepp.mjs.map +1 -0
  19. package/es/ae/contract.mjs +159 -0
  20. package/es/ae/contract.mjs.map +1 -0
  21. package/es/ae/{index.js → index.mjs} +12 -10
  22. package/es/ae/index.mjs.map +1 -0
  23. package/es/ae/{oracle.js → oracle.mjs} +37 -20
  24. package/es/ae/oracle.mjs.map +1 -0
  25. package/es/ae/{universal.js → universal.mjs} +10 -10
  26. package/es/ae/universal.mjs.map +1 -0
  27. package/es/ae/{wallet.js → wallet.mjs} +10 -10
  28. package/es/ae/wallet.mjs.map +1 -0
  29. package/es/aepp-wallet-communication/schema.d.ts +74 -0
  30. package/es/bignumber.d.ts +1 -7
  31. package/es/chain/{index.js → index.mjs} +28 -8
  32. package/es/chain/index.mjs.map +1 -0
  33. package/es/chain/{node.js → node.mjs} +133 -90
  34. package/es/chain/node.mjs.map +1 -0
  35. package/es/channel/{handlers.js → handlers.mjs} +18 -20
  36. package/es/channel/handlers.mjs.map +1 -0
  37. package/es/channel/{index.js → index.mjs} +43 -22
  38. package/es/channel/index.mjs.map +1 -0
  39. package/es/channel/{internal.js → internal.mjs} +51 -35
  40. package/es/channel/internal.mjs.map +1 -0
  41. package/es/contract/aci.mjs +477 -0
  42. package/es/contract/aci.mjs.map +1 -0
  43. package/es/contract/compiler.mjs +115 -0
  44. package/es/contract/compiler.mjs.map +1 -0
  45. package/es/contract/ga/helpers.mjs +30 -0
  46. package/es/contract/ga/helpers.mjs.map +1 -0
  47. package/es/contract/ga/{index.js → index.mjs} +40 -28
  48. package/es/contract/ga/index.mjs.map +1 -0
  49. package/es/encoder.d.ts +26 -0
  50. package/es/errors.d.ts +284 -0
  51. package/es/index.mjs +57 -0
  52. package/es/index.mjs.map +1 -0
  53. package/es/node-pool/{index.js → index.mjs} +15 -12
  54. package/es/node-pool/index.mjs.map +1 -0
  55. package/es/{node.js → node.mjs} +17 -11
  56. package/es/node.mjs.map +1 -0
  57. package/es/tx/builder/constants.mjs +108 -0
  58. package/es/tx/builder/constants.mjs.map +1 -0
  59. package/es/tx/builder/field-types.mjs +74 -0
  60. package/es/tx/builder/field-types.mjs.map +1 -0
  61. package/es/tx/builder/helpers.mjs +321 -0
  62. package/es/tx/builder/helpers.mjs.map +1 -0
  63. package/es/tx/builder/{index.js → index.mjs} +92 -74
  64. package/es/tx/builder/index.mjs.map +1 -0
  65. package/es/tx/builder/{schema.js → schema.mjs} +16 -172
  66. package/es/tx/builder/schema.mjs.map +1 -0
  67. package/es/tx/{index.js → index.mjs} +106 -14
  68. package/es/tx/index.mjs.map +1 -0
  69. package/es/tx/{tx-object.js → tx-object.mjs} +31 -18
  70. package/es/tx/tx-object.mjs.map +1 -0
  71. package/es/tx/{tx.js → tx.mjs} +15 -14
  72. package/es/tx/tx.mjs.map +1 -0
  73. package/es/tx/{validator.js → validator.mjs} +72 -33
  74. package/es/tx/validator.mjs.map +1 -0
  75. package/es/typings/blakejs/index.d.mjs +2 -0
  76. package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
  77. package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +10 -8
  78. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
  79. package/es/utils/aepp-wallet-communication/connection/{browser-window-message.js → browser-window-message.mjs} +25 -17
  80. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
  81. package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
  82. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
  83. package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +15 -8
  84. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
  85. package/es/utils/aepp-wallet-communication/{helpers.js → helpers.mjs} +3 -14
  86. package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
  87. package/es/utils/aepp-wallet-communication/rpc/{aepp-rpc.js → aepp-rpc.mjs} +126 -72
  88. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
  89. package/es/utils/aepp-wallet-communication/rpc/{rpc-client.js → rpc-client.mjs} +23 -14
  90. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
  91. package/es/utils/aepp-wallet-communication/rpc/{wallet-rpc.js → wallet-rpc.mjs} +116 -91
  92. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
  93. package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
  94. package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
  95. package/es/utils/aepp-wallet-communication/{wallet-detector.js → wallet-detector.mjs} +6 -5
  96. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  97. package/es/utils/{amount-formatter.js → amount-formatter.mjs} +14 -7
  98. package/es/utils/amount-formatter.mjs.map +1 -0
  99. package/es/utils/{async-init.js → async-init.mjs} +8 -11
  100. package/es/utils/async-init.mjs.map +1 -0
  101. package/es/utils/{bignumber.js → bignumber.mjs} +2 -9
  102. package/es/utils/bignumber.mjs.map +1 -0
  103. package/es/utils/{bytes.js → bytes.mjs} +16 -8
  104. package/es/utils/bytes.mjs.map +1 -0
  105. package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
  106. package/es/utils/crypto-ts.mjs.map +1 -0
  107. package/es/utils/{crypto.js → crypto.mjs} +42 -156
  108. package/es/utils/crypto.mjs.map +1 -0
  109. package/es/utils/encoder.mjs +106 -0
  110. package/es/utils/encoder.mjs.map +1 -0
  111. package/es/utils/errors.mjs +689 -0
  112. package/es/utils/errors.mjs.map +1 -0
  113. package/es/utils/{hd-wallet.js → hd-wallet.mjs} +33 -34
  114. package/es/utils/hd-wallet.mjs.map +1 -0
  115. package/es/utils/{json-big.js → json-big.mjs} +1 -1
  116. package/es/utils/{json-big.js.map → json-big.mjs.map} +1 -1
  117. package/es/utils/{keystore.js → keystore.mjs} +63 -51
  118. package/es/utils/keystore.mjs.map +1 -0
  119. package/es/utils/{mptree.js → mptree.mjs} +21 -12
  120. package/es/utils/mptree.mjs.map +1 -0
  121. package/es/utils/{other.js → other.mjs} +2 -2
  122. package/es/utils/other.mjs.map +1 -0
  123. package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
  124. package/es/utils/{semver-satisfies.js.map → semver-satisfies.mjs.map} +1 -1
  125. package/es/utils/{string.js → string.mjs} +1 -1
  126. package/es/utils/{string.js.map → string.mjs.map} +1 -1
  127. package/es/utils/{swagger.js → swagger.mjs} +49 -15
  128. package/es/utils/swagger.mjs.map +1 -0
  129. package/package.json +49 -58
  130. package/src/account/base.js +3 -1
  131. package/src/account/memory.js +13 -8
  132. package/src/account/multiple.js +16 -6
  133. package/src/ae/aens.js +52 -58
  134. package/src/ae/aepp.js +2 -2
  135. package/src/ae/contract.js +21 -154
  136. package/src/ae/index.js +6 -4
  137. package/src/ae/oracle.js +33 -14
  138. package/src/ae/universal.js +4 -2
  139. package/src/ae/wallet.js +2 -2
  140. package/src/chain/index.js +29 -6
  141. package/src/chain/node.js +95 -65
  142. package/src/channel/handlers.js +30 -20
  143. package/src/channel/index.js +46 -16
  144. package/src/channel/internal.js +35 -30
  145. package/src/contract/aci.js +376 -0
  146. package/src/contract/compiler.js +22 -113
  147. package/src/contract/ga/helpers.js +10 -6
  148. package/src/contract/ga/index.js +31 -24
  149. package/src/index.js +9 -8
  150. package/src/node-pool/index.js +13 -10
  151. package/src/node.js +11 -10
  152. package/src/tx/builder/constants.js +100 -0
  153. package/src/tx/builder/field-types.js +61 -0
  154. package/src/tx/builder/helpers.js +99 -103
  155. package/src/tx/builder/index.js +81 -40
  156. package/src/tx/builder/schema.js +44 -132
  157. package/src/tx/index.js +101 -12
  158. package/src/tx/tx-object.js +35 -15
  159. package/src/tx/tx.js +110 -35
  160. package/src/tx/validator.js +25 -5
  161. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
  162. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
  163. package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
  164. package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
  165. package/src/utils/aepp-wallet-communication/helpers.js +6 -14
  166. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +106 -57
  167. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
  168. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +95 -53
  169. package/src/utils/aepp-wallet-communication/schema.ts +80 -0
  170. package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
  171. package/src/utils/amount-formatter.ts +4 -3
  172. package/src/utils/async-init.js +10 -6
  173. package/src/utils/bignumber.ts +1 -9
  174. package/src/utils/bytes.ts +3 -2
  175. package/src/utils/crypto-ts.ts +2 -2
  176. package/src/utils/crypto.js +11 -155
  177. package/src/utils/encoder.ts +101 -0
  178. package/src/utils/errors.ts +683 -0
  179. package/src/utils/hd-wallet.js +11 -26
  180. package/src/utils/keystore.js +57 -53
  181. package/src/utils/mptree.ts +12 -6
  182. package/src/utils/swagger.js +68 -45
  183. package/es/account/base.js.map +0 -1
  184. package/es/account/memory.js.map +0 -1
  185. package/es/account/multiple.js.map +0 -1
  186. package/es/ae/aens.js.map +0 -1
  187. package/es/ae/aepp.js.map +0 -1
  188. package/es/ae/contract.js +0 -308
  189. package/es/ae/contract.js.map +0 -1
  190. package/es/ae/index.js.map +0 -1
  191. package/es/ae/oracle.js.map +0 -1
  192. package/es/ae/universal.js.map +0 -1
  193. package/es/ae/wallet.js.map +0 -1
  194. package/es/chain/index.js.map +0 -1
  195. package/es/chain/node.js.map +0 -1
  196. package/es/channel/handlers.js.map +0 -1
  197. package/es/channel/index.js.map +0 -1
  198. package/es/channel/internal.js.map +0 -1
  199. package/es/contract/aci/helpers.js +0 -298
  200. package/es/contract/aci/helpers.js.map +0 -1
  201. package/es/contract/aci/index.js +0 -356
  202. package/es/contract/aci/index.js.map +0 -1
  203. package/es/contract/aci/transformation.js +0 -66
  204. package/es/contract/aci/transformation.js.map +0 -1
  205. package/es/contract/compiler.js +0 -242
  206. package/es/contract/compiler.js.map +0 -1
  207. package/es/contract/ga/helpers.js +0 -22
  208. package/es/contract/ga/helpers.js.map +0 -1
  209. package/es/contract/ga/index.js.map +0 -1
  210. package/es/contract/index.js +0 -158
  211. package/es/contract/index.js.map +0 -1
  212. package/es/index.js +0 -56
  213. package/es/index.js.map +0 -1
  214. package/es/node-pool/index.js.map +0 -1
  215. package/es/node.js.map +0 -1
  216. package/es/tx/builder/helpers.js +0 -318
  217. package/es/tx/builder/helpers.js.map +0 -1
  218. package/es/tx/builder/index.js.map +0 -1
  219. package/es/tx/builder/schema.js.map +0 -1
  220. package/es/tx/index.js.map +0 -1
  221. package/es/tx/tx-object.js.map +0 -1
  222. package/es/tx/tx.js.map +0 -1
  223. package/es/tx/validator.js.map +0 -1
  224. package/es/typings/blakejs/index.d.js +0 -2
  225. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  226. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  227. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  228. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  229. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  230. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  231. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  232. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  233. package/es/utils/aepp-wallet-communication/schema.js +0 -107
  234. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  235. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  236. package/es/utils/amount-formatter.js.map +0 -1
  237. package/es/utils/async-init.js.map +0 -1
  238. package/es/utils/bignumber.js.map +0 -1
  239. package/es/utils/bytes.js.map +0 -1
  240. package/es/utils/crypto-ts.js.map +0 -1
  241. package/es/utils/crypto.js.map +0 -1
  242. package/es/utils/hd-wallet.js.map +0 -1
  243. package/es/utils/keystore.js.map +0 -1
  244. package/es/utils/mptree.js.map +0 -1
  245. package/es/utils/other.js.map +0 -1
  246. package/es/utils/swagger.js.map +0 -1
  247. package/src/contract/aci/index.js +0 -310
  248. package/src/contract/aci/transformation.js +0 -72
  249. package/src/contract/index.js +0 -159
  250. package/src/utils/aepp-wallet-communication/schema.js +0 -108
@@ -8,7 +8,9 @@
8
8
  // # https://github.com/aeternity/protocol/blob/master/serializations.md#binary-serialization
9
9
 
10
10
  import BigNumber from 'bignumber.js'
11
+ import { Name, NameId, NameFee, Deposit } from './field-types'
11
12
 
13
+ export * from './constants'
12
14
  export const VSN = 1
13
15
  export const VSN_2 = 2
14
16
 
@@ -20,89 +22,11 @@ export const ORACLE_TTL = { type: 'delta', value: 500 }
20
22
  export const QUERY_TTL = { type: 'delta', value: 10 }
21
23
  export const RESPONSE_TTL = { type: 'delta', value: 10 }
22
24
  // # CONTRACT
23
- export const DEPOSIT = 0
24
25
  export const AMOUNT = 0
25
- export const GAS = 25000
26
+ export const GAS_MAX = 1600000 - 21000
26
27
  export const MIN_GAS_PRICE = 1e9
27
28
  export const MAX_AUTH_FUN_GAS = 50000
28
29
  export const DRY_RUN_ACCOUNT = { pub: 'ak_11111111111111111111111111111111273Yts', amount: '100000000000000000000000000000000000' }
29
- // # AENS
30
- export const NAME_TTL = 180000
31
- // # max number of block into the future that the name is going to be available
32
- // # https://github.com/aeternity/protocol/blob/epoch-v0.22.0/AENS.md#update
33
- // # https://github.com/aeternity/protocol/blob/44a93d3aab957ca820183c3520b9daf6b0fedff4/AENS.md#aens-entry
34
- export const NAME_MAX_TTL = 36000
35
- export const NAME_MAX_CLIENT_TTL = 84600
36
- export const CLIENT_TTL = NAME_MAX_CLIENT_TTL
37
- export const NAME_FEE = 0
38
- // # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L67
39
- export const NAME_FEE_MULTIPLIER = 1e14 // 100000000000000
40
- export const NAME_FEE_BID_INCREMENT = 0.05 // # the increment is in percentage
41
- // # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L272
42
- export const NAME_BID_TIMEOUT_BLOCKS = 480 // # ~1 day
43
- export const NAME_MAX_LENGTH_FEE = 31 // # this is the max length for a domain that requires a base fee to be paid
44
- export const NAME_BID_MAX_LENGTH = 12 // # this is the max length for a domain to be part of a bid
45
- export const NAME_ID_KEY = {
46
- ak: 'account_pubkey',
47
- ok: 'oracle_pubkey',
48
- ct: 'contract_pubkey',
49
- ch: 'channel'
50
- }
51
- // # https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L290
52
- // # https://github.com/aeternity/protocol/blob/master/AENS.md#protocol-fees-and-protection-times
53
- // # bid ranges:
54
- export const NAME_BID_RANGES = {
55
- 31: BigNumber(3).times(NAME_FEE_MULTIPLIER),
56
- 30: BigNumber(5).times(NAME_FEE_MULTIPLIER),
57
- 29: BigNumber(8).times(NAME_FEE_MULTIPLIER),
58
- 28: BigNumber(13).times(NAME_FEE_MULTIPLIER),
59
- 27: BigNumber(21).times(NAME_FEE_MULTIPLIER),
60
- 26: BigNumber(34).times(NAME_FEE_MULTIPLIER),
61
- 25: BigNumber(55).times(NAME_FEE_MULTIPLIER),
62
- 24: BigNumber(89).times(NAME_FEE_MULTIPLIER),
63
- 23: BigNumber(144).times(NAME_FEE_MULTIPLIER),
64
- 22: BigNumber(233).times(NAME_FEE_MULTIPLIER),
65
- 21: BigNumber(377).times(NAME_FEE_MULTIPLIER),
66
- 20: BigNumber(610).times(NAME_FEE_MULTIPLIER),
67
- 19: BigNumber(987).times(NAME_FEE_MULTIPLIER),
68
- 18: BigNumber(1597).times(NAME_FEE_MULTIPLIER),
69
- 17: BigNumber(2584).times(NAME_FEE_MULTIPLIER),
70
- 16: BigNumber(4181).times(NAME_FEE_MULTIPLIER),
71
- 15: BigNumber(6765).times(NAME_FEE_MULTIPLIER),
72
- 14: BigNumber(10946).times(NAME_FEE_MULTIPLIER),
73
- 13: BigNumber(17711).times(NAME_FEE_MULTIPLIER),
74
- 12: BigNumber(28657).times(NAME_FEE_MULTIPLIER),
75
- 11: BigNumber(46368).times(NAME_FEE_MULTIPLIER),
76
- 10: BigNumber(75025).times(NAME_FEE_MULTIPLIER),
77
- 9: BigNumber(121393).times(NAME_FEE_MULTIPLIER),
78
- 8: BigNumber(196418).times(NAME_FEE_MULTIPLIER),
79
- 7: BigNumber(317811).times(NAME_FEE_MULTIPLIER),
80
- 6: BigNumber(514229).times(NAME_FEE_MULTIPLIER),
81
- 5: BigNumber(832040).times(NAME_FEE_MULTIPLIER),
82
- 4: BigNumber(1346269).times(NAME_FEE_MULTIPLIER),
83
- 3: BigNumber(2178309).times(NAME_FEE_MULTIPLIER),
84
- 2: BigNumber(3524578).times(NAME_FEE_MULTIPLIER),
85
- 1: BigNumber(5702887).times(NAME_FEE_MULTIPLIER)
86
- }
87
-
88
- // # ref: https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L273
89
- // # name bid timeouts
90
- export const NAME_BID_TIMEOUTS = {
91
- 13: BigNumber(0),
92
- 12: BigNumber(NAME_BID_TIMEOUT_BLOCKS), // # 480 blocks
93
- 8: BigNumber(31).times(NAME_BID_TIMEOUT_BLOCKS), // # 14880 blocks
94
- 4: BigNumber(62).times(NAME_BID_TIMEOUT_BLOCKS) // # 29760 blocks
95
- }
96
-
97
- // # Tag constant for ids (type uint8)
98
- // # see https://github.com/aeternity/protocol/blob/master/serializations.md#the-id-type
99
- // # <<Tag:1/unsigned-integer-unit:8, Hash:32/binary-unit:8>>
100
- const ID_TAG_ACCOUNT = 1
101
- const ID_TAG_NAME = 2
102
- const ID_TAG_COMMITMENT = 3
103
- const ID_TAG_ORACLE = 4
104
- const ID_TAG_CONTRACT = 5
105
- const ID_TAG_CHANNEL = 6
106
30
 
107
31
  // # OBJECT tags
108
32
  // # see https://github.com/aeternity/protocol/blob/master/serializations.md#binary-serialization
@@ -157,8 +81,6 @@ const OBJECT_TAG_SOPHIA_BYTE_CODE = 70
157
81
  const TX_FIELD = (name, type, prefix) => [name, type, prefix]
158
82
  const TX_SCHEMA_FIELD = (schema, objectId) => [schema, objectId]
159
83
 
160
- const revertObject = (obj) => Object.entries(obj).reduce((acc, [key, v]) => (acc[v] = key) && acc, {})
161
-
162
84
  /**
163
85
  * @constant
164
86
  * @description Object with transaction types
@@ -225,7 +147,6 @@ export const TX_TYPE = {
225
147
  nameserviceTree: 'nameserviceTree',
226
148
  oraclesTree: 'oraclesTree',
227
149
  accountsTree: 'accountsTree',
228
- // GA ACCOUNTS
229
150
  gaAttach: 'gaAttach',
230
151
  gaMeta: 'gaMeta',
231
152
  payingFor: 'payingFor',
@@ -325,7 +246,6 @@ export const OBJECT_ID_TX_TYPE = {
325
246
  [OBJECT_TAG_NAMESERVICE_TREE]: TX_TYPE.nameserviceTree,
326
247
  [OBJECT_TAG_ORACLES_TREE]: TX_TYPE.oraclesTree,
327
248
  [OBJECT_TAG_ACCOUNTS_TREE]: TX_TYPE.accountsTree,
328
- // GA Accounts
329
249
  [OBJECT_TAG_GA_ATTACH]: TX_TYPE.gaAttach,
330
250
  [OBJECT_TAG_GA_META]: TX_TYPE.gaMeta,
331
251
  [OBJECT_TAG_PAYING_FOR]: TX_TYPE.payingFor,
@@ -402,35 +322,6 @@ export const TX_FEE_OTHER_GAS = (txType, txSize, { relativeTtl, innerTxSize }) =
402
322
  }
403
323
  }
404
324
 
405
- export const ID_TAG = {
406
- account: ID_TAG_ACCOUNT,
407
- name: ID_TAG_NAME,
408
- commitment: ID_TAG_COMMITMENT,
409
- oracle: ID_TAG_ORACLE,
410
- contract: ID_TAG_CONTRACT,
411
- channel: ID_TAG_CHANNEL
412
- }
413
- export const PREFIX_ID_TAG = {
414
- ak: ID_TAG.account,
415
- nm: ID_TAG.name,
416
- cm: ID_TAG.commitment,
417
- ok: ID_TAG.oracle,
418
- ct: ID_TAG.contract,
419
- ch: ID_TAG.channel
420
- }
421
- export const ID_TAG_PREFIX = revertObject(PREFIX_ID_TAG)
422
- const VALIDATION_ERROR = (msg) => msg
423
-
424
- export const VALIDATION_MESSAGE = {
425
- [FIELD_TYPES.int]: ({ value, isMinusValue }) => isMinusValue ? VALIDATION_ERROR(`${value} must be >= 0`) : VALIDATION_ERROR(`${value} is not of type Number or BigNumber`),
426
- [FIELD_TYPES.amount]: ({ value, isMinusValue }) => isMinusValue ? VALIDATION_ERROR(`${value} must be >= 0`) : VALIDATION_ERROR(`${value} is not of type Number or BigNumber`),
427
- [FIELD_TYPES.id]: ({ value, prefix }) => VALIDATION_ERROR(`'${value}' prefix doesn't match expected prefix '${prefix}' or ID_TAG for prefix not found`),
428
- [FIELD_TYPES.binary]: ({ prefix, value }) => VALIDATION_ERROR(`'${value}' prefix doesn't match expected prefix '${prefix}'`),
429
- [FIELD_TYPES.string]: ({ value }) => VALIDATION_ERROR('Not a string'),
430
- [FIELD_TYPES.pointers]: ({ value }) => VALIDATION_ERROR('Value must be of type Array and contains only object\'s like \'{key: "account_pubkey", id: "ak_lkamsflkalsdalksdlasdlasdlamd"}\''),
431
- [FIELD_TYPES.ctVersion]: ({ value }) => VALIDATION_ERROR('Value must be an object with "vmVersion" and "abiVersion" fields')
432
- }
433
-
434
325
  const BASE_TX = [
435
326
  TX_FIELD('tag', FIELD_TYPES.int),
436
327
  TX_FIELD('VSN', FIELD_TYPES.int)
@@ -484,9 +375,9 @@ const NAME_CLAIM_TX_2 = [
484
375
  ...BASE_TX,
485
376
  TX_FIELD('accountId', FIELD_TYPES.id, 'ak'),
486
377
  TX_FIELD('nonce', FIELD_TYPES.int),
487
- TX_FIELD('name', FIELD_TYPES.binary, 'nm'),
378
+ TX_FIELD('name', Name),
488
379
  TX_FIELD('nameSalt', FIELD_TYPES.int),
489
- TX_FIELD('nameFee', FIELD_TYPES.amount),
380
+ TX_FIELD('nameFee', NameFee),
490
381
  TX_FIELD('fee', FIELD_TYPES.int),
491
382
  TX_FIELD('ttl', FIELD_TYPES.int)
492
383
  ]
@@ -495,7 +386,7 @@ const NAME_UPDATE_TX = [
495
386
  ...BASE_TX,
496
387
  TX_FIELD('accountId', FIELD_TYPES.id, 'ak'),
497
388
  TX_FIELD('nonce', FIELD_TYPES.int),
498
- TX_FIELD('nameId', FIELD_TYPES.id, 'nm'),
389
+ TX_FIELD('nameId', NameId),
499
390
  TX_FIELD('nameTtl', FIELD_TYPES.int),
500
391
  TX_FIELD('pointers', FIELD_TYPES.pointers),
501
392
  TX_FIELD('clientTtl', FIELD_TYPES.int),
@@ -507,7 +398,7 @@ const NAME_TRANSFER_TX = [
507
398
  ...BASE_TX,
508
399
  TX_FIELD('accountId', FIELD_TYPES.id, 'ak'),
509
400
  TX_FIELD('nonce', FIELD_TYPES.int),
510
- TX_FIELD('nameId', FIELD_TYPES.id, 'nm'),
401
+ TX_FIELD('nameId', NameId),
511
402
  TX_FIELD('recipientId', FIELD_TYPES.id, ['ak', 'nm']),
512
403
  TX_FIELD('fee', FIELD_TYPES.int),
513
404
  TX_FIELD('ttl', FIELD_TYPES.int)
@@ -517,7 +408,7 @@ const NAME_REVOKE_TX = [
517
408
  ...BASE_TX,
518
409
  TX_FIELD('accountId', FIELD_TYPES.id, 'ak'),
519
410
  TX_FIELD('nonce', FIELD_TYPES.int),
520
- TX_FIELD('nameId', FIELD_TYPES.id, 'nm'),
411
+ TX_FIELD('nameId', NameId),
521
412
  TX_FIELD('fee', FIELD_TYPES.int),
522
413
  TX_FIELD('ttl', FIELD_TYPES.int)
523
414
  ]
@@ -530,7 +421,7 @@ const CONTRACT_TX = [
530
421
  TX_FIELD('log', FIELD_TYPES.binary, 'cb'),
531
422
  TX_FIELD('active', FIELD_TYPES.bool),
532
423
  TX_FIELD('referers', FIELD_TYPES.ids, 'ak'),
533
- TX_FIELD('deposit', FIELD_TYPES.amount)
424
+ TX_FIELD('deposit', Deposit)
534
425
  ]
535
426
 
536
427
  const GA_ATTACH_TX = [
@@ -574,7 +465,7 @@ const CONTRACT_CREATE_TX = [
574
465
  TX_FIELD('ctVersion', FIELD_TYPES.ctVersion),
575
466
  TX_FIELD('fee', FIELD_TYPES.int),
576
467
  TX_FIELD('ttl', FIELD_TYPES.int),
577
- TX_FIELD('deposit', FIELD_TYPES.amount),
468
+ TX_FIELD('deposit', Deposit),
578
469
  TX_FIELD('amount', FIELD_TYPES.amount),
579
470
  TX_FIELD('gas', FIELD_TYPES.int),
580
471
  TX_FIELD('gasPrice', FIELD_TYPES.int),
@@ -605,7 +496,8 @@ const CONTRACT_CALL_RESULT_TX = [
605
496
  TX_FIELD('gasUsed', FIELD_TYPES.int),
606
497
  TX_FIELD('returnValue', FIELD_TYPES.binary, 'cb'),
607
498
  TX_FIELD('returnType', FIELD_TYPES.callReturnType),
608
- // TODO: add serialization for <log> :: [ { <address> :: id, [ <topics> :: binary() ], <data> :: binary() } ]
499
+ // TODO: add serialization for
500
+ // <log> :: [ { <address> :: id, [ <topics> :: binary() ], <data> :: binary() } ]
609
501
  TX_FIELD('log', FIELD_TYPES.rawBinary)
610
502
  ]
611
503
 
@@ -749,8 +641,8 @@ const CHANNEL_FORCE_PROGRESS_TX = [
749
641
  TX_FIELD('fromId', FIELD_TYPES.id, 'ak'),
750
642
  TX_FIELD('payload', FIELD_TYPES.binary, 'tx'),
751
643
  TX_FIELD('round', FIELD_TYPES.int),
752
- TX_FIELD('update', FIELD_TYPES.binary),
753
- TX_FIELD('stateHash', FIELD_TYPES.binary),
644
+ TX_FIELD('update', FIELD_TYPES.binary, 'cb'),
645
+ TX_FIELD('stateHash', FIELD_TYPES.binary, 'st'),
754
646
  TX_FIELD('offChainTrees', FIELD_TYPES.stateTree),
755
647
  TX_FIELD('ttl', FIELD_TYPES.int),
756
648
  TX_FIELD('fee', FIELD_TYPES.int),
@@ -985,19 +877,29 @@ export const TX_SERIALIZATION_SCHEMA = {
985
877
  1: TX_SCHEMA_FIELD(CHANNEL_SNAPSHOT_SOLO_TX, OBJECT_TAG_CHANNEL_SNAPSHOT_SOLO_TX)
986
878
  },
987
879
  [TX_TYPE.channelOffChainUpdateTransfer]: {
988
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX)
880
+ 1: TX_SCHEMA_FIELD(
881
+ CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX
882
+ )
989
883
  },
990
884
  [TX_TYPE.channelOffChainUpdateDeposit]: {
991
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX)
885
+ 1: TX_SCHEMA_FIELD(
886
+ CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX
887
+ )
992
888
  },
993
889
  [TX_TYPE.channelOffChainUpdateWithdrawal]: {
994
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX)
890
+ 1: TX_SCHEMA_FIELD(
891
+ CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX
892
+ )
995
893
  },
996
894
  [TX_TYPE.channelOffChainCreateContract]: {
997
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX)
895
+ 1: TX_SCHEMA_FIELD(
896
+ CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX
897
+ )
998
898
  },
999
899
  [TX_TYPE.channelOffChainCallContract]: {
1000
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_CALL_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CALL_CONTRACT_TX)
900
+ 1: TX_SCHEMA_FIELD(
901
+ CHANNEL_OFFCHAIN_CALL_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CALL_CONTRACT_TX
902
+ )
1001
903
  },
1002
904
  [TX_TYPE.channelReconnect]: {
1003
905
  1: TX_SCHEMA_FIELD(CHANNEL_RECONNECT_TX, OBJECT_TAG_CHANNEL_RECONNECT_TX)
@@ -1123,19 +1025,29 @@ export const TX_DESERIALIZATION_SCHEMA = {
1123
1025
  1: TX_SCHEMA_FIELD(CHANNEL_SNAPSHOT_SOLO_TX, OBJECT_TAG_CHANNEL_SNAPSHOT_SOLO_TX)
1124
1026
  },
1125
1027
  [OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX]: {
1126
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX)
1028
+ 1: TX_SCHEMA_FIELD(
1029
+ CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX
1030
+ )
1127
1031
  },
1128
1032
  [OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX]: {
1129
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX)
1033
+ 1: TX_SCHEMA_FIELD(
1034
+ CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX
1035
+ )
1130
1036
  },
1131
1037
  [OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX]: {
1132
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX)
1038
+ 1: TX_SCHEMA_FIELD(
1039
+ CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX
1040
+ )
1133
1041
  },
1134
1042
  [OBJECT_TAG_CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX]: {
1135
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX)
1043
+ 1: TX_SCHEMA_FIELD(
1044
+ CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX
1045
+ )
1136
1046
  },
1137
1047
  [OBJECT_TAG_CHANNEL_OFFCHAIN_CALL_CONTRACT_TX]: {
1138
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_CALL_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CALL_CONTRACT_TX)
1048
+ 1: TX_SCHEMA_FIELD(
1049
+ CHANNEL_OFFCHAIN_CALL_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CALL_CONTRACT_TX
1050
+ )
1139
1051
  },
1140
1052
  [OBJECT_TAG_CHANNEL_RECONNECT_TX]: {
1141
1053
  1: TX_SCHEMA_FIELD(CHANNEL_RECONNECT_TX, OBJECT_TAG_CHANNEL_RECONNECT_TX)
package/src/tx/index.js CHANGED
@@ -72,7 +72,15 @@ const Tx = stampit(required({
72
72
  * @instance
73
73
  * @abstract
74
74
  * @category async
75
- * @rtype ({sender?: String, recipientId: String, amount: Number, fee?: Number, ttl?: Number, nonce?: Number, payload?: String}) => tx: Promise[String]
75
+ * @rtype ({
76
+ * sender?: String,
77
+ * recipientId: String,
78
+ * amount: Number,
79
+ * fee?: Number,
80
+ * ttl?: Number,
81
+ * nonce?: Number,
82
+ * payload?: String
83
+ * }) => tx: Promise[String]
76
84
  * @param {Object} options - The object to extract properties from
77
85
  * @return {String} `spend_tx` transaction
78
86
  */
@@ -83,7 +91,9 @@ const Tx = stampit(required({
83
91
  * @instance
84
92
  * @abstract
85
93
  * @category async
86
- * @rtype ({account?: String, commitment: String, fee?: Number, ttl?: Number, nonce?: Number}) => tx: Promise[String]
94
+ * @rtype ({
95
+ * account?: String, commitment: String, fee?: Number, ttl?: Number, nonce?: Number
96
+ * }) => tx: Promise[String]
87
97
  * @param {Object} options - The object to extract properties from
88
98
  * @return {String} `name_preclaim_tx` transaction
89
99
  */
@@ -94,7 +104,9 @@ const Tx = stampit(required({
94
104
  * @instance
95
105
  * @abstract
96
106
  * @category async
97
- * @rtype ({account?: String, name: String, nameSalt: String, fee?: Number, ttl?: Number, nonce?: Number}) => tx: Promise[String]
107
+ * @rtype ({
108
+ * account?: String, name: String, nameSalt: String, fee?: Number, ttl?: Number, nonce?: Number
109
+ * }) => tx: Promise[String]
98
110
  * @param {Object} options - The object to extract properties from
99
111
  * @return {String} `name_claim_tx` transaction
100
112
  */
@@ -105,7 +117,14 @@ const Tx = stampit(required({
105
117
  * @instance
106
118
  * @abstract
107
119
  * @category async
108
- * @rtype ({account?: String, nameId: String, recipientId: String, fee?: Number, ttl?: Number, nonce?: Number}) => tx: Promise[String]
120
+ * @rtype ({
121
+ * account?: String,
122
+ * nameId: String,
123
+ * recipientId: String,
124
+ * fee?: Number,
125
+ * ttl?: Number,
126
+ * nonce?: Number
127
+ * }) => tx: Promise[String]
109
128
  * @param {Object} options - The object to extract properties from
110
129
  * @return {String} `name_transfer_tx` transaction
111
130
  */
@@ -116,7 +135,16 @@ const Tx = stampit(required({
116
135
  * @instance
117
136
  * @abstract
118
137
  * @category async
119
- * @rtype ({account?: String, nameId: String, pointers: Object, nameTtl: Number, clientTtl: Number, fee?: Number, ttl?: Number, nonce?: Number}) => tx: Promise[String]
138
+ * @rtype ({
139
+ * account?: String,
140
+ * nameId: String,
141
+ * pointers: Object,
142
+ * nameTtl: Number,
143
+ * clientTtl: Number,
144
+ * fee?: Number,
145
+ * ttl?: Number,
146
+ * nonce?: Number
147
+ * }) => tx: Promise[String]
120
148
  * @param {Object} options - The object to extract properties from
121
149
  * @return {String} `name_update_tx` transaction
122
150
  */
@@ -127,7 +155,9 @@ const Tx = stampit(required({
127
155
  * @instance
128
156
  * @abstract
129
157
  * @category async
130
- * @rtype ({account?: String, nameId: String, fee?: Number, ttl?: Number, nonce?: Number}) => tx: Promise[String]
158
+ * @rtype ({
159
+ * account?: String, nameId: String, fee?: Number, ttl?: Number, nonce?: Number
160
+ * }) => tx: Promise[String]
131
161
  * @param {Object} options - The object to extract properties from
132
162
  * @return {String} `name_revoke_tx` transaction
133
163
  */
@@ -138,7 +168,19 @@ const Tx = stampit(required({
138
168
  * @instance
139
169
  * @abstract
140
170
  * @category async
141
- * @rtype ({owner: String, code: String, callData: String, vmVersion: Number, deposit: Number, amount: Number, gas: Number, gasPrice: Number, fee?: Number, ttl?: Number, nonce?: Number}) => tx: Promise[String]
171
+ * @rtype ({
172
+ * owner: String,
173
+ * code: String,
174
+ * callData: String,
175
+ * vmVersion: Number,
176
+ * deposit: Number,
177
+ * amount: Number,
178
+ * gas: Number,
179
+ * gasPrice: Number,
180
+ * fee?: Number,
181
+ * ttl?: Number,
182
+ * nonce?: Number
183
+ * }) => tx: Promise[String]
142
184
  * @param {Object} options - The object to extract properties from
143
185
  * @return {String} `contract_create_tx` transaction
144
186
  */
@@ -149,7 +191,18 @@ const Tx = stampit(required({
149
191
  * @instance
150
192
  * @abstract
151
193
  * @category async
152
- * @rtype ({callerId: String, contract: String, callData: String, vmVersion: Number, amount: Number, gas: Number, gasPrice: Number, fee?: Number, ttl?: Number, nonce?: Number}) => tx: Promise[String]
194
+ * @rtype ({
195
+ * callerId: String,
196
+ * contract: String,
197
+ * callData: String,
198
+ * vmVersion: Number,
199
+ * amount: Number,
200
+ * gas: Number,
201
+ * gasPrice: Number,
202
+ * fee?: Number,
203
+ * ttl?: Number,
204
+ * nonce?: Number
205
+ * }) => tx: Promise[String]
153
206
  * @param {Object} options - The object to extract properties from
154
207
  * @return {String} `contract_call_tx` transaction
155
208
  */
@@ -160,7 +213,17 @@ const Tx = stampit(required({
160
213
  * @instance
161
214
  * @abstract
162
215
  * @category async
163
- * @rtype ({ accountId: String, queryFormat: String, responseFormat: String, queryFee: String|Number, oracleTtl: Object, vmVersion: Number = ORACLE_VM_VERSION, fee?: Number, ttl?: Number, nonce?: Number }) => tx: Promise[String]
216
+ * @rtype ({
217
+ * accountId: String,
218
+ * queryFormat: String,
219
+ * responseFormat: String,
220
+ * queryFee: String|Number,
221
+ * oracleTtl: Object,
222
+ * vmVersion: Number = ORACLE_VM_VERSION,
223
+ * fee?: Number,
224
+ * ttl?: Number,
225
+ * nonce?: Number
226
+ * }) => tx: Promise[String]
164
227
  * @param {Object} options - The object to extract properties from
165
228
  * @return {String} `oracle_register_tx` transaction
166
229
  */
@@ -171,7 +234,14 @@ const Tx = stampit(required({
171
234
  * @instance
172
235
  * @abstract
173
236
  * @category async
174
- * @rtype ({ oracleId: String, callerId: String, oracleTtl: Object, fee?: Number, ttl: Number, nonce?: Number}) => tx: Promise[String]
237
+ * @rtype ({
238
+ * oracleId: String,
239
+ * callerId: String,
240
+ * oracleTtl: Object,
241
+ * fee?: Number,
242
+ * ttl: Number,
243
+ * nonce?: Number
244
+ * }) => tx: Promise[String]
175
245
  * @param {Object} options - The object to extract properties from
176
246
  * @return {String} `oracle_extend_tx` transaction
177
247
  */
@@ -182,7 +252,17 @@ const Tx = stampit(required({
182
252
  * @instance
183
253
  * @abstract
184
254
  * @category async
185
- * @rtype ({ oracleId: String, responseTtl: Object, query: String, queryTtl: Object, queryFee: String|Number, senderId: String, fee?: Number, ttl: Number, nonce?: Number}) => tx: Promise[String]
255
+ * @rtype ({
256
+ * oracleId: String,
257
+ * responseTtl: Object,
258
+ * query: String,
259
+ * queryTtl: Object,
260
+ * queryFee: String|Number,
261
+ * senderId: String,
262
+ * fee?: Number,
263
+ * ttl: Number,
264
+ * nonce?: Number
265
+ * }) => tx: Promise[String]
186
266
  * @param {Object} options - The object to extract properties from
187
267
  * @return {String} `oracle_post_query_tx` transaction
188
268
  */
@@ -193,7 +273,16 @@ const Tx = stampit(required({
193
273
  * @instance
194
274
  * @abstract
195
275
  * @category async
196
- * @rtype ({ oracleId: String, callerId: String, responseTtl: Object, queryId: String, response: String, fee?: Number, ttl?: Number, nonce?: Number}) => tx: Promise[String]
276
+ * @rtype ({
277
+ * oracleId: String,
278
+ * callerId: String,
279
+ * responseTtl: Object,
280
+ * queryId: String,
281
+ * response: String,
282
+ * fee?: Number,
283
+ * ttl?: Number,
284
+ * nonce?: Number
285
+ * }) => tx: Promise[String]
197
286
  * @param {Object} options - The object to extract properties from
198
287
  * @return {String} `oracle_respond_tx` transaction
199
288
  */
@@ -9,6 +9,7 @@ import { buildTx, calculateFee, unpackTx } from './builder'
9
9
  import { TX_TYPE } from './builder/schema'
10
10
  import { encode } from './builder/helpers'
11
11
  import { isHex } from '../utils/string'
12
+ import { InvalidTxError, TypeError, UnknownTxError, InvalidSignatureError } from '../utils/errors'
12
13
 
13
14
  /**
14
15
  * Build transaction from object
@@ -17,33 +18,40 @@ import { isHex } from '../utils/string'
17
18
  * @param {Object} params Transaction params
18
19
  * @param {Object} [options={}] Options
19
20
  * @throws {Error} Arguments validation error's
20
- * @return {{ encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, params: Object, type: String }}
21
+ * @return {{
22
+ * encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, params: Object, type: String
23
+ * }}
21
24
  */
22
25
  const buildTransaction = (type, params, options = {}) => {
23
- if (typeof params !== 'object') throw new Error('"params" should be an object')
24
- if (typeof type !== 'string' || !Object.values(TX_TYPE).includes(type)) throw new Error(`Unknown transaction type ${type}`)
26
+ if (typeof params !== 'object') throw new TypeError('tx "params" should be an object')
27
+ if (typeof type !== 'string' || !Object.values(TX_TYPE).includes(type)) throw new UnknownTxError(`Unknown transaction type ${type}`)
25
28
  const fee = calculateFee(params.fee, type, { gas: params.gas, params, vsn: params.vsn })
26
- const { rlpEncoded, binary, tx: encodedTx, txObject } = buildTx({ ...params, fee }, type, { vsn: params.vsn, ...options })
29
+ const { rlpEncoded, binary, tx: encodedTx, txObject } = buildTx(
30
+ { ...params, fee }, type, { vsn: params.vsn, ...options }
31
+ )
27
32
  return { rlpEncoded, binary, encodedTx, params: txObject, type }
28
33
  }
29
34
 
30
35
  /**
31
36
  * Unpack transaction from RLP encoded binary or base64c string
32
37
  * @alias module:@aeternity/aepp-sdk/es/tx/tx-object
33
- * @param {Buffer|String} tx RLP encoded binary or base64c(rlpBinary) string
38
+ * @param {Uint8Array|String} tx RLP encoded binary or base64c(rlpBinary) string
34
39
  * @throws {Error} Arguments validation error's
35
- * @return {{ encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, type: String, params: Object }}
40
+ * @return {{
41
+ * encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, type: String, params: Object
42
+ * }}
36
43
  */
37
44
  const unpackTransaction = (tx) => {
38
- if (!tx) throw new Error(`Invalid transaction: ${tx}`)
45
+ if (!tx) throw new InvalidTxError(`Invalid transaction: ${tx}`)
39
46
  if (typeof tx === 'string') {
40
47
  const { txType: type, tx: params, rlpEncoded, binary } = unpackTx(tx)
41
48
  return { encodedTx: tx, type, params, rlpEncoded, binary }
42
49
  }
43
- if (Buffer.isBuffer(tx)) {
50
+ if (tx instanceof Uint8Array) {
44
51
  const { txType: type, tx: params, rlpEncoded, binary } = unpackTx(tx, true)
45
52
  return { encodedTx: encode(tx, 'tx'), type, params, rlpEncoded, binary }
46
53
  }
54
+ throw new InvalidTxError(`"tx" should be a string or Uint8Array, got ${tx} instead`)
47
55
  }
48
56
 
49
57
  /**
@@ -55,12 +63,14 @@ const unpackTransaction = (tx) => {
55
63
  * @param {String} type Transaction type
56
64
  * @param {Object} [options={}] Options
57
65
  * @throws {Error} Arguments validation error's
58
- * @return {{encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, type: String, params: Object}}
66
+ * @return {{
67
+ * encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, type: String, params: Object
68
+ * }}
59
69
  */
60
70
  const initTransaction = ({ tx, params, type, options = {} } = {}) => {
61
71
  if (params && type) return buildTransaction(type, params, options)
62
72
  if (tx) return unpackTransaction(tx)
63
- throw new Error('Invalid TxObject arguments. Please provide one of { tx: "tx_asdasd23..." } or { type: "spendTx", params: {...} }')
73
+ throw new InvalidTxError('Invalid TxObject arguments. Please provide one of { tx: "tx_asdasd23..." } or { type: "spendTx", params: {...} }')
64
74
  }
65
75
 
66
76
  /**
@@ -119,10 +129,15 @@ export const TxObject = stampit({
119
129
  * @return {TxObject}
120
130
  */
121
131
  setProp (props = {}, options = {}) {
122
- if (typeof props !== 'object') throw new Error('Props should be an object')
132
+ if (typeof props !== 'object') throw new TypeError('Props should be an object')
123
133
  this.isSigned = false
124
134
  this.signatures = []
125
- Object.assign(this, buildTransaction(this.type, { ...this.params, ...props, fee: null }, { ...this.options, ...options }))
135
+ Object.assign(
136
+ this,
137
+ buildTransaction(
138
+ this.type, { ...this.params, ...props, fee: null }, { ...this.options, ...options }
139
+ )
140
+ )
126
141
  return this
127
142
  },
128
143
  /**
@@ -131,7 +146,6 @@ export const TxObject = stampit({
131
146
  * @return {Array} Array of signatures
132
147
  */
133
148
  getSignatures () {
134
- if (!this.isSigned) throw new Error('Signature not found, transaction is not signed')
135
149
  return this.signatures
136
150
  },
137
151
  /**
@@ -142,8 +156,14 @@ export const TxObject = stampit({
142
156
  */
143
157
  addSignature (signature) {
144
158
  signature = isHex(signature) ? Buffer.from(signature, 'hex') : signature
145
- if (!Buffer.isBuffer(signature) && !(signature instanceof Uint8Array)) throw new Error('Invalid signature, signature must be of type Buffer or Uint8Array')
146
- Object.assign(this, buildTransaction(TX_TYPE.signed, { encodedTx: this.rlpEncoded, signatures: [[...this.signatures, signature]] }))
159
+ if (!Buffer.isBuffer(signature) && !(signature instanceof Uint8Array)) throw new InvalidSignatureError('Invalid signature, signature must be of type Buffer or Uint8Array')
160
+ Object.assign(
161
+ this,
162
+ buildTransaction(
163
+ TX_TYPE.signed,
164
+ { encodedTx: this.rlpEncoded, signatures: [[...this.signatures, signature]] }
165
+ )
166
+ )
147
167
 
148
168
  const { signatures, encodedTx: { txType, tx } } = this.params
149
169
  this.signatures = signatures