@aeternity/aepp-sdk 10.0.0 → 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 (238) 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} +20 -10
  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} +10 -9
  14. package/es/account/multiple.mjs.map +1 -0
  15. package/es/ae/{aens.js → aens.mjs} +18 -22
  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} +8 -7
  22. package/es/ae/index.mjs.map +1 -0
  23. package/es/ae/{oracle.js → oracle.mjs} +33 -16
  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} +20 -4
  32. package/es/chain/index.mjs.map +1 -0
  33. package/es/chain/{node.js → node.mjs} +121 -73
  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} +7 -7
  38. package/es/channel/index.mjs.map +1 -0
  39. package/es/channel/{internal.js → internal.mjs} +49 -32
  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} +36 -28
  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.js → index.mjs} +11 -10
  53. package/es/node-pool/index.mjs.map +1 -0
  54. package/es/{node.js → node.mjs} +9 -8
  55. package/es/node.mjs.map +1 -0
  56. package/es/tx/builder/field-types.mjs +74 -0
  57. package/es/tx/builder/field-types.mjs.map +1 -0
  58. package/es/tx/builder/{helpers.js → helpers.mjs} +114 -56
  59. package/es/tx/builder/helpers.mjs.map +1 -0
  60. package/es/tx/builder/{index.js → index.mjs} +79 -68
  61. package/es/tx/builder/index.mjs.map +1 -0
  62. package/es/tx/builder/{schema.js → schema.mjs} +11 -65
  63. package/es/tx/builder/schema.mjs.map +1 -0
  64. package/es/tx/{index.js → index.mjs} +5 -2
  65. package/es/tx/index.mjs.map +1 -0
  66. package/es/tx/{tx-object.js → tx-object.mjs} +22 -15
  67. package/es/tx/tx-object.mjs.map +1 -0
  68. package/es/tx/{tx.js → tx.mjs} +15 -14
  69. package/es/tx/tx.mjs.map +1 -0
  70. package/es/tx/{validator.js → validator.mjs} +72 -33
  71. package/es/tx/validator.mjs.map +1 -0
  72. package/es/typings/blakejs/index.d.mjs +2 -0
  73. package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
  74. package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +7 -6
  75. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
  76. package/es/utils/aepp-wallet-communication/connection/{browser-window-message.js → browser-window-message.mjs} +10 -11
  77. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
  78. package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +5 -2
  79. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
  80. package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +6 -5
  81. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
  82. package/es/utils/aepp-wallet-communication/{helpers.js → helpers.mjs} +3 -14
  83. package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
  84. package/es/utils/aepp-wallet-communication/rpc/{aepp-rpc.js → aepp-rpc.mjs} +113 -67
  85. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
  86. package/es/utils/aepp-wallet-communication/rpc/{rpc-client.js → rpc-client.mjs} +14 -9
  87. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
  88. package/es/utils/aepp-wallet-communication/rpc/{wallet-rpc.js → wallet-rpc.mjs} +71 -63
  89. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
  90. package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
  91. package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
  92. package/es/utils/aepp-wallet-communication/{wallet-detector.js → wallet-detector.mjs} +6 -5
  93. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  94. package/es/utils/{amount-formatter.js → amount-formatter.mjs} +14 -7
  95. package/es/utils/amount-formatter.mjs.map +1 -0
  96. package/es/utils/{async-init.js → async-init.mjs} +8 -11
  97. package/es/utils/async-init.mjs.map +1 -0
  98. package/es/utils/{bignumber.js → bignumber.mjs} +2 -9
  99. package/es/utils/bignumber.mjs.map +1 -0
  100. package/es/utils/{bytes.js → bytes.mjs} +16 -8
  101. package/es/utils/bytes.mjs.map +1 -0
  102. package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
  103. package/es/utils/crypto-ts.mjs.map +1 -0
  104. package/es/utils/{crypto.js → crypto.mjs} +40 -105
  105. package/es/utils/crypto.mjs.map +1 -0
  106. package/es/utils/errors.mjs +689 -0
  107. package/es/utils/errors.mjs.map +1 -0
  108. package/es/utils/{hd-wallet.js → hd-wallet.mjs} +33 -34
  109. package/es/utils/hd-wallet.mjs.map +1 -0
  110. package/es/utils/{json-big.js → json-big.mjs} +1 -1
  111. package/es/utils/{json-big.js.map → json-big.mjs.map} +1 -1
  112. package/es/utils/{keystore.js → keystore.mjs} +63 -51
  113. package/es/utils/keystore.mjs.map +1 -0
  114. package/es/utils/{mptree.js → mptree.mjs} +21 -12
  115. package/es/utils/mptree.mjs.map +1 -0
  116. package/es/utils/{other.js → other.mjs} +2 -2
  117. package/es/utils/other.mjs.map +1 -0
  118. package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
  119. package/es/utils/{semver-satisfies.js.map → semver-satisfies.mjs.map} +1 -1
  120. package/es/utils/{string.js → string.mjs} +1 -1
  121. package/es/utils/{string.js.map → string.mjs.map} +1 -1
  122. package/es/utils/{swagger.js → swagger.mjs} +46 -14
  123. package/es/utils/swagger.mjs.map +1 -0
  124. package/package.json +46 -55
  125. package/src/account/memory.js +13 -8
  126. package/src/account/multiple.js +12 -4
  127. package/src/ae/aens.js +12 -17
  128. package/src/ae/aepp.js +2 -2
  129. package/src/ae/contract.js +15 -152
  130. package/src/ae/index.js +2 -1
  131. package/src/ae/oracle.js +25 -10
  132. package/src/ae/universal.js +2 -2
  133. package/src/ae/wallet.js +2 -2
  134. package/src/chain/index.js +21 -2
  135. package/src/chain/node.js +80 -53
  136. package/src/channel/handlers.js +20 -17
  137. package/src/channel/internal.js +30 -24
  138. package/src/contract/{aci/index.js → aci.js} +152 -93
  139. package/src/contract/compiler.js +22 -117
  140. package/src/contract/ga/helpers.js +7 -5
  141. package/src/contract/ga/index.js +27 -24
  142. package/src/index.js +7 -8
  143. package/src/node-pool/index.js +9 -8
  144. package/src/node.js +5 -7
  145. package/src/tx/builder/field-types.js +61 -0
  146. package/src/tx/builder/helpers.js +113 -58
  147. package/src/tx/builder/index.js +39 -34
  148. package/src/tx/builder/schema.js +11 -25
  149. package/src/tx/tx-object.js +10 -9
  150. package/src/tx/tx.js +17 -8
  151. package/src/tx/validator.js +25 -5
  152. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +8 -3
  153. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +10 -6
  154. package/src/utils/aepp-wallet-communication/content-script-bridge.js +5 -4
  155. package/src/utils/aepp-wallet-communication/helpers.js +2 -12
  156. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +81 -55
  157. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +15 -6
  158. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +60 -49
  159. package/src/utils/aepp-wallet-communication/schema.ts +80 -0
  160. package/src/utils/aepp-wallet-communication/wallet-detector.js +3 -2
  161. package/src/utils/amount-formatter.ts +4 -3
  162. package/src/utils/async-init.js +10 -6
  163. package/src/utils/bignumber.ts +1 -9
  164. package/src/utils/bytes.ts +3 -2
  165. package/src/utils/crypto-ts.ts +2 -2
  166. package/src/utils/crypto.js +9 -92
  167. package/src/utils/errors.ts +683 -0
  168. package/src/utils/hd-wallet.js +11 -26
  169. package/src/utils/keystore.js +47 -51
  170. package/src/utils/mptree.ts +12 -6
  171. package/src/utils/swagger.js +67 -44
  172. package/CHANGELOG.md +0 -1603
  173. package/es/account/base.js.map +0 -1
  174. package/es/account/memory.js.map +0 -1
  175. package/es/account/multiple.js.map +0 -1
  176. package/es/ae/aens.js.map +0 -1
  177. package/es/ae/aepp.js.map +0 -1
  178. package/es/ae/contract.js +0 -312
  179. package/es/ae/contract.js.map +0 -1
  180. package/es/ae/index.js.map +0 -1
  181. package/es/ae/oracle.js.map +0 -1
  182. package/es/ae/universal.js.map +0 -1
  183. package/es/ae/wallet.js.map +0 -1
  184. package/es/chain/index.js.map +0 -1
  185. package/es/chain/node.js.map +0 -1
  186. package/es/channel/handlers.js.map +0 -1
  187. package/es/channel/index.js.map +0 -1
  188. package/es/channel/internal.js.map +0 -1
  189. package/es/contract/aci/helpers.js +0 -298
  190. package/es/contract/aci/helpers.js.map +0 -1
  191. package/es/contract/aci/index.js +0 -361
  192. package/es/contract/aci/index.js.map +0 -1
  193. package/es/contract/aci/transformation.js +0 -66
  194. package/es/contract/aci/transformation.js.map +0 -1
  195. package/es/contract/compiler.js +0 -244
  196. package/es/contract/compiler.js.map +0 -1
  197. package/es/contract/ga/helpers.js +0 -22
  198. package/es/contract/ga/helpers.js.map +0 -1
  199. package/es/contract/ga/index.js.map +0 -1
  200. package/es/contract/index.js +0 -162
  201. package/es/contract/index.js.map +0 -1
  202. package/es/index.js +0 -57
  203. package/es/index.js.map +0 -1
  204. package/es/node-pool/index.js.map +0 -1
  205. package/es/node.js.map +0 -1
  206. package/es/tx/builder/helpers.js.map +0 -1
  207. package/es/tx/builder/index.js.map +0 -1
  208. package/es/tx/builder/schema.js.map +0 -1
  209. package/es/tx/index.js.map +0 -1
  210. package/es/tx/tx-object.js.map +0 -1
  211. package/es/tx/tx.js.map +0 -1
  212. package/es/tx/validator.js.map +0 -1
  213. package/es/typings/blakejs/index.d.js +0 -2
  214. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  215. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  216. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  217. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  218. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  219. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  220. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  221. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  222. package/es/utils/aepp-wallet-communication/schema.js +0 -107
  223. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  224. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  225. package/es/utils/amount-formatter.js.map +0 -1
  226. package/es/utils/async-init.js.map +0 -1
  227. package/es/utils/bignumber.js.map +0 -1
  228. package/es/utils/bytes.js.map +0 -1
  229. package/es/utils/crypto-ts.js.map +0 -1
  230. package/es/utils/crypto.js.map +0 -1
  231. package/es/utils/hd-wallet.js.map +0 -1
  232. package/es/utils/keystore.js.map +0 -1
  233. package/es/utils/mptree.js.map +0 -1
  234. package/es/utils/other.js.map +0 -1
  235. package/es/utils/swagger.js.map +0 -1
  236. package/src/contract/aci/transformation.js +0 -72
  237. package/src/contract/index.js +0 -163
  238. package/src/utils/aepp-wallet-communication/schema.js +0 -108
@@ -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,18 +16,18 @@
16
16
  */
17
17
 
18
18
  /**
19
- * ContractCompilerAPI module
19
+ * ContractCompilerHttp module
20
20
  *
21
- * This is the complement to {@link module:@aeternity/aepp-sdk/es/contract}.
22
21
  * @module @aeternity/aepp-sdk/es/contract/compiler
23
- * @export ContractCompilerAPI
24
- * @example import { ContractCompilerAPI } from '@aeternity/aepp-sdk'
22
+ * @export ContractCompilerHttp
23
+ * @example import { ContractCompilerHttp } from '@aeternity/aepp-sdk'
25
24
  */
26
25
 
27
- import ContractBase from './index'
28
26
  import semverSatisfies from '../utils/semver-satisfies'
29
27
  import AsyncInit from '../utils/async-init'
30
28
  import genSwaggerClient from '../utils/swagger'
29
+ import { MissingParamError, UnsupportedVersionError } from '../utils/errors'
30
+ import { mapObject } from '../utils/other'
31
31
 
32
32
  /**
33
33
  * Contract Compiler Stamp
@@ -39,16 +39,16 @@ import genSwaggerClient from '../utils/swagger'
39
39
  * @param {Object} [options={}] - Initializer object
40
40
  * @param {String} [options.compilerUrl] compilerUrl - Url for compiler API
41
41
  * @return {Object} Contract compiler instance
42
- * @example ContractCompilerAPI({ compilerUrl: 'COMPILER_URL' })
42
+ * @example ContractCompilerHttp({ compilerUrl: 'COMPILER_URL' })
43
43
  */
44
- export default AsyncInit.compose(ContractBase, {
44
+ export default AsyncInit.compose({
45
45
  async init ({ compilerUrl, ignoreVersion }) {
46
46
  if (!compilerUrl) return
47
47
  await this.setCompilerUrl(compilerUrl, { ignoreVersion })
48
48
  },
49
49
  methods: {
50
50
  async setCompilerUrl (compilerUrl, { ignoreVersion = false } = {}) {
51
- if (!compilerUrl) throw new Error('"compilerUrl" required')
51
+ if (!compilerUrl) throw new MissingParamError('compilerUrl required')
52
52
  compilerUrl = compilerUrl.replace(/\/$/, '')
53
53
  const client = await genSwaggerClient(`${compilerUrl}/api`, {
54
54
  disableBigNumbers: true,
@@ -73,117 +73,22 @@ export default AsyncInit.compose(ContractBase, {
73
73
  }
74
74
  })
75
75
  this.compilerVersion = client.spec.info.version
76
- this._compilerApi = client.api
76
+ this.compilerApi = mapObject(
77
+ client.api,
78
+ ([key, fn]) => [
79
+ key,
80
+ ({ options: { filesystem, ...options } = {}, ...args } = {}) => fn({
81
+ ...args, options: { ...options, file_system: filesystem }
82
+ })
83
+ ]
84
+ )
77
85
 
78
86
  if (ignoreVersion) return
79
87
  if (!semverSatisfies(this.compilerVersion, COMPILER_GE_VERSION, COMPILER_LT_VERSION)) {
80
- throw new Error(`Unsupported compiler version ${this.compilerVersion}. ` +
81
- `Supported: >= ${COMPILER_GE_VERSION} < ${COMPILER_LT_VERSION}`)
88
+ throw new UnsupportedVersionError(
89
+ 'compiler', this.compilerVersion, COMPILER_GE_VERSION, COMPILER_LT_VERSION
90
+ )
82
91
  }
83
- },
84
- _ensureCompilerReady () {
85
- if (!this._compilerApi) throw new Error('Compiler is not ready')
86
- },
87
- _prepareCompilerOptions ({ filesystem = {} } = {}) {
88
- return { file_system: filesystem }
89
- },
90
- getCompilerVersion () {
91
- this._ensureCompilerReady()
92
- return Promise.resolve(this.compilerVersion)
93
- },
94
- /**
95
- * Encode call data for contract call
96
- * @function
97
- * @category async
98
- * @param {String} source Contract source code
99
- * @param {String} name Name of function to call
100
- * @param {Array} args Argument's for call
101
- * @param {Object} [options={}] Options
102
- * @param {Object} [options.filesystem={}] Contract external namespaces map
103
- * @return {Promise<String>}
104
- */
105
- async contractEncodeCallDataAPI (source, name, args = [], options) {
106
- this._ensureCompilerReady()
107
- const { calldata } = await this._compilerApi.encodeCalldata({
108
- source,
109
- function: name,
110
- arguments: args,
111
- options: this._prepareCompilerOptions(options)
112
- })
113
- return calldata
114
- },
115
- async compileContractAPI (code, options) {
116
- this._ensureCompilerReady()
117
- const { bytecode } = await this._compilerApi.compileContract({
118
- code,
119
- options: this._prepareCompilerOptions(options)
120
- })
121
- return bytecode
122
- },
123
- contractGetACI (code, options) {
124
- this._ensureCompilerReady()
125
- return this._compilerApi.generateACI({ code, options: this._prepareCompilerOptions(options) })
126
- },
127
- contractDecodeCallDataByCodeAPI (bytecode, calldata) {
128
- this._ensureCompilerReady()
129
- return this._compilerApi.decodeCalldataBytecode({ bytecode, calldata })
130
- },
131
- contractDecodeCallDataBySourceAPI (source, fn, callData, options) {
132
- this._ensureCompilerReady()
133
- return this._compilerApi.decodeCalldataSource({
134
- function: fn,
135
- source,
136
- calldata: callData,
137
- options: this._prepareCompilerOptions(options)
138
- })
139
- },
140
- /**
141
- * Decode contract call result data
142
- * @function
143
- * @category async
144
- * @param {String} source - source code
145
- * @param {String } fn - function name
146
- * @param {String} callValue - result call data
147
- * @param {String} callResult - result status
148
- * @param {Object} [options={}] Options
149
- * @param {Object} [options.filesystem={}] Contract external namespaces map
150
- * @return {Promise<String>} Result object
151
- * @example
152
- * const decodedData = await sdk.contractDecodeCallResultAPI(
153
- * SourceCode ,'functionName', 'cb_asdasdasd...', 'ok|revert'
154
- * )
155
- */
156
- contractDecodeCallResultAPI (source, fn, callValue, callResult, options) {
157
- this._ensureCompilerReady()
158
- return this._compilerApi.decodeCallResult({
159
- function: fn,
160
- source,
161
- 'call-result': callResult,
162
- 'call-value': callValue,
163
- options: this._prepareCompilerOptions(options)
164
- })
165
- },
166
- async validateByteCodeAPI (bytecode, source, options) {
167
- this._ensureCompilerReady()
168
- const res = await this._compilerApi.validateByteCode({
169
- bytecode,
170
- source,
171
- options: this._prepareCompilerOptions(options)
172
- })
173
- return typeof res === 'object' ? true : res
174
- },
175
- getFateAssembler (bytecode, options) {
176
- this._ensureCompilerReady()
177
- return this._compilerApi.getFateAssemblerCode(
178
- { bytecode, options: this._prepareCompilerOptions(options) }
179
- )
180
- },
181
- getBytecodeCompilerVersion (bytecode, options) {
182
- this._ensureCompilerReady()
183
- return this._compilerApi.getCompilerVersion({
184
- bytecode,
185
- options: this._prepareCompilerOptions(options)
186
- })
187
92
  }
188
93
  },
189
94
  props: {
@@ -191,5 +96,5 @@ export default AsyncInit.compose(ContractBase, {
191
96
  }
192
97
  })
193
98
 
194
- const COMPILER_GE_VERSION = '6.0.0'
99
+ const COMPILER_GE_VERSION = '6.1.0'
195
100
  const COMPILER_LT_VERSION = '7.0.0'
@@ -1,17 +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
12
  }
12
- if (!authData.source || !authData.args) throw new Error('Auth data must contain source code and arguments.')
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 })
13
15
  return {
14
- authCallData: await ins.contractEncodeCallDataAPI(authData.source, authFnName, authData.args),
16
+ authCallData: contract.calldata.encode(contract._name, authFnName, authData.args),
15
17
  gas
16
18
  }
17
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,52 +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, {
49
+ * await aeSdk.spend(10000, receiverPub, {
49
50
  * authData: { source: authContract, args: [...authContractArgs] }
50
51
  * }) // sdk will prepare callData itself
51
52
  */
52
- export const GeneralizeAccount = ContractAPI.compose({
53
+ export const GeneralizedAccount = Contract.compose({
53
54
  methods: {
54
- createGeneralizeAccount,
55
+ createGeneralizedAccount,
55
56
  createMetaTx,
56
57
  isGA
57
58
  }
58
59
  })
59
- export default GeneralizeAccount
60
+ export default GeneralizedAccount
60
61
 
61
62
  /**
62
63
  * @alias module:@aeternity/aepp-sdk/es/contract/ga
63
64
  * @function
64
- * Check if account is GA account
65
+ * Check if account is GA
65
66
  * @param {String} address - Account address
66
67
  * @return {Boolean}
67
68
  */
@@ -71,7 +72,7 @@ async function isGA (address) {
71
72
  }
72
73
 
73
74
  /**
74
- * Convert current account to GA account
75
+ * Convert current account to GA
75
76
  * @alias module:@aeternity/aepp-sdk/es/contract/ga
76
77
  * @function
77
78
  * @param {String} authFnName - Authorization function name
@@ -79,20 +80,22 @@ async function isGA (address) {
79
80
  * @param {Array} [args] - init arguments
80
81
  * @param {Object} [options] - Options
81
82
  * @return {Promise<Readonly<{
82
- * result: *, owner: *, createdAt: Date, address, rawTx: *, transaction: *
83
+ * result: *, owner: *, address, rawTx: *, transaction: *
83
84
  * }>>}
84
85
  */
85
- async function createGeneralizeAccount (authFnName, source, args = [], options = {}) {
86
+ async function createGeneralizedAccount (authFnName, source, args = [], options = {}) {
86
87
  const opt = { ...this.Ae.defaults, ...options }
87
88
  const ownerId = await this.address(opt)
89
+ if (await this.isGA(ownerId)) throw new IllegalArgumentError(`Account ${ownerId} is already GA`)
88
90
 
89
- if (await this.isGA(ownerId)) throw new Error(`Account ${ownerId} is already GA`)
90
-
91
+ const contract = await this.getContractInstance({ source })
92
+ await contract.compile()
91
93
  const { tx, contractId } = await this.gaAttachTx({
92
94
  ...opt,
95
+ gas: opt.gas ?? await contract._estimateGas('init', args, opt),
93
96
  ownerId,
94
- code: (await this.contractCompile(source)).bytecode,
95
- callData: await this.contractEncodeCallDataAPI(source, 'init', args),
97
+ code: contract.bytecode,
98
+ callData: contract.calldata.encode(contract._name, 'init', args),
96
99
  authFun: hash(authFnName)
97
100
  })
98
101
 
@@ -119,7 +122,7 @@ const wrapInEmptySignedTx = (tx) => buildTx({ encodedTx: tx, signatures: [] }, T
119
122
  * @return {String}
120
123
  */
121
124
  async function createMetaTx (rawTransaction, authData, authFnName, options = {}) {
122
- if (!authData) throw new Error('authData is required')
125
+ if (!authData) throw new MissingParamError('authData is required')
123
126
  // Check if authData is callData or if it's an object prepare a callData from source and args
124
127
  const { authCallData, gas } = await prepareGaParams(this)(authData, authFnName)
125
128
  const opt = { ...this.Ae.defaults, ...options }
@@ -132,7 +135,7 @@ async function createMetaTx (rawTransaction, authData, authFnName, options = {})
132
135
  tx: wrappedTx.txObject
133
136
  },
134
137
  gaId: await this.address(opt),
135
- abiVersion: abiVersion,
138
+ abiVersion,
136
139
  authData: authCallData,
137
140
  gas,
138
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,7 @@ 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
56
 
57
57
  export const getDefaultPointerKey = TxBuilderHelper.getDefaultPointerKey
58
58
 
@@ -64,8 +64,7 @@ export {
64
64
  Aens,
65
65
  Bytes,
66
66
  Contract,
67
- ContractCompilerAPI,
68
- ACITransformation,
67
+ ContractCompilerHttp,
69
68
  ChainNode,
70
69
  RpcAepp,
71
70
  RpcWallet,
@@ -73,7 +72,7 @@ export {
73
72
  Crypto,
74
73
  Keystore,
75
74
  Chain,
76
- GeneralizeAccount,
75
+ GeneralizedAccount,
77
76
  HdWallet,
78
77
  MemoryAccount,
79
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
  }
@@ -55,7 +56,7 @@ export default stampit({
55
56
  * nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true)
56
57
  */
57
58
  addNode (name, node, select = false) {
58
- if (this.pool.has(name)) throw new Error(`Node with name ${name} already exist`)
59
+ if (this.pool.has(name)) throw new DuplicateNodeError(name)
59
60
 
60
61
  this.validateNodes([{ name, instance: node }])
61
62
 
@@ -83,7 +84,7 @@ export default stampit({
83
84
  * nodePool.selectNode('testNode')
84
85
  */
85
86
  selectNode (name) {
86
- 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`)
87
88
 
88
89
  this.selectedNode = this.pool.get(name)
89
90
  },
@@ -119,7 +120,7 @@ export default stampit({
119
120
  * nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }
120
121
  */
121
122
  getNodeInfo () {
122
- if (!this.isNodeConnected()) throw new Error('Can not get node info. Node is not connected')
123
+ if (!this.isNodeConnected()) throw new DisconnectedError()
123
124
  return {
124
125
  name: this.selectedNode.name,
125
126
  ...this.selectedNode.instance.getNodeInfo()
@@ -143,12 +144,12 @@ export default stampit({
143
144
  validateNodes (nodes) {
144
145
  // TODO: validate it on TypeScript level instead
145
146
  // (to speedup development, save runtime resources)
146
- if (!Array.isArray(nodes)) throw new Error('"nodes" should be an array')
147
+ if (!Array.isArray(nodes)) throw new TypeError('"nodes" should be an array')
147
148
  const notObject = nodes.map(n => typeof n).find(t => t !== 'object')
148
- 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`)
149
150
  const wrongFields = nodes.find(n => typeof n.name !== 'string' || typeof n.instance !== 'object')
150
151
  if (notObject) {
151
- throw new Error(
152
+ throw new TypeError(
152
153
  'Each node should have name (string), instance (object) ' +
153
154
  `fields, got ${JSON.stringify(wrongFields)} instead`
154
155
  )
@@ -158,7 +159,7 @@ export default stampit({
158
159
  .find(i => typeof i.api !== 'object' || typeof i.genesisHash !== 'string' ||
159
160
  typeof i.consensusProtocolVersion !== 'number')
160
161
  if (wrongInstanceFields) {
161
- throw new Error(
162
+ throw new TypeError(
162
163
  'Each node instance should have api (object), consensusProtocolVersion (number), ' +
163
164
  `genesisHash (string) fields, got ${JSON.stringify(wrongInstanceFields)} instead`
164
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
@@ -35,7 +36,7 @@ import semverSatisfies from './utils/semver-satisfies'
35
36
  */
36
37
  export function getNetworkId ({ networkId, force = false } = {}) {
37
38
  const res = networkId || this.networkId || this.selectedNode?.networkId
38
- if (!force && !res) throw new Error('networkId is not provided')
39
+ if (!force && !res) throw new MissingParamError('networkId is not provided')
39
40
  if (force && !res) return null
40
41
  return res
41
42
  }
@@ -56,9 +57,9 @@ export function getNetworkId ({ networkId, force = false } = {}) {
56
57
  */
57
58
  const Node = AsyncInit.compose({
58
59
  async init ({ url, internalUrl, ignoreVersion }) {
59
- if (!url) throw new Error('"url" required')
60
+ if (!url) throw new MissingParamError('"url" required')
60
61
  this.url = url.replace(/\/$/, '')
61
- this.internalUrl = internalUrl ? internalUrl.replace(/\/$/, '') : this.url
62
+ this.internalUrl = internalUrl?.replace(/\/$/, '')
62
63
  const client = await genSwaggerClient(`${this.url}/api?oas3`, {
63
64
  internalUrl: this.internalUrl,
64
65
  responseInterceptor: response => {
@@ -73,10 +74,7 @@ const Node = AsyncInit.compose({
73
74
  !semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) &&
74
75
  !ignoreVersion
75
76
  ) {
76
- throw new Error(
77
- `Unsupported node version ${this.version}. ` +
78
- `Supported: >= ${NODE_GE_VERSION} < ${NODE_LT_VERSION}`
79
- )
77
+ throw new UnsupportedVersionError('node', this.version, NODE_GE_VERSION, NODE_LT_VERSION)
80
78
  }
81
79
  this.api = client.api
82
80
 
@@ -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
+ }