@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
@@ -1,15 +1,19 @@
1
1
  import BigNumber from 'bignumber.js'
2
2
  import { MAX_AUTH_FUN_GAS } from '../../tx/builder/schema'
3
+ import { InvalidAuthDataError } from '../../utils/errors'
3
4
 
4
5
  export const prepareGaParams = (ins) => async (authData, authFnName) => {
5
- if (typeof authData !== 'object') throw new Error('AuthData must be an object')
6
- if (authData.gas && BigNumber(authData.gas).gt(MAX_AUTH_FUN_GAS)) throw new Error(`the maximum gas value for ga authFun is ${MAX_AUTH_FUN_GAS}, got ${authData.gas}`)
6
+ if (typeof authData !== 'object') throw new InvalidAuthDataError('AuthData must be an object')
7
+ if (authData.gas && BigNumber(authData.gas).gt(MAX_AUTH_FUN_GAS)) { throw new InvalidAuthDataError(`the maximum gas value for ga authFun is ${MAX_AUTH_FUN_GAS}, got ${authData.gas}`) }
7
8
  const gas = authData.gas || MAX_AUTH_FUN_GAS
8
9
  if (authData.callData) {
9
- if (authData.callData.split('_')[0] !== 'cb') throw new Error('Auth data must be a string with "cb" prefix.')
10
+ if (authData.callData.split('_')[0] !== 'cb') throw new InvalidAuthDataError('Auth data must be a string with "cb" prefix.')
10
11
  return { authCallData: authData.callData, gas }
11
- } else {
12
- if (!authData.source || !authData.args) throw new Error('Auth data must contain source code and arguments.')
13
- return { authCallData: await ins.contractEncodeCallDataAPI(authData.source, authFnName, authData.args), gas }
12
+ }
13
+ if (!authData.source || !authData.args) throw new InvalidAuthDataError('Auth data must contain source code and arguments.')
14
+ const contract = await ins.getContractInstance({ source: authData.source })
15
+ return {
16
+ authCallData: contract.calldata.encode(contract._name, authFnName, authData.args),
17
+ gas
14
18
  }
15
19
  }
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * ISC License (ISC)
3
- * Copyright (c) 2018 aeternity developers
3
+ * Copyright (c) 2021 aeternity developers
4
4
  *
5
5
  * Permission to use, copy, modify, and/or distribute this software for any
6
6
  * purpose with or without fee is hereby granted, provided that the above
@@ -16,50 +16,53 @@
16
16
  */
17
17
 
18
18
  /**
19
- * Generalize Account module - routines to use generalize account
19
+ * Generalized Account module - routines to use generalized account
20
20
  *
21
21
  * @module @aeternity/aepp-sdk/es/contract/ga
22
- * @export GeneralizeAccount
23
- * @example import { GeneralizeAccount } from '@aeternity/aepp-sdk'
22
+ * @export GeneralizedAccount
23
+ * @example import { GeneralizedAccount } from '@aeternity/aepp-sdk'
24
24
  */
25
- import { ContractAPI } from '../../ae/contract'
25
+ import Contract from '../../ae/contract'
26
26
  import { TX_TYPE } from '../../tx/builder/schema'
27
27
  import { buildTx, unpackTx } from '../../tx/builder'
28
28
  import { prepareGaParams } from './helpers'
29
29
  import { hash } from '../../utils/crypto'
30
+ import { IllegalArgumentError, MissingParamError } from '../../utils/errors'
30
31
 
31
32
  /**
32
- * GeneralizeAccount Stamp
33
+ * GeneralizedAccount Stamp
33
34
  *
34
- * Provide Generalize Account implementation
35
+ * Provide Generalized Account implementation
35
36
  * {@link module:@aeternity/aepp-sdk/es/contract/ga} clients.
36
37
  * @function
37
38
  * @alias module:@aeternity/aepp-sdk/es/contract/ga
38
39
  * @rtype Stamp
39
40
  * @param {Object} [options={}] - Initializer object
40
- * @return {Object} GeneralizeAccount instance
41
+ * @return {Object} GeneralizedAccount instance
41
42
  * @example
42
43
  * const authContract = ``
43
- * await client.createGeneralizeAccount(authFnName, authContract, [...authFnArguments]
44
+ * await aeSdk.createGeneralizedAccount(authFnName, authContract, [...authFnArguments]
44
45
  * // Make spend using GA
45
46
  * const callData = 'cb_...' // encoded call data for auth contract
46
- * await client.spend(10000, receiverPub, { authData: { callData } })
47
+ * await aeSdk.spend(10000, receiverPub, { authData: { callData } })
47
48
  * // or
48
- * await client.spend(10000, receiverPub, { authData: { source: authContract, args: [...authContractArgs] } }) // sdk will prepare callData itself
49
+ * await aeSdk.spend(10000, receiverPub, {
50
+ * authData: { source: authContract, args: [...authContractArgs] }
51
+ * }) // sdk will prepare callData itself
49
52
  */
50
- export const GeneralizeAccount = ContractAPI.compose({
53
+ export const GeneralizedAccount = Contract.compose({
51
54
  methods: {
52
- createGeneralizeAccount,
55
+ createGeneralizedAccount,
53
56
  createMetaTx,
54
57
  isGA
55
58
  }
56
59
  })
57
- export default GeneralizeAccount
60
+ export default GeneralizedAccount
58
61
 
59
62
  /**
60
63
  * @alias module:@aeternity/aepp-sdk/es/contract/ga
61
64
  * @function
62
- * Check if account is GA account
65
+ * Check if account is GA
63
66
  * @param {String} address - Account address
64
67
  * @return {Boolean}
65
68
  */
@@ -69,26 +72,30 @@ async function isGA (address) {
69
72
  }
70
73
 
71
74
  /**
72
- * Convert current account to GA account
75
+ * Convert current account to GA
73
76
  * @alias module:@aeternity/aepp-sdk/es/contract/ga
74
77
  * @function
75
78
  * @param {String} authFnName - Authorization function name
76
79
  * @param {String} source - Auth contract source code
77
80
  * @param {Array} [args] - init arguments
78
81
  * @param {Object} [options] - Options
79
- * @return {Promise<Readonly<{result: *, owner: *, createdAt: Date, address, rawTx: *, transaction: *}>>}
82
+ * @return {Promise<Readonly<{
83
+ * result: *, owner: *, address, rawTx: *, transaction: *
84
+ * }>>}
80
85
  */
81
- async function createGeneralizeAccount (authFnName, source, args = [], options = {}) {
86
+ async function createGeneralizedAccount (authFnName, source, args = [], options = {}) {
82
87
  const opt = { ...this.Ae.defaults, ...options }
83
88
  const ownerId = await this.address(opt)
89
+ if (await this.isGA(ownerId)) throw new IllegalArgumentError(`Account ${ownerId} is already GA`)
84
90
 
85
- if (await this.isGA(ownerId)) throw new Error(`Account ${ownerId} is already GA`)
86
-
91
+ const contract = await this.getContractInstance({ source })
92
+ await contract.compile()
87
93
  const { tx, contractId } = await this.gaAttachTx({
88
94
  ...opt,
95
+ gas: opt.gas ?? await contract._estimateGas('init', args, opt),
89
96
  ownerId,
90
- code: (await this.contractCompile(source)).bytecode,
91
- callData: await this.contractEncodeCallDataAPI(source, 'init', args),
97
+ code: contract.bytecode,
98
+ callData: contract.calldata.encode(contract._name, 'init', args),
92
99
  authFun: hash(authFnName)
93
100
  })
94
101
 
@@ -115,7 +122,7 @@ const wrapInEmptySignedTx = (tx) => buildTx({ encodedTx: tx, signatures: [] }, T
115
122
  * @return {String}
116
123
  */
117
124
  async function createMetaTx (rawTransaction, authData, authFnName, options = {}) {
118
- if (!authData) throw new Error('authData is required')
125
+ if (!authData) throw new MissingParamError('authData is required')
119
126
  // Check if authData is callData or if it's an object prepare a callData from source and args
120
127
  const { authCallData, gas } = await prepareGaParams(this)(authData, authFnName)
121
128
  const opt = { ...this.Ae.defaults, ...options }
@@ -128,7 +135,7 @@ async function createMetaTx (rawTransaction, authData, authFnName, options = {})
128
135
  tx: wrappedTx.txObject
129
136
  },
130
137
  gaId: await this.address(opt),
131
- abiVersion: abiVersion,
138
+ abiVersion,
132
139
  authData: authCallData,
133
140
  gas,
134
141
  vsn: 2
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * ISC License (ISC)
3
- * Copyright (c) 2018 aeternity developers
3
+ * Copyright (c) 2021 aeternity developers
4
4
  *
5
5
  * Permission to use, copy, modify, and/or distribute this software for any
6
6
  * purpose with or without fee is hereby granted, provided that the above
@@ -21,9 +21,8 @@ import * as Bytes from './utils/bytes'
21
21
  import * as TxBuilder from './tx/builder'
22
22
  import * as TxBuilderHelper from './tx/builder/helpers'
23
23
  import * as SCHEMA from './tx/builder/schema'
24
- import * as ACITransformation from './contract/aci/transformation'
25
24
  import * as AmountFormatter from './utils/amount-formatter'
26
- import HdWallet from './utils/hd-wallet'
25
+ import * as HdWallet from './utils/hd-wallet'
27
26
 
28
27
  import Ae from './ae'
29
28
  import Chain from './chain'
@@ -38,8 +37,8 @@ import AccountMultiple from './account/multiple'
38
37
  import MemoryAccount from './account/memory'
39
38
  import Aens from './ae/aens'
40
39
  import Contract from './ae/contract'
41
- import GeneralizeAccount from './contract/ga'
42
- import ContractCompilerAPI from './contract/compiler'
40
+ import GeneralizedAccount from './contract/ga'
41
+ import ContractCompilerHttp from './contract/compiler'
43
42
  import RpcAepp from './ae/aepp'
44
43
  import RpcWallet from './ae/wallet'
45
44
  import Oracle from './ae/oracle'
@@ -53,6 +52,9 @@ export * as AeppWalletSchema from './utils/aepp-wallet-communication/schema'
53
52
  export { default as WalletDetector } from './utils/aepp-wallet-communication/wallet-detector'
54
53
  export { default as BrowserRuntimeConnection } from './utils/aepp-wallet-communication/connection/browser-runtime'
55
54
  export { default as BrowserWindowMessageConnection } from './utils/aepp-wallet-communication/connection/browser-window-message'
55
+ export * from './utils/errors'
56
+
57
+ export const getDefaultPointerKey = TxBuilderHelper.getDefaultPointerKey
56
58
 
57
59
  export {
58
60
  AmountFormatter,
@@ -62,8 +64,7 @@ export {
62
64
  Aens,
63
65
  Bytes,
64
66
  Contract,
65
- ContractCompilerAPI,
66
- ACITransformation,
67
+ ContractCompilerHttp,
67
68
  ChainNode,
68
69
  RpcAepp,
69
70
  RpcWallet,
@@ -71,7 +72,7 @@ export {
71
72
  Crypto,
72
73
  Keystore,
73
74
  Chain,
74
- GeneralizeAccount,
75
+ GeneralizedAccount,
75
76
  HdWallet,
76
77
  MemoryAccount,
77
78
  Node,
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import stampit from '@stamp/it'
8
8
  import { getNetworkId } from '../node'
9
+ import { DisconnectedError, DuplicateNodeError, NodeNotFoundError, TypeError } from '../utils/errors'
9
10
 
10
11
  /**
11
12
  * Node Pool Stamp
@@ -34,7 +35,7 @@ export default stampit({
34
35
  configurable: false,
35
36
  get () {
36
37
  if (!this.selectedNode || !this.selectedNode.instance) {
37
- throw new Error('You can\'t use Node API. Node is not connected or not defined!')
38
+ throw new NodeNotFoundError('You can\'t use Node API. Node is not connected or not defined!')
38
39
  }
39
40
  return this.selectedNode.instance.api
40
41
  }
@@ -51,10 +52,11 @@ export default stampit({
51
52
  * @param {Boolean} select - Select this node as current
52
53
  * @return {void}
53
54
  * @example
54
- * nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true) // add and select new node with name 'testNode'
55
+ * // add and select new node with name 'testNode'
56
+ * nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true)
55
57
  */
56
58
  addNode (name, node, select = false) {
57
- if (this.pool.has(name)) throw new Error(`Node with name ${name} already exist`)
59
+ if (this.pool.has(name)) throw new DuplicateNodeError(name)
58
60
 
59
61
  this.validateNodes([{ name, instance: node }])
60
62
 
@@ -82,7 +84,7 @@ export default stampit({
82
84
  * nodePool.selectNode('testNode')
83
85
  */
84
86
  selectNode (name) {
85
- if (!this.pool.has(name)) throw new Error(`Node with name ${name} not in pool`)
87
+ if (!this.pool.has(name)) throw new NodeNotFoundError(`Node with name ${name} not in pool`)
86
88
 
87
89
  this.selectedNode = this.pool.get(name)
88
90
  },
@@ -118,7 +120,7 @@ export default stampit({
118
120
  * nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }
119
121
  */
120
122
  getNodeInfo () {
121
- if (!this.isNodeConnected()) throw new Error('Can not get node info. Node is not connected')
123
+ if (!this.isNodeConnected()) throw new DisconnectedError()
122
124
  return {
123
125
  name: this.selectedNode.name,
124
126
  ...this.selectedNode.instance.getNodeInfo()
@@ -140,13 +142,14 @@ export default stampit({
140
142
  }))
141
143
  },
142
144
  validateNodes (nodes) {
143
- // TODO: validate it on TypeScript level instead (to speedup development, save runtime resources)
144
- if (!Array.isArray(nodes)) throw new Error('"nodes" should be an array')
145
+ // TODO: validate it on TypeScript level instead
146
+ // (to speedup development, save runtime resources)
147
+ if (!Array.isArray(nodes)) throw new TypeError('"nodes" should be an array')
145
148
  const notObject = nodes.map(n => typeof n).find(t => t !== 'object')
146
- if (notObject) throw new Error(`Each node should be an object, got ${notObject} instead`)
149
+ if (notObject) throw new TypeError(`Each node should be an object, got ${notObject} instead`)
147
150
  const wrongFields = nodes.find(n => typeof n.name !== 'string' || typeof n.instance !== 'object')
148
151
  if (notObject) {
149
- throw new Error(
152
+ throw new TypeError(
150
153
  'Each node should have name (string), instance (object) ' +
151
154
  `fields, got ${JSON.stringify(wrongFields)} instead`
152
155
  )
@@ -156,7 +159,7 @@ export default stampit({
156
159
  .find(i => typeof i.api !== 'object' || typeof i.genesisHash !== 'string' ||
157
160
  typeof i.consensusProtocolVersion !== 'number')
158
161
  if (wrongInstanceFields) {
159
- throw new Error(
162
+ throw new TypeError(
160
163
  'Each node instance should have api (object), consensusProtocolVersion (number), ' +
161
164
  `genesisHash (string) fields, got ${JSON.stringify(wrongInstanceFields)} instead`
162
165
  )
package/src/node.js CHANGED
@@ -25,6 +25,7 @@
25
25
  import AsyncInit from './utils/async-init'
26
26
  import genSwaggerClient from './utils/swagger'
27
27
  import semverSatisfies from './utils/semver-satisfies'
28
+ import { MissingParamError, UnsupportedVersionError } from './utils/errors'
28
29
 
29
30
  /**
30
31
  * Obtain networkId from account or node
@@ -34,9 +35,10 @@ import semverSatisfies from './utils/semver-satisfies'
34
35
  * @return {String} NetworkId
35
36
  */
36
37
  export function getNetworkId ({ networkId, force = false } = {}) {
37
- if (!force && !networkId && !this.networkId && (!this.selectedNode || !this.selectedNode.networkId)) throw new Error('networkId is not provided')
38
- if (force && !networkId && !this.networkId && (!this.selectedNode || !this.selectedNode.networkId)) return null
39
- return networkId || this.networkId || this.selectedNode.networkId
38
+ const res = networkId || this.networkId || this.selectedNode?.networkId
39
+ if (!force && !res) throw new MissingParamError('networkId is not provided')
40
+ if (force && !res) return null
41
+ return res
40
42
  }
41
43
 
42
44
  /**
@@ -47,15 +49,17 @@ export function getNetworkId ({ networkId, force = false } = {}) {
47
49
  * @param {Object} [options={}] - Options
48
50
  * @param {String} options.url - Base URL for Node
49
51
  * @param {String} options.internalUrl - Base URL for internal requests
50
- * @param {String} options.axiosConfig - Object with axios configuration. Example { config: {}, errorHandler: (err) => throw err }
52
+ * @param {Object} options.axiosConfig - Object with axios configuration
53
+ * @param {Object} options.axiosConfig.config
54
+ * @param {Function} options.axiosConfig.errorHandler - (err) => throw err
51
55
  * @return {Object} Node client
52
56
  * @example Node({url: 'https://testnet.aeternity.io'})
53
57
  */
54
58
  const Node = AsyncInit.compose({
55
59
  async init ({ url, internalUrl, ignoreVersion }) {
56
- if (!url) throw new Error('"url" required')
60
+ if (!url) throw new MissingParamError('"url" required')
57
61
  this.url = url.replace(/\/$/, '')
58
- this.internalUrl = internalUrl ? internalUrl.replace(/\/$/, '') : this.url
62
+ this.internalUrl = internalUrl?.replace(/\/$/, '')
59
63
  const client = await genSwaggerClient(`${this.url}/api?oas3`, {
60
64
  internalUrl: this.internalUrl,
61
65
  responseInterceptor: response => {
@@ -70,10 +74,7 @@ const Node = AsyncInit.compose({
70
74
  !semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) &&
71
75
  !ignoreVersion
72
76
  ) {
73
- throw new Error(
74
- `Unsupported node version ${this.version}. ` +
75
- `Supported: >= ${NODE_GE_VERSION} < ${NODE_LT_VERSION}`
76
- )
77
+ throw new UnsupportedVersionError('node', this.version, NODE_GE_VERSION, NODE_LT_VERSION)
77
78
  }
78
79
  this.api = client.api
79
80
 
@@ -0,0 +1,100 @@
1
+ import BigNumber from 'bignumber.js'
2
+ import { mapObject } from '../../utils/other'
3
+
4
+ // # AENS
5
+ export const NAME_TTL = 180000
6
+ // # max number of block into the future that the name is going to be available
7
+ // # https://github.com/aeternity/protocol/blob/epoch-v0.22.0/AENS.md#update
8
+ // # https://github.com/aeternity/protocol/blob/44a93d3aab957ca820183c3520b9daf6b0fedff4/AENS.md#aens-entry
9
+ export const NAME_MAX_TTL = 36000
10
+ export const NAME_MAX_CLIENT_TTL = 84600
11
+ export const CLIENT_TTL = NAME_MAX_CLIENT_TTL
12
+ // # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L67
13
+ export const NAME_FEE_MULTIPLIER = 1e14 // 100000000000000
14
+ export const NAME_FEE_BID_INCREMENT = 0.05 // # the increment is in percentage
15
+ // # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L272
16
+ export const NAME_BID_TIMEOUT_BLOCKS = 480 // # ~1 day
17
+ // # this is the max length for a domain that requires a base fee to be paid
18
+ export const NAME_MAX_LENGTH_FEE = 31
19
+ export const NAME_BID_MAX_LENGTH = 12 // # this is the max length for a domain to be part of a bid
20
+ export const POINTER_KEY_BY_PREFIX = {
21
+ ak: 'account_pubkey',
22
+ ok: 'oracle_pubkey',
23
+ ct: 'contract_pubkey',
24
+ ch: 'channel'
25
+ }
26
+ // # https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L290
27
+ // # https://github.com/aeternity/protocol/blob/master/AENS.md#protocol-fees-and-protection-times
28
+ // # bid ranges:
29
+ export const NAME_BID_RANGES = mapObject({
30
+ 31: 3,
31
+ 30: 5,
32
+ 29: 8,
33
+ 28: 13,
34
+ 27: 21,
35
+ 26: 34,
36
+ 25: 55,
37
+ 24: 89,
38
+ 23: 144,
39
+ 22: 233,
40
+ 21: 377,
41
+ 20: 610,
42
+ 19: 987,
43
+ 18: 1597,
44
+ 17: 2584,
45
+ 16: 4181,
46
+ 15: 6765,
47
+ 14: 10946,
48
+ 13: 17711,
49
+ 12: 28657,
50
+ 11: 46368,
51
+ 10: 75025,
52
+ 9: 121393,
53
+ 8: 196418,
54
+ 7: 317811,
55
+ 6: 514229,
56
+ 5: 832040,
57
+ 4: 1346269,
58
+ 3: 2178309,
59
+ 2: 3524578,
60
+ 1: 5702887
61
+ }, ([key, value]) => [key, new BigNumber(value).times(NAME_FEE_MULTIPLIER)])
62
+
63
+ // # ref: https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L273
64
+ // # name bid timeouts
65
+ export const NAME_BID_TIMEOUTS = {
66
+ 13: BigNumber(0),
67
+ 12: BigNumber(NAME_BID_TIMEOUT_BLOCKS), // # 480 blocks
68
+ 8: BigNumber(31).times(NAME_BID_TIMEOUT_BLOCKS), // # 14880 blocks
69
+ 4: BigNumber(62).times(NAME_BID_TIMEOUT_BLOCKS) // # 29760 blocks
70
+ }
71
+
72
+ // # Tag constant for ids (type uint8)
73
+ // # see https://github.com/aeternity/protocol/blob/master/serializations.md#the-id-type
74
+ // # <<Tag:1/unsigned-integer-unit:8, Hash:32/binary-unit:8>>
75
+ const ID_TAG_ACCOUNT = 1
76
+ const ID_TAG_NAME = 2
77
+ const ID_TAG_COMMITMENT = 3
78
+ const ID_TAG_ORACLE = 4
79
+ const ID_TAG_CONTRACT = 5
80
+ const ID_TAG_CHANNEL = 6
81
+
82
+ export const ID_TAG = {
83
+ account: ID_TAG_ACCOUNT,
84
+ name: ID_TAG_NAME,
85
+ commitment: ID_TAG_COMMITMENT,
86
+ oracle: ID_TAG_ORACLE,
87
+ contract: ID_TAG_CONTRACT,
88
+ channel: ID_TAG_CHANNEL
89
+ }
90
+
91
+ export const PREFIX_ID_TAG = {
92
+ ak: ID_TAG.account,
93
+ nm: ID_TAG.name,
94
+ cm: ID_TAG.commitment,
95
+ ok: ID_TAG.oracle,
96
+ ct: ID_TAG.contract,
97
+ ch: ID_TAG.channel
98
+ }
99
+
100
+ export const ID_TAG_PREFIX = mapObject(PREFIX_ID_TAG, ([key, value]) => [value, key])
@@ -0,0 +1,61 @@
1
+ import {
2
+ writeId, readId, isNameValid, produceNameId, ensureNameValid, getMinimumNameFee, readInt, writeInt
3
+ } from './helpers'
4
+ import { InsufficientNameFeeError, IllegalArgumentError } from '../../utils/errors'
5
+
6
+ export class Field {
7
+ static serialize (value) {
8
+ return value
9
+ }
10
+
11
+ static deserialize (value) {
12
+ return value
13
+ }
14
+ }
15
+
16
+ export class Name extends Field {
17
+ static serialize (value) {
18
+ ensureNameValid(value)
19
+ return Buffer.from(value)
20
+ }
21
+
22
+ static deserialize (value) {
23
+ return value.toString()
24
+ }
25
+ }
26
+
27
+ export class NameId extends Field {
28
+ static serialize (value) {
29
+ return writeId(isNameValid(value) ? produceNameId(value) : value)
30
+ }
31
+
32
+ static deserialize (value) {
33
+ return readId(value)
34
+ }
35
+ }
36
+
37
+ export class NameFee extends Field {
38
+ static serialize (value, { name }) {
39
+ const minNameFee = getMinimumNameFee(name)
40
+ value ??= minNameFee
41
+ if (minNameFee.gt(value)) {
42
+ throw new InsufficientNameFeeError(value, minNameFee)
43
+ }
44
+ return writeInt(value)
45
+ }
46
+
47
+ static deserialize (value) {
48
+ return readInt(value)
49
+ }
50
+ }
51
+
52
+ export class Deposit extends Field {
53
+ static serialize (value, { name }) {
54
+ if (+value) throw new IllegalArgumentError(`Contract deposit is not refundable, so it should be equal 0, got ${value} instead`)
55
+ return writeInt(0)
56
+ }
57
+
58
+ static deserialize (value) {
59
+ return readInt(value)
60
+ }
61
+ }