@aeternity/aepp-sdk 9.0.1 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) 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 -36
  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.mjs +179 -0
  10. package/es/account/base.mjs.map +1 -0
  11. package/es/account/memory.mjs +99 -0
  12. package/es/account/memory.mjs.map +1 -0
  13. package/es/account/multiple.mjs +179 -0
  14. package/es/account/multiple.mjs.map +1 -0
  15. package/es/ae/aens.mjs +404 -0
  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.mjs +207 -0
  22. package/es/ae/index.mjs.map +1 -0
  23. package/es/ae/oracle.mjs +339 -0
  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} +29 -9
  32. package/es/chain/index.mjs.map +1 -0
  33. package/es/chain/node.mjs +442 -0
  34. package/es/chain/node.mjs.map +1 -0
  35. package/es/channel/handlers.mjs +1110 -0
  36. package/es/channel/handlers.mjs.map +1 -0
  37. package/es/channel/{index.js → index.mjs} +245 -472
  38. package/es/channel/index.mjs.map +1 -0
  39. package/es/channel/internal.mjs +283 -0
  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.mjs +178 -0
  48. package/es/contract/ga/index.mjs.map +1 -0
  49. package/es/errors.d.ts +284 -0
  50. package/es/index.mjs +57 -0
  51. package/es/index.mjs.map +1 -0
  52. package/es/node-pool/index.mjs +188 -0
  53. package/es/node-pool/index.mjs.map +1 -0
  54. package/es/node.mjs +133 -0
  55. package/es/node.mjs.map +1 -0
  56. package/es/other.d.ts +1 -1
  57. package/es/tx/builder/field-types.mjs +74 -0
  58. package/es/tx/builder/field-types.mjs.map +1 -0
  59. package/es/tx/builder/helpers.mjs +363 -0
  60. package/es/tx/builder/helpers.mjs.map +1 -0
  61. package/es/tx/builder/index.mjs +606 -0
  62. package/es/tx/builder/index.mjs.map +1 -0
  63. package/es/tx/builder/schema.mjs +760 -0
  64. package/es/tx/builder/schema.mjs.map +1 -0
  65. package/es/tx/{index.js → index.mjs} +107 -15
  66. package/es/tx/index.mjs.map +1 -0
  67. package/es/tx/tx-object.mjs +283 -0
  68. package/es/tx/tx-object.mjs.map +1 -0
  69. package/es/tx/tx.mjs +938 -0
  70. package/es/tx/tx.mjs.map +1 -0
  71. package/es/tx/validator.mjs +247 -0
  72. package/es/tx/validator.mjs.map +1 -0
  73. package/es/typings/blakejs/index.d.mjs +2 -0
  74. package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
  75. package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +27 -29
  76. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
  77. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +183 -0
  78. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
  79. package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
  80. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
  81. package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +29 -23
  82. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
  83. package/es/utils/aepp-wallet-communication/helpers.mjs +92 -0
  84. package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
  85. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +375 -0
  86. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
  87. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +275 -0
  88. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
  89. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +541 -0
  90. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
  91. package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
  92. package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
  93. package/es/utils/aepp-wallet-communication/wallet-detector.mjs +110 -0
  94. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  95. package/es/utils/amount-formatter.mjs +139 -0
  96. package/es/utils/amount-formatter.mjs.map +1 -0
  97. package/es/utils/async-init.mjs +64 -0
  98. package/es/utils/async-init.mjs.map +1 -0
  99. package/es/utils/bignumber.mjs +21 -0
  100. package/es/utils/bignumber.mjs.map +1 -0
  101. package/es/utils/{bytes.js → bytes.mjs} +16 -12
  102. package/es/utils/bytes.mjs.map +1 -0
  103. package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
  104. package/es/utils/crypto-ts.mjs.map +1 -0
  105. package/es/utils/crypto.mjs +239 -0
  106. package/es/utils/crypto.mjs.map +1 -0
  107. package/es/utils/errors.mjs +689 -0
  108. package/es/utils/errors.mjs.map +1 -0
  109. package/es/utils/hd-wallet.mjs +111 -0
  110. package/es/utils/hd-wallet.mjs.map +1 -0
  111. package/es/utils/json-big.mjs +45 -0
  112. package/es/utils/json-big.mjs.map +1 -0
  113. package/es/utils/keystore.mjs +240 -0
  114. package/es/utils/keystore.mjs.map +1 -0
  115. package/es/utils/mptree.mjs +161 -0
  116. package/es/utils/mptree.mjs.map +1 -0
  117. package/es/utils/other.mjs +43 -0
  118. package/es/utils/other.mjs.map +1 -0
  119. package/es/utils/semver-satisfies.mjs +16 -0
  120. package/es/utils/semver-satisfies.mjs.map +1 -0
  121. package/es/utils/{string.js → string.mjs} +5 -14
  122. package/es/utils/string.mjs.map +1 -0
  123. package/es/utils/swagger.mjs +164 -0
  124. package/es/utils/swagger.mjs.map +1 -0
  125. package/package.json +55 -62
  126. package/src/account/base.js +3 -1
  127. package/src/account/memory.js +13 -8
  128. package/src/account/multiple.js +31 -22
  129. package/src/ae/aens.js +75 -77
  130. package/src/ae/aepp.js +2 -2
  131. package/src/ae/contract.js +27 -291
  132. package/src/ae/index.js +9 -7
  133. package/src/ae/oracle.js +51 -28
  134. package/src/ae/universal.js +4 -2
  135. package/src/ae/wallet.js +2 -2
  136. package/src/chain/index.js +29 -6
  137. package/src/chain/node.js +95 -67
  138. package/src/channel/handlers.js +30 -21
  139. package/src/channel/index.js +44 -20
  140. package/src/channel/internal.js +30 -24
  141. package/src/contract/aci.js +376 -0
  142. package/src/contract/compiler.js +41 -91
  143. package/src/contract/ga/helpers.js +10 -13
  144. package/src/contract/ga/index.js +42 -33
  145. package/src/index.js +9 -10
  146. package/src/node-pool/index.js +29 -17
  147. package/src/node.js +33 -36
  148. package/src/tx/builder/field-types.js +61 -0
  149. package/src/tx/builder/helpers.js +126 -84
  150. package/src/tx/builder/index.js +83 -41
  151. package/src/tx/builder/schema.js +50 -40
  152. package/src/tx/index.js +101 -12
  153. package/src/tx/tx-object.js +35 -15
  154. package/src/tx/tx.js +232 -153
  155. package/src/tx/validator.js +34 -12
  156. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
  157. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
  158. package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
  159. package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
  160. package/src/utils/aepp-wallet-communication/helpers.js +6 -14
  161. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +107 -60
  162. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
  163. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +98 -56
  164. package/src/utils/aepp-wallet-communication/schema.ts +80 -0
  165. package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
  166. package/src/utils/amount-formatter.ts +4 -3
  167. package/src/utils/async-init.js +10 -6
  168. package/src/utils/bignumber.ts +3 -10
  169. package/src/utils/bytes.ts +3 -2
  170. package/src/utils/crypto-ts.ts +2 -2
  171. package/src/utils/crypto.js +10 -144
  172. package/src/utils/errors.ts +683 -0
  173. package/src/utils/hd-wallet.js +11 -26
  174. package/src/utils/keystore.js +57 -53
  175. package/src/utils/mptree.ts +12 -6
  176. package/src/utils/other.ts +1 -1
  177. package/src/utils/semver-satisfies.ts +1 -1
  178. package/src/utils/swagger.js +75 -45
  179. package/es/account/base.js +0 -259
  180. package/es/account/base.js.map +0 -1
  181. package/es/account/memory.js +0 -86
  182. package/es/account/memory.js.map +0 -1
  183. package/es/account/multiple.js +0 -267
  184. package/es/account/multiple.js.map +0 -1
  185. package/es/ae/aens.js +0 -829
  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 -985
  189. package/es/ae/contract.js.map +0 -1
  190. package/es/ae/index.js +0 -442
  191. package/es/ae/index.js.map +0 -1
  192. package/es/ae/oracle.js +0 -690
  193. package/es/ae/oracle.js.map +0 -1
  194. package/es/ae/universal.js.map +0 -1
  195. package/es/ae/wallet.js.map +0 -1
  196. package/es/chain/index.js.map +0 -1
  197. package/es/chain/node.js +0 -1119
  198. package/es/chain/node.js.map +0 -1
  199. package/es/channel/handlers.js +0 -1601
  200. package/es/channel/handlers.js.map +0 -1
  201. package/es/channel/index.js.map +0 -1
  202. package/es/channel/internal.js +0 -438
  203. package/es/channel/internal.js.map +0 -1
  204. package/es/contract/aci/helpers.js +0 -298
  205. package/es/contract/aci/helpers.js.map +0 -1
  206. package/es/contract/aci/index.js +0 -517
  207. package/es/contract/aci/index.js.map +0 -1
  208. package/es/contract/aci/transformation.js +0 -742
  209. package/es/contract/aci/transformation.js.map +0 -1
  210. package/es/contract/compiler.js +0 -316
  211. package/es/contract/compiler.js.map +0 -1
  212. package/es/contract/ga/helpers.js +0 -120
  213. package/es/contract/ga/helpers.js.map +0 -1
  214. package/es/contract/ga/index.js +0 -307
  215. package/es/contract/ga/index.js.map +0 -1
  216. package/es/contract/index.js +0 -158
  217. package/es/contract/index.js.map +0 -1
  218. package/es/index.js +0 -57
  219. package/es/index.js.map +0 -1
  220. package/es/node-pool/index.js +0 -204
  221. package/es/node-pool/index.js.map +0 -1
  222. package/es/node.js +0 -228
  223. package/es/node.js.map +0 -1
  224. package/es/tx/builder/helpers.js +0 -355
  225. package/es/tx/builder/helpers.js.map +0 -1
  226. package/es/tx/builder/index.js +0 -686
  227. package/es/tx/builder/index.js.map +0 -1
  228. package/es/tx/builder/schema.js +0 -695
  229. package/es/tx/builder/schema.js.map +0 -1
  230. package/es/tx/index.js.map +0 -1
  231. package/es/tx/tx-object.js +0 -297
  232. package/es/tx/tx-object.js.map +0 -1
  233. package/es/tx/tx.js +0 -1757
  234. package/es/tx/tx.js.map +0 -1
  235. package/es/tx/validator.js +0 -344
  236. package/es/tx/validator.js.map +0 -1
  237. package/es/typings/blakejs/index.d.js +0 -2
  238. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  239. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -211
  240. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  241. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  242. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  243. package/es/utils/aepp-wallet-communication/helpers.js +0 -148
  244. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  245. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -652
  246. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  247. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -285
  248. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  249. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -763
  250. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  251. package/es/utils/aepp-wallet-communication/schema.js +0 -103
  252. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  253. package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -135
  254. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  255. package/es/utils/amount-formatter.js +0 -152
  256. package/es/utils/amount-formatter.js.map +0 -1
  257. package/es/utils/async-init.js +0 -103
  258. package/es/utils/async-init.js.map +0 -1
  259. package/es/utils/bignumber.js +0 -36
  260. package/es/utils/bignumber.js.map +0 -1
  261. package/es/utils/bytes.js.map +0 -1
  262. package/es/utils/crypto-ts.js.map +0 -1
  263. package/es/utils/crypto.js +0 -358
  264. package/es/utils/crypto.js.map +0 -1
  265. package/es/utils/hd-wallet.js +0 -148
  266. package/es/utils/hd-wallet.js.map +0 -1
  267. package/es/utils/json-big.js +0 -78
  268. package/es/utils/json-big.js.map +0 -1
  269. package/es/utils/keystore.js +0 -393
  270. package/es/utils/keystore.js.map +0 -1
  271. package/es/utils/mptree.js +0 -198
  272. package/es/utils/mptree.js.map +0 -1
  273. package/es/utils/other.js +0 -93
  274. package/es/utils/other.js.map +0 -1
  275. package/es/utils/semver-satisfies.js +0 -35
  276. package/es/utils/semver-satisfies.js.map +0 -1
  277. package/es/utils/string.js.map +0 -1
  278. package/es/utils/swagger.js +0 -269
  279. package/es/utils/swagger.js.map +0 -1
  280. package/src/contract/aci/helpers.js +0 -140
  281. package/src/contract/aci/index.js +0 -191
  282. package/src/contract/aci/transformation.js +0 -464
  283. package/src/contract/index.js +0 -159
  284. package/src/utils/aepp-wallet-communication/schema.js +0 -110
@@ -8,6 +8,7 @@
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
 
12
13
  export const VSN = 1
13
14
  export const VSN_2 = 2
@@ -20,9 +21,8 @@ export const ORACLE_TTL = { type: 'delta', value: 500 }
20
21
  export const QUERY_TTL = { type: 'delta', value: 10 }
21
22
  export const RESPONSE_TTL = { type: 'delta', value: 10 }
22
23
  // # CONTRACT
23
- export const DEPOSIT = 0
24
24
  export const AMOUNT = 0
25
- export const GAS = 25000
25
+ export const GAS_MAX = 1600000 - 21000
26
26
  export const MIN_GAS_PRICE = 1e9
27
27
  export const MAX_AUTH_FUN_GAS = 50000
28
28
  export const DRY_RUN_ACCOUNT = { pub: 'ak_11111111111111111111111111111111273Yts', amount: '100000000000000000000000000000000000' }
@@ -34,21 +34,22 @@ export const NAME_TTL = 180000
34
34
  export const NAME_MAX_TTL = 36000
35
35
  export const NAME_MAX_CLIENT_TTL = 84600
36
36
  export const CLIENT_TTL = NAME_MAX_CLIENT_TTL
37
- export const NAME_FEE = 0
38
37
  // # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L67
39
38
  export const NAME_FEE_MULTIPLIER = 1e14 // 100000000000000
40
39
  export const NAME_FEE_BID_INCREMENT = 0.05 // # the increment is in percentage
41
40
  // # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L272
42
41
  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
42
+ // # this is the max length for a domain that requires a base fee to be paid
43
+ export const NAME_MAX_LENGTH_FEE = 31
44
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 = {
45
+ export const POINTER_KEY_BY_PREFIX = {
46
46
  ak: 'account_pubkey',
47
47
  ok: 'oracle_pubkey',
48
48
  ct: 'contract_pubkey',
49
49
  ch: 'channel'
50
50
  }
51
- // # ref: https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L290
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
52
53
  // # bid ranges:
53
54
  export const NAME_BID_RANGES = {
54
55
  31: BigNumber(3).times(NAME_FEE_MULTIPLIER),
@@ -156,7 +157,8 @@ const OBJECT_TAG_SOPHIA_BYTE_CODE = 70
156
157
  const TX_FIELD = (name, type, prefix) => [name, type, prefix]
157
158
  const TX_SCHEMA_FIELD = (schema, objectId) => [schema, objectId]
158
159
 
159
- const revertObject = (obj) => Object.entries(obj).reduce((acc, [key, v]) => (acc[v] = key) && acc, {})
160
+ const revertObject = (obj) => Object.entries(obj)
161
+ .reduce((acc, [key, v]) => (acc[v] = key) && acc, {})
160
162
 
161
163
  /**
162
164
  * @constant
@@ -224,7 +226,6 @@ export const TX_TYPE = {
224
226
  nameserviceTree: 'nameserviceTree',
225
227
  oraclesTree: 'oraclesTree',
226
228
  accountsTree: 'accountsTree',
227
- // GA ACCOUNTS
228
229
  gaAttach: 'gaAttach',
229
230
  gaMeta: 'gaMeta',
230
231
  payingFor: 'payingFor',
@@ -324,7 +325,6 @@ export const OBJECT_ID_TX_TYPE = {
324
325
  [OBJECT_TAG_NAMESERVICE_TREE]: TX_TYPE.nameserviceTree,
325
326
  [OBJECT_TAG_ORACLES_TREE]: TX_TYPE.oraclesTree,
326
327
  [OBJECT_TAG_ACCOUNTS_TREE]: TX_TYPE.accountsTree,
327
- // GA Accounts
328
328
  [OBJECT_TAG_GA_ATTACH]: TX_TYPE.gaAttach,
329
329
  [OBJECT_TAG_GA_META]: TX_TYPE.gaMeta,
330
330
  [OBJECT_TAG_PAYING_FOR]: TX_TYPE.payingFor,
@@ -418,17 +418,6 @@ export const PREFIX_ID_TAG = {
418
418
  ch: ID_TAG.channel
419
419
  }
420
420
  export const ID_TAG_PREFIX = revertObject(PREFIX_ID_TAG)
421
- const VALIDATION_ERROR = (msg) => msg
422
-
423
- export const VALIDATION_MESSAGE = {
424
- [FIELD_TYPES.int]: ({ value, isMinusValue }) => isMinusValue ? VALIDATION_ERROR(`${value} must be >= 0`) : VALIDATION_ERROR(`${value} is not of type Number or BigNumber`),
425
- [FIELD_TYPES.amount]: ({ value, isMinusValue }) => isMinusValue ? VALIDATION_ERROR(`${value} must be >= 0`) : VALIDATION_ERROR(`${value} is not of type Number or BigNumber`),
426
- [FIELD_TYPES.id]: ({ value, prefix }) => VALIDATION_ERROR(`'${value}' prefix doesn't match expected prefix '${prefix}' or ID_TAG for prefix not found`),
427
- [FIELD_TYPES.binary]: ({ prefix, value }) => VALIDATION_ERROR(`'${value}' prefix doesn't match expected prefix '${prefix}'`),
428
- [FIELD_TYPES.string]: ({ value }) => VALIDATION_ERROR('Not a string'),
429
- [FIELD_TYPES.pointers]: ({ value }) => VALIDATION_ERROR('Value must be of type Array and contains only object\'s like \'{key: "account_pubkey", id: "ak_lkamsflkalsdalksdlasdlasdlamd"}\''),
430
- [FIELD_TYPES.ctVersion]: ({ value }) => VALIDATION_ERROR('Value must be an object with "vmVersion" and "abiVersion" fields')
431
- }
432
421
 
433
422
  const BASE_TX = [
434
423
  TX_FIELD('tag', FIELD_TYPES.int),
@@ -483,9 +472,9 @@ const NAME_CLAIM_TX_2 = [
483
472
  ...BASE_TX,
484
473
  TX_FIELD('accountId', FIELD_TYPES.id, 'ak'),
485
474
  TX_FIELD('nonce', FIELD_TYPES.int),
486
- TX_FIELD('name', FIELD_TYPES.binary, 'nm'),
475
+ TX_FIELD('name', Name),
487
476
  TX_FIELD('nameSalt', FIELD_TYPES.int),
488
- TX_FIELD('nameFee', FIELD_TYPES.amount),
477
+ TX_FIELD('nameFee', NameFee),
489
478
  TX_FIELD('fee', FIELD_TYPES.int),
490
479
  TX_FIELD('ttl', FIELD_TYPES.int)
491
480
  ]
@@ -494,7 +483,7 @@ const NAME_UPDATE_TX = [
494
483
  ...BASE_TX,
495
484
  TX_FIELD('accountId', FIELD_TYPES.id, 'ak'),
496
485
  TX_FIELD('nonce', FIELD_TYPES.int),
497
- TX_FIELD('nameId', FIELD_TYPES.id, 'nm'),
486
+ TX_FIELD('nameId', NameId),
498
487
  TX_FIELD('nameTtl', FIELD_TYPES.int),
499
488
  TX_FIELD('pointers', FIELD_TYPES.pointers),
500
489
  TX_FIELD('clientTtl', FIELD_TYPES.int),
@@ -506,7 +495,7 @@ const NAME_TRANSFER_TX = [
506
495
  ...BASE_TX,
507
496
  TX_FIELD('accountId', FIELD_TYPES.id, 'ak'),
508
497
  TX_FIELD('nonce', FIELD_TYPES.int),
509
- TX_FIELD('nameId', FIELD_TYPES.id, 'nm'),
498
+ TX_FIELD('nameId', NameId),
510
499
  TX_FIELD('recipientId', FIELD_TYPES.id, ['ak', 'nm']),
511
500
  TX_FIELD('fee', FIELD_TYPES.int),
512
501
  TX_FIELD('ttl', FIELD_TYPES.int)
@@ -516,7 +505,7 @@ const NAME_REVOKE_TX = [
516
505
  ...BASE_TX,
517
506
  TX_FIELD('accountId', FIELD_TYPES.id, 'ak'),
518
507
  TX_FIELD('nonce', FIELD_TYPES.int),
519
- TX_FIELD('nameId', FIELD_TYPES.id, 'nm'),
508
+ TX_FIELD('nameId', NameId),
520
509
  TX_FIELD('fee', FIELD_TYPES.int),
521
510
  TX_FIELD('ttl', FIELD_TYPES.int)
522
511
  ]
@@ -529,7 +518,7 @@ const CONTRACT_TX = [
529
518
  TX_FIELD('log', FIELD_TYPES.binary, 'cb'),
530
519
  TX_FIELD('active', FIELD_TYPES.bool),
531
520
  TX_FIELD('referers', FIELD_TYPES.ids, 'ak'),
532
- TX_FIELD('deposit', FIELD_TYPES.amount)
521
+ TX_FIELD('deposit', Deposit)
533
522
  ]
534
523
 
535
524
  const GA_ATTACH_TX = [
@@ -573,7 +562,7 @@ const CONTRACT_CREATE_TX = [
573
562
  TX_FIELD('ctVersion', FIELD_TYPES.ctVersion),
574
563
  TX_FIELD('fee', FIELD_TYPES.int),
575
564
  TX_FIELD('ttl', FIELD_TYPES.int),
576
- TX_FIELD('deposit', FIELD_TYPES.amount),
565
+ TX_FIELD('deposit', Deposit),
577
566
  TX_FIELD('amount', FIELD_TYPES.amount),
578
567
  TX_FIELD('gas', FIELD_TYPES.int),
579
568
  TX_FIELD('gasPrice', FIELD_TYPES.int),
@@ -604,7 +593,8 @@ const CONTRACT_CALL_RESULT_TX = [
604
593
  TX_FIELD('gasUsed', FIELD_TYPES.int),
605
594
  TX_FIELD('returnValue', FIELD_TYPES.binary, 'cb'),
606
595
  TX_FIELD('returnType', FIELD_TYPES.callReturnType),
607
- // TODO: add serialization for <log> :: [ { <address> :: id, [ <topics> :: binary() ], <data> :: binary() } ]
596
+ // TODO: add serialization for
597
+ // <log> :: [ { <address> :: id, [ <topics> :: binary() ], <data> :: binary() } ]
608
598
  TX_FIELD('log', FIELD_TYPES.rawBinary)
609
599
  ]
610
600
 
@@ -748,8 +738,8 @@ const CHANNEL_FORCE_PROGRESS_TX = [
748
738
  TX_FIELD('fromId', FIELD_TYPES.id, 'ak'),
749
739
  TX_FIELD('payload', FIELD_TYPES.binary, 'tx'),
750
740
  TX_FIELD('round', FIELD_TYPES.int),
751
- TX_FIELD('update', FIELD_TYPES.binary),
752
- TX_FIELD('stateHash', FIELD_TYPES.binary),
741
+ TX_FIELD('update', FIELD_TYPES.binary, 'cb'),
742
+ TX_FIELD('stateHash', FIELD_TYPES.binary, 'st'),
753
743
  TX_FIELD('offChainTrees', FIELD_TYPES.stateTree),
754
744
  TX_FIELD('ttl', FIELD_TYPES.int),
755
745
  TX_FIELD('fee', FIELD_TYPES.int),
@@ -984,19 +974,29 @@ export const TX_SERIALIZATION_SCHEMA = {
984
974
  1: TX_SCHEMA_FIELD(CHANNEL_SNAPSHOT_SOLO_TX, OBJECT_TAG_CHANNEL_SNAPSHOT_SOLO_TX)
985
975
  },
986
976
  [TX_TYPE.channelOffChainUpdateTransfer]: {
987
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX)
977
+ 1: TX_SCHEMA_FIELD(
978
+ CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX
979
+ )
988
980
  },
989
981
  [TX_TYPE.channelOffChainUpdateDeposit]: {
990
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX)
982
+ 1: TX_SCHEMA_FIELD(
983
+ CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX
984
+ )
991
985
  },
992
986
  [TX_TYPE.channelOffChainUpdateWithdrawal]: {
993
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX)
987
+ 1: TX_SCHEMA_FIELD(
988
+ CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX
989
+ )
994
990
  },
995
991
  [TX_TYPE.channelOffChainCreateContract]: {
996
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX)
992
+ 1: TX_SCHEMA_FIELD(
993
+ CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX
994
+ )
997
995
  },
998
996
  [TX_TYPE.channelOffChainCallContract]: {
999
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_CALL_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CALL_CONTRACT_TX)
997
+ 1: TX_SCHEMA_FIELD(
998
+ CHANNEL_OFFCHAIN_CALL_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CALL_CONTRACT_TX
999
+ )
1000
1000
  },
1001
1001
  [TX_TYPE.channelReconnect]: {
1002
1002
  1: TX_SCHEMA_FIELD(CHANNEL_RECONNECT_TX, OBJECT_TAG_CHANNEL_RECONNECT_TX)
@@ -1122,19 +1122,29 @@ export const TX_DESERIALIZATION_SCHEMA = {
1122
1122
  1: TX_SCHEMA_FIELD(CHANNEL_SNAPSHOT_SOLO_TX, OBJECT_TAG_CHANNEL_SNAPSHOT_SOLO_TX)
1123
1123
  },
1124
1124
  [OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX]: {
1125
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX)
1125
+ 1: TX_SCHEMA_FIELD(
1126
+ CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_TRANSFER_TX
1127
+ )
1126
1128
  },
1127
1129
  [OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX]: {
1128
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX)
1130
+ 1: TX_SCHEMA_FIELD(
1131
+ CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_DEPOSIT_TX
1132
+ )
1129
1133
  },
1130
1134
  [OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX]: {
1131
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX)
1135
+ 1: TX_SCHEMA_FIELD(
1136
+ CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_UPDATE_WITHDRAWAL_TX
1137
+ )
1132
1138
  },
1133
1139
  [OBJECT_TAG_CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX]: {
1134
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX)
1140
+ 1: TX_SCHEMA_FIELD(
1141
+ CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CREATE_CONTRACT_TX
1142
+ )
1135
1143
  },
1136
1144
  [OBJECT_TAG_CHANNEL_OFFCHAIN_CALL_CONTRACT_TX]: {
1137
- 1: TX_SCHEMA_FIELD(CHANNEL_OFFCHAIN_CALL_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CALL_CONTRACT_TX)
1145
+ 1: TX_SCHEMA_FIELD(
1146
+ CHANNEL_OFFCHAIN_CALL_CONTRACT_TX, OBJECT_TAG_CHANNEL_OFFCHAIN_CALL_CONTRACT_TX
1147
+ )
1138
1148
  },
1139
1149
  [OBJECT_TAG_CHANNEL_RECONNECT_TX]: {
1140
1150
  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