@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
@@ -1,26 +1,30 @@
1
- import * as R from 'ramda'
2
1
  import BigNumber from 'bignumber.js'
3
-
4
- import {
5
- decodeBase58Check,
6
- decodeBase64Check,
7
- encodeBase58Check, encodeBase64Check,
8
- hash,
9
- salt
10
- } from '../../utils/crypto'
2
+ import bs58 from 'bs58'
3
+ import { hash, salt, sha256hash } from '../../utils/crypto'
11
4
  import { toBytes } from '../../utils/bytes'
12
5
  import {
13
6
  ID_TAG_PREFIX,
14
7
  PREFIX_ID_TAG,
15
8
  NAME_BID_RANGES,
16
- NAME_BID_MAX_LENGTH,
17
- NAME_FEE,
18
9
  NAME_FEE_BID_INCREMENT,
19
10
  NAME_BID_TIMEOUTS,
20
11
  NAME_MAX_LENGTH_FEE,
21
- NAME_ID_KEY
12
+ POINTER_KEY_BY_PREFIX
22
13
  } from './schema'
23
14
  import { ceil } from '../../utils/bignumber'
15
+ import {
16
+ PrefixMismatchError,
17
+ DecodeError,
18
+ EncodeError,
19
+ PayloadLengthError,
20
+ TagNotFoundError,
21
+ PrefixNotFoundError,
22
+ InvalidNameError,
23
+ IllegalBidFeeError,
24
+ NoDefaultAensPointerError,
25
+ ArgumentError,
26
+ InvalidChecksumError
27
+ } from '../../utils/errors'
24
28
 
25
29
  /**
26
30
  * JavaScript-based Transaction builder helper function's
@@ -31,8 +35,6 @@ import { ceil } from '../../utils/bignumber'
31
35
 
32
36
  export const createSalt = salt
33
37
 
34
- const base64Types = ['tx', 'st', 'ss', 'pi', 'ov', 'or', 'cb', 'cs', 'ba']
35
-
36
38
  /**
37
39
  * Build a contract public key
38
40
  * @function
@@ -78,11 +80,11 @@ export function formatSalt (salt) {
78
80
  }
79
81
 
80
82
  /**
81
- * Encode a domain name
83
+ * Encode an AENS name
82
84
  * @function
83
85
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
84
86
  * @param {String} name Name to encode
85
- * @return {String} `nm_` prefixed encoded domain name
87
+ * @return {String} `nm_` prefixed encoded AENS name
86
88
  */
87
89
  export function produceNameId (name) {
88
90
  ensureNameValid(name)
@@ -103,24 +105,72 @@ export function produceNameId (name) {
103
105
  */
104
106
  export function commitmentHash (name, salt = createSalt()) {
105
107
  ensureNameValid(name)
106
- return `cm_${encodeBase58Check(hash(Buffer.concat([Buffer.from(name.toLowerCase()), formatSalt(salt)])))}`
108
+ return encode(hash(Buffer.concat([Buffer.from(name.toLowerCase()), formatSalt(salt)])), 'cm')
109
+ }
110
+
111
+ // based on https://github.com/aeternity/protocol/blob/master/node/api/api_encoding.md
112
+ const base64Types = ['ba', 'cb', 'or', 'ov', 'pi', 'ss', 'cs', 'ck', 'cv', 'st', 'tx']
113
+ const base58Types = ['ak', 'bf', 'bs', 'bx', 'ch', 'cm', 'ct', 'kh', 'mh', 'nm', 'ok', 'oq', 'pp', 'sg', 'th']
114
+ // TODO: add all types with a fixed length
115
+ const typesLength = {
116
+ ak: 32,
117
+ ct: 32,
118
+ ok: 32
119
+ }
120
+
121
+ function ensureValidLength (data, type) {
122
+ if (!typesLength[type]) return
123
+ if (data.length === typesLength[type]) return
124
+ throw new PayloadLengthError(`Payload should be ${typesLength[type]} bytes, got ${data.length} instead`)
125
+ }
126
+
127
+ const getChecksum = payload => sha256hash(sha256hash(payload)).slice(0, 4)
128
+
129
+ const addChecksum = (input) => {
130
+ const payload = Buffer.from(input)
131
+ return Buffer.concat([payload, getChecksum(payload)])
132
+ }
133
+
134
+ function getPayload (buffer) {
135
+ const payload = buffer.slice(0, -4)
136
+ if (!getChecksum(payload).equals(buffer.slice(-4))) throw new InvalidChecksumError()
137
+ return payload
138
+ }
139
+
140
+ const base64 = {
141
+ encode: buffer => addChecksum(buffer).toString('base64'),
142
+ decode: string => getPayload(Buffer.from(string, 'base64'))
143
+ }
144
+
145
+ const base58 = {
146
+ encode: buffer => bs58.encode(addChecksum(buffer)),
147
+ decode: string => getPayload(bs58.decode(string))
107
148
  }
108
149
 
109
150
  /**
110
151
  * Decode data using the default encoding/decoding algorithm
111
152
  * @function
112
153
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
113
- * @param {string} data An Base58check or Base64check encoded and prefixed string (ex tx_..., sg_..., ak_....)
154
+ * @param {string} data An Base58/64check encoded and prefixed string (ex tx_..., sg_..., ak_....)
114
155
  * @param {string} [requiredPrefix] Ensure that data have this prefix
115
156
  * @return {Buffer} Decoded data
116
157
  */
117
158
  export function decode (data, requiredPrefix) {
118
- const [prefix, payload, extra] = data.split('_')
119
- if (extra) throw new Error(`Encoded string have extra parts: ${data}`)
159
+ if (typeof data !== 'string') throw new DecodeError(`Encoded should be a string, got ${data} instead`)
160
+ const [prefix, encodedPayload, extra] = data.split('_')
161
+ if (!encodedPayload) throw new DecodeError(`Encoded string missing payload: ${data}`)
162
+ if (extra) throw new DecodeError(`Encoded string have extra parts: ${data}`)
120
163
  if (requiredPrefix && requiredPrefix !== prefix) {
121
- throw new Error(`Encoded string have a wrong type: ${prefix} (expected: ${requiredPrefix})`)
164
+ throw new PrefixMismatchError(prefix, requiredPrefix)
122
165
  }
123
- return (base64Types.includes(prefix) ? decodeBase64Check : decodeBase58Check)(payload)
166
+ const decoder = (base64Types.includes(prefix) && base64.decode) ||
167
+ (base58Types.includes(prefix) && base58.decode)
168
+ if (!decoder) {
169
+ throw new DecodeError(`Encoded string have unknown type: ${prefix}`)
170
+ }
171
+ const payload = decoder(encodedPayload)
172
+ ensureValidLength(payload, prefix)
173
+ return payload
124
174
  }
125
175
 
126
176
  /**
@@ -132,9 +182,13 @@ export function decode (data, requiredPrefix) {
132
182
  * @return {String} Encoded string Base58check or Base64check data
133
183
  */
134
184
  export function encode (data, type) {
135
- return `${type}_${base64Types.includes(type)
136
- ? encodeBase64Check(data)
137
- : encodeBase58Check(data)}`
185
+ const encoder = (base64Types.includes(type) && base64.encode) ||
186
+ (base58Types.includes(type) && base58.encode)
187
+ if (!encoder) {
188
+ throw new EncodeError(`Unknown type: ${type}`)
189
+ }
190
+ ensureValidLength(data, type)
191
+ return `${type}_${encoder(data)}`
138
192
  }
139
193
 
140
194
  /**
@@ -145,9 +199,10 @@ export function encode (data, type) {
145
199
  * @return {Buffer} Buffer Buffer with ID tag and decoded HASh
146
200
  */
147
201
  export function writeId (hashId) {
202
+ if (typeof hashId !== 'string') throw new ArgumentError('hashId', 'a string', hashId)
148
203
  const prefix = hashId.slice(0, 2)
149
204
  const idTag = PREFIX_ID_TAG[prefix]
150
- if (!idTag) throw new Error(`Id tag for prefix ${prefix} not found.`)
205
+ if (!idTag) throw new TagNotFoundError(prefix)
151
206
  return Buffer.from([...toBytes(idTag), ...decode(hashId, prefix)])
152
207
  }
153
208
 
@@ -159,9 +214,9 @@ export function writeId (hashId) {
159
214
  * @return {String} Encoided hash string with prefix
160
215
  */
161
216
  export function readId (buf) {
162
- const tag = buf.readUIntBE(0, 1)
217
+ const tag = Buffer.from(buf).readUIntBE(0, 1)
163
218
  const prefix = ID_TAG_PREFIX[tag]
164
- if (!prefix) throw new Error(`Prefix for id-tag ${tag} not found.`)
219
+ if (!prefix) throw new PrefixNotFoundError(tag)
165
220
  return encode(buf.slice(1, buf.length), prefix)
166
221
  }
167
222
 
@@ -184,14 +239,15 @@ export function writeInt (val) {
184
239
  * @return {String} Buffer Buffer from number(BigEndian)
185
240
  */
186
241
  export function readInt (buf = Buffer.from([])) {
187
- return BigNumber(buf.toString('hex'), 16).toString(10)
242
+ return new BigNumber(Buffer.from(buf).toString('hex'), 16).toString(10)
188
243
  }
189
244
 
190
245
  /**
191
246
  * Helper function to build pointers for name update TX
192
247
  * @function
193
248
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
194
- * @param {Array} pointers - Array of pointers ([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])
249
+ * @param {Array} pointers - Array of pointers
250
+ * ([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])
195
251
  * @return {Array} Serialized pointers array
196
252
  */
197
253
  export function buildPointers (pointers) {
@@ -207,7 +263,8 @@ export function buildPointers (pointers) {
207
263
  * Helper function to read pointers from name update TX
208
264
  * @function
209
265
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
210
- * @param {Array} pointers - Array of pointers ([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])
266
+ * @param {Array} pointers - Array of pointers
267
+ * ([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])
211
268
  * @return {Array} Deserialize pointer array
212
269
  */
213
270
  export function readPointers (pointers) {
@@ -219,8 +276,10 @@ export function readPointers (pointers) {
219
276
  )
220
277
  }
221
278
 
279
+ const AENS_SUFFIX = '.chain'
280
+
222
281
  /**
223
- * Ensure that name is valid
282
+ * Ensure that AENS name is valid
224
283
  * @function
225
284
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
226
285
  * @param {string} name
@@ -228,12 +287,12 @@ export function readPointers (pointers) {
228
287
  * @throws Error
229
288
  */
230
289
  export function ensureNameValid (name) {
231
- if (!name || typeof name !== 'string') throw new Error('Name must be a string')
232
- if (!name.endsWith('.chain')) throw new Error(`Name should end with .chain: ${name}`)
290
+ if (!name || typeof name !== 'string') throw new InvalidNameError('Name must be a string')
291
+ if (!name.endsWith(AENS_SUFFIX)) throw new InvalidNameError(`Name should end with ${AENS_SUFFIX}: ${name}`)
233
292
  }
234
293
 
235
294
  /**
236
- * Is name valid
295
+ * Is AENS name valid
237
296
  * @function
238
297
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
239
298
  * @param {string} name
@@ -249,63 +308,44 @@ export function isNameValid (name) {
249
308
  }
250
309
 
251
310
  /**
252
- * What kind of a hash is this? If it begins with 'ak_' it is an
253
- * account key, if with 'ok_' it's an oracle key.
254
- *
255
- * @param s - the hash.
256
- * returns the type, or throws an exception if type not found.
311
+ * @param identifier - account/oracle/contract address, or channel
312
+ * @returns {String} default AENS pointer key
313
+ * @throws exception when default key not defined
257
314
  */
258
- export function classify (s) {
259
- if (!s.match(/^[a-z]{2}_.+/)) {
260
- throw new Error('Not a valid hash')
261
- }
262
-
263
- const klass = s.substr(0, 2)
264
- if (klass in NAME_ID_KEY) {
265
- return NAME_ID_KEY[klass]
266
- } else {
267
- throw new Error(`Unknown class ${klass}`)
268
- }
315
+ export function getDefaultPointerKey (identifier) {
316
+ decode(identifier)
317
+ const prefix = identifier.substr(0, 2)
318
+ return POINTER_KEY_BY_PREFIX[prefix] ||
319
+ (() => { throw new NoDefaultAensPointerError(prefix) })()
269
320
  }
270
321
 
271
322
  /**
272
- * Validate name pointers array
323
+ * Get the minimum AENS name fee
273
324
  * @function
274
325
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
275
- * @param {String[]} pointers Pointers array. Allowed values is: account(ak_), oracle(ok_), contract(ct_), channel(ch_)
276
- * @return {Boolean}
326
+ * @param {String} name the AENS name to get the fee for
327
+ * @return {String} the minimum fee for the AENS name auction
277
328
  */
278
- export function validatePointers (pointers = []) {
279
- return !pointers
280
- .find(p => !p || typeof p !== 'string' || !['ak', 'ok', 'ct', 'ch'].includes(p.split('_')[0]))
281
- }
282
-
283
- /**
284
- * Get the minimum name fee for a domain
285
- * @function
286
- * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
287
- * @param {String} domain the domain name to get the fee for
288
- * @return {String} the minimum fee for the domain auction
289
- */
290
- export function getMinimumNameFee (domain) {
291
- const nameLength = domain.replace('.chain', '').length
292
- return NAME_BID_RANGES[nameLength >= NAME_MAX_LENGTH_FEE ? NAME_MAX_LENGTH_FEE : nameLength]
329
+ export function getMinimumNameFee (name) {
330
+ ensureNameValid(name)
331
+ const nameLength = name.length - AENS_SUFFIX.length
332
+ return NAME_BID_RANGES[Math.min(nameLength, NAME_MAX_LENGTH_FEE)]
293
333
  }
294
334
 
295
335
  /**
296
336
  * Compute bid fee for AENS auction
297
337
  * @function
298
338
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
299
- * @param {String} domain the domain name to get the fee for
339
+ * @param {String} name the AENS name to get the fee for
300
340
  * @param {Number|String} startFee Auction start fee
301
341
  * @param {Number} [increment=0.5] Bid multiplier(In percentage, must be between 0 and 1)
302
342
  * @return {String} Bid fee
303
343
  */
304
- export function computeBidFee (domain, startFee = NAME_FEE, increment = NAME_FEE_BID_INCREMENT) {
305
- if (!(Number(increment) === increment && increment % 1 !== 0)) throw new Error(`Increment must be float. Current increment ${increment}`)
306
- if (increment < NAME_FEE_BID_INCREMENT) throw new Error(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`)
344
+ export function computeBidFee (name, startFee, increment = NAME_FEE_BID_INCREMENT) {
345
+ if (!(Number(increment) === increment && increment % 1 !== 0)) throw new IllegalBidFeeError(`Increment must be float. Current increment ${increment}`)
346
+ if (increment < NAME_FEE_BID_INCREMENT) throw new IllegalBidFeeError(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`)
307
347
  return ceil(
308
- BigNumber(BigNumber(startFee).eq(NAME_FEE) ? getMinimumNameFee(domain) : startFee).times(BigNumber(NAME_FEE_BID_INCREMENT).plus(1))
348
+ BigNumber(startFee ?? getMinimumNameFee(name)).times(BigNumber(NAME_FEE_BID_INCREMENT).plus(1))
309
349
  )
310
350
  }
311
351
 
@@ -313,26 +353,28 @@ export function computeBidFee (domain, startFee = NAME_FEE, increment = NAME_FEE
313
353
  * Compute auction end height
314
354
  * @function
315
355
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
316
- * @param {String} domain the domain name to get the fee for
356
+ * @param {String} name
317
357
  * @param {Number|String} claimHeight Auction starting height
318
358
  * @return {String} Auction end height
319
359
  */
320
- export function computeAuctionEndBlock (domain, claimHeight) {
321
- return R.cond([
322
- [R.lt(5), R.always(NAME_BID_TIMEOUTS[4].plus(claimHeight))],
323
- [R.lt(9), R.always(NAME_BID_TIMEOUTS[8].plus(claimHeight))],
324
- [R.lte(NAME_BID_MAX_LENGTH), R.always(NAME_BID_TIMEOUTS[12].plus(claimHeight))],
325
- [R.T, R.always(BigNumber(claimHeight))]
326
- ])(domain.replace('.chain', '').length).toString(10)
360
+ export function computeAuctionEndBlock (name, claimHeight) {
361
+ ensureNameValid(name)
362
+ const length = name.length - AENS_SUFFIX.length
363
+ const h = (length <= 4 && NAME_BID_TIMEOUTS[4]) ||
364
+ (length <= 8 && NAME_BID_TIMEOUTS[8]) ||
365
+ (length <= 12 && NAME_BID_TIMEOUTS[12]) ||
366
+ NAME_BID_TIMEOUTS[13]
367
+ return h.plus(claimHeight).toString(10)
327
368
  }
328
369
 
329
370
  /**
330
371
  * Is name accept going to auction
331
372
  * @function
332
373
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
333
- * @param {String} name Transaction abiVersion
374
+ * @param {String} name
334
375
  * @return {Boolean}
335
376
  */
336
377
  export function isAuctionName (name) {
337
- return name.replace('.chain', '').length < 13
378
+ ensureNameValid(name)
379
+ return name.length < 13 + AENS_SUFFIX.length
338
380
  }
@@ -2,18 +2,17 @@ import BigNumber from 'bignumber.js'
2
2
  import { decode as rlpDecode, encode as rlpEncode } from 'rlp'
3
3
  import { AE_AMOUNT_FORMATS, formatAmount } from '../../utils/amount-formatter'
4
4
  import { hash } from '../../utils/crypto'
5
+ import { Field } from './field-types'
5
6
 
6
7
  import {
7
8
  DEFAULT_FEE,
8
9
  FIELD_TYPES,
9
10
  OBJECT_ID_TX_TYPE,
10
- PREFIX_ID_TAG,
11
11
  TX_DESERIALIZATION_SCHEMA,
12
12
  TX_FEE_BASE_GAS,
13
13
  TX_FEE_OTHER_GAS,
14
14
  TX_SERIALIZATION_SCHEMA,
15
15
  TX_TYPE,
16
- VALIDATION_MESSAGE,
17
16
  VSN
18
17
  } from './schema'
19
18
  import {
@@ -28,6 +27,7 @@ import {
28
27
  } from './helpers'
29
28
  import { toBytes } from '../../utils/bytes'
30
29
  import MPTree from '../../utils/mptree'
30
+ import { InvalidTxParamsError, SchemaNotFoundError } from '../../utils/errors'
31
31
 
32
32
  /**
33
33
  * JavaScript-based Transaction builder
@@ -50,7 +50,6 @@ function deserializeField (value, type, prefix) {
50
50
  return { vmVersion: readInt(Buffer.from([vm])), abiVersion: readInt(Buffer.from([abi])) }
51
51
  }
52
52
  case FIELD_TYPES.amount:
53
- return readInt(value)
54
53
  case FIELD_TYPES.int:
55
54
  return readInt(value)
56
55
  case FIELD_TYPES.id:
@@ -99,11 +98,12 @@ function deserializeField (value, type, prefix) {
99
98
  {}
100
99
  )
101
100
  default:
101
+ if (type.prototype instanceof Field) return type.deserialize(value)
102
102
  return value
103
103
  }
104
104
  }
105
105
 
106
- function serializeField (value, type, prefix) {
106
+ function serializeField (value, type, prefix, params) {
107
107
  switch (type) {
108
108
  case FIELD_TYPES.amount:
109
109
  case FIELD_TYPES.int:
@@ -144,44 +144,55 @@ function serializeField (value, type, prefix) {
144
144
  default: return value
145
145
  }
146
146
  default:
147
+ if (type.prototype instanceof Field) return type.serialize(value, params)
147
148
  return value
148
149
  }
149
150
  }
150
151
 
151
- function validateField (value, key, type, prefix) {
152
- const assert = (valid, params) => valid ? {} : { [key]: VALIDATION_MESSAGE[type](params) }
152
+ function validateField (value, type, prefix) {
153
153
  // All fields are required
154
- if (value === undefined || value === null) return { [key]: 'Field is required' }
154
+ if (value === undefined || value === null) return 'Field is required'
155
155
 
156
156
  // Validate type of value
157
157
  switch (type) {
158
158
  case FIELD_TYPES.amount:
159
159
  case FIELD_TYPES.int: {
160
- const isMinusValue = (!isNaN(value) || BigNumber.isBigNumber(value)) && BigNumber(value).lt(0)
161
- return assert((!isNaN(value) || BigNumber.isBigNumber(value)) && BigNumber(value).gte(0), { value, isMinusValue })
160
+ if (isNaN(value) && !BigNumber.isBigNumber(value)) {
161
+ return `${value} is not of type Number or BigNumber`
162
+ }
163
+ if (new BigNumber(value).lt(0)) return `${value} must be >= 0`
164
+ return
162
165
  }
163
166
  case FIELD_TYPES.id: {
164
167
  const prefixes = Array.isArray(prefix) ? prefix : [prefix]
165
- const p = prefixes.find(p => p === value.split('_')[0])
166
- return assert(p && PREFIX_ID_TAG[value.split('_')[0]], { value, prefix })
168
+ if (!prefixes.includes(value.split('_')[0])) {
169
+ return `'${value}' prefix doesn't match expected prefix '${prefix}'`
170
+ }
171
+ return
167
172
  }
168
- case FIELD_TYPES.binary:
169
- return assert(value.split('_')[0] === prefix, { prefix, value })
170
- case FIELD_TYPES.string:
171
- return assert(true)
172
173
  case FIELD_TYPES.ctVersion:
173
- return assert(typeof value === 'object' && Object.prototype.hasOwnProperty.call(value, 'abiVersion') && Object.prototype.hasOwnProperty.call(value, 'vmVersion'))
174
+ if (!value?.abiVersion || !value?.vmVersion) {
175
+ return 'Value must be an object with "vmVersion" and "abiVersion" fields'
176
+ }
177
+ return
174
178
  case FIELD_TYPES.pointers:
175
- return assert(Array.isArray(value) && !value.find(e => e !== Object(e)), { value })
176
- default:
177
- return {}
179
+ if (!Array.isArray(value)) return 'Value must be of type Array'
180
+ if (value.some(p => !p?.key || !p?.id)) {
181
+ return 'Value must contains only object\'s like \'{key: "account_pubkey", id: "ak_lkamsflkalsdalksdlasdlasdlamd"}\''
182
+ }
183
+ if (value.length > 32) {
184
+ return `Expected 32 pointers or less, got ${value.length} instead`
185
+ }
178
186
  }
179
187
  }
180
188
 
181
189
  function transformParams (params, schema, { denomination } = {}) {
182
190
  params = schema
183
191
  .filter(([_, t]) => t === FIELD_TYPES.amount)
184
- .reduce((acc, [key]) => ({ ...params, [key]: formatAmount(params[key], { denomination }) }), params)
192
+ .reduce(
193
+ (acc, [key]) => ({ ...params, [key]: formatAmount(params[key], { denomination }) }),
194
+ params
195
+ )
185
196
  const schemaKeys = schema.map(([k]) => k)
186
197
  return Object
187
198
  .entries(params)
@@ -256,7 +267,8 @@ function buildFee (txType, { params, gas = 0, multiplier, vsn }) {
256
267
  .plus(TX_FEE_OTHER_GAS(txType, txSize, {
257
268
  relativeTtl: getOracleRelativeTtl(params, txType),
258
269
  innerTxSize: [TX_TYPE.gaMeta, TX_TYPE.payingFor].includes(txType)
259
- ? params.tx.tx.encodedTx.rlpEncoded.length : 0
270
+ ? params.tx.tx.encodedTx.rlpEncoded.length
271
+ : 0
260
272
  }))
261
273
  .times(multiplier)
262
274
  }
@@ -290,12 +302,14 @@ export function calculateFee (fee = 0, txType, { gas = 0, params, showWarning =
290
302
  * @return {Object} Object with validation errors
291
303
  */
292
304
  export function validateParams (params, schema, { excludeKeys = [] }) {
293
- return schema
294
- .filter(([key]) => !excludeKeys.includes(key) && key !== 'payload')
295
- .reduce(
296
- (acc, [key, type, prefix]) => Object.assign(acc, validateField(params[key], key, type, prefix)),
297
- {}
298
- )
305
+ return Object.fromEntries(
306
+ schema
307
+ // TODO: allow optional keys in schema
308
+ .filter(([key]) => !excludeKeys.includes(key) &&
309
+ !['payload', 'nameFee', 'deposit'].includes(key))
310
+ .map(([key, type, prefix]) => [key, validateField(params[key], type, prefix)])
311
+ .filter(([, message]) => message)
312
+ )
299
313
  }
300
314
 
301
315
  /**
@@ -305,12 +319,16 @@ export function validateParams (params, schema, { excludeKeys = [] }) {
305
319
  * @param {Object} params Object with tx params
306
320
  * @param {Array} schema Transaction schema
307
321
  * @param {Object} [options={}] options
308
- * @param {Array} [options.excludeKeys=[]] excludeKeys Array of keys to exclude for validation and build
309
- * @param {String} [options.denomination='aettos'] denomination Denomination of amounts (default: aettos)
322
+ * @param {String[]} [options.excludeKeys=[]] Array of keys to exclude for validation and build
323
+ * @param {String} [options.denomination='aettos'] Denomination of amounts
310
324
  * @throws {Error} Validation error
311
325
  * @return {Array} Array with binary fields of transaction
312
326
  */
313
- export function buildRawTx (params, schema, { excludeKeys = [], denomination = AE_AMOUNT_FORMATS.AETTOS } = {}) {
327
+ export function buildRawTx (
328
+ params,
329
+ schema,
330
+ { excludeKeys = [], denomination = AE_AMOUNT_FORMATS.AETTOS } = {}
331
+ ) {
314
332
  const filteredSchema = schema.filter(([key]) => !excludeKeys.includes(key))
315
333
 
316
334
  // Transform `amount` type fields to `aettos`
@@ -318,11 +336,11 @@ export function buildRawTx (params, schema, { excludeKeys = [], denomination = A
318
336
  // Validation
319
337
  const valid = validateParams(params, schema, { excludeKeys })
320
338
  if (Object.keys(valid).length) {
321
- throw new Error('Transaction build error. ' + JSON.stringify(valid))
339
+ throw new InvalidTxParamsError('Transaction build error. ' + JSON.stringify(valid))
322
340
  }
323
341
 
324
342
  return filteredSchema
325
- .map(([key, fieldType, prefix]) => serializeField(params[key], fieldType, prefix))
343
+ .map(([key, fieldType, prefix]) => serializeField(params[key], fieldType, prefix, params))
326
344
  }
327
345
 
328
346
  /**
@@ -358,10 +376,10 @@ const getSchema = ({ vsn, objId, type }) => {
358
376
  const schema = isDeserialize ? TX_DESERIALIZATION_SCHEMA : TX_SERIALIZATION_SCHEMA
359
377
 
360
378
  if (!schema[firstKey]) {
361
- throw new Error(`Transaction ${isDeserialize ? 'deserialization' : 'serialization'} not implemented for ${isDeserialize ? 'tag ' + objId : type}`)
379
+ throw new SchemaNotFoundError(`Transaction ${isDeserialize ? 'deserialization' : 'serialization'} not implemented for ${isDeserialize ? 'tag ' + objId : type}`)
362
380
  }
363
381
  if (!schema[firstKey][vsn]) {
364
- throw new Error(`Transaction ${isDeserialize ? 'deserialization' : 'serialization'} not implemented for ${isDeserialize ? 'tag ' + objId : type} version ${vsn}`)
382
+ throw new SchemaNotFoundError(`Transaction ${isDeserialize ? 'deserialization' : 'serialization'} not implemented for ${isDeserialize ? 'tag ' + objId : type} version ${vsn}`)
365
383
  }
366
384
  return schema[firstKey][vsn]
367
385
  }
@@ -373,14 +391,25 @@ const getSchema = ({ vsn, objId, type }) => {
373
391
  * @param {Object} params Object with tx params
374
392
  * @param {String} type Transaction type
375
393
  * @param {Object} [options={}] options
376
- * @param {Object} [options.excludeKeys] excludeKeys Array of keys to exclude for validation and build
394
+ * @param {String[]} [options.excludeKeys] Array of keys to exclude for validation and build
377
395
  * @param {String} [options.prefix] Prefix of transaction
378
396
  * @throws {Error} Validation error
379
- * @return {Object} { tx, rlpEncoded, binary } Object with tx -> Base64Check transaction hash with 'tx_' prefix, rlp encoded transaction and binary transaction
397
+ * @returns {Object} object
398
+ * @returns {String} object.tx Base64Check transaction hash with 'tx_' prefix
399
+ * @returns {Buffer} object.rlpEncoded rlp encoded transaction
400
+ * @returns {Array<Buffer>} object.binary binary transaction
380
401
  */
381
- export function buildTx (params, type, { excludeKeys = [], prefix = 'tx', vsn = VSN, denomination = AE_AMOUNT_FORMATS.AETTOS } = {}) {
402
+ export function buildTx (
403
+ params,
404
+ type,
405
+ { excludeKeys = [], prefix = 'tx', vsn = VSN, denomination = AE_AMOUNT_FORMATS.AETTOS } = {}
406
+ ) {
382
407
  const [schema, tag] = getSchema({ type, vsn })
383
- const binary = buildRawTx({ ...params, VSN: vsn, tag }, schema, { excludeKeys, denomination: params.denomination || denomination }).filter(e => e !== undefined)
408
+ const binary = buildRawTx(
409
+ { ...params, VSN: vsn, tag },
410
+ schema,
411
+ { excludeKeys, denomination: params.denomination || denomination }
412
+ ).filter(e => e !== undefined)
384
413
 
385
414
  const rlpEncoded = rlpEncode(binary)
386
415
  const tx = encode(rlpEncoded, prefix)
@@ -392,10 +421,14 @@ export function buildTx (params, type, { excludeKeys = [], prefix = 'tx', vsn =
392
421
  * Unpack transaction hash
393
422
  * @function
394
423
  * @alias module:@aeternity/aepp-sdk/es/tx/builder
395
- * @param {String|Buffer} encodedTx String or RLP encoded transaction array (if fromRlpBinary flag is true)
424
+ * @param {String|Buffer} encodedTx String or RLP encoded transaction array
425
+ * (if fromRlpBinary flag is true)
396
426
  * @param {Boolean} fromRlpBinary Unpack from RLP encoded transaction (default: false)
397
427
  * @param {String} prefix - Prefix of data
398
- * @return {Object} { tx, rlpEncoded, binary } Object with tx -> Object with transaction param's, rlp encoded transaction and binary transaction
428
+ * @returns {Object} object
429
+ * @returns {Object} object.tx Object with transaction param's
430
+ * @returns {Buffer} object.rlpEncoded rlp encoded transaction
431
+ * @returns {Array<Buffer>} object.binary binary transaction
399
432
  */
400
433
  export function unpackTx (encodedTx, fromRlpBinary = false, prefix = 'tx') {
401
434
  const rlpEncoded = fromRlpBinary ? encodedTx : decode(encodedTx, prefix)
@@ -420,4 +453,13 @@ export function buildTxHash (rawTx) {
420
453
  return encode(hash(data), 'th')
421
454
  }
422
455
 
423
- export default { calculateMinFee, calculateFee, unpackTx, unpackRawTx, buildTx, buildRawTx, validateParams, buildTxHash }
456
+ export default {
457
+ calculateMinFee,
458
+ calculateFee,
459
+ unpackTx,
460
+ unpackRawTx,
461
+ buildTx,
462
+ buildRawTx,
463
+ validateParams,
464
+ buildTxHash
465
+ }