@aeternity/aepp-sdk 8.2.0 → 10.0.0-beta.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 (145) hide show
  1. package/README.md +16 -9
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
  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 +33 -119
  10. package/es/account/base.js.map +1 -1
  11. package/es/account/memory.js +17 -19
  12. package/es/account/memory.js.map +1 -1
  13. package/es/account/multiple.js +75 -154
  14. package/es/account/multiple.js.map +1 -1
  15. package/es/ae/aens.js +164 -599
  16. package/es/ae/aens.js.map +1 -1
  17. package/es/ae/contract.js +108 -916
  18. package/es/ae/contract.js.map +1 -1
  19. package/es/ae/index.js +89 -250
  20. package/es/ae/index.js.map +1 -1
  21. package/es/ae/oracle.js +132 -500
  22. package/es/ae/oracle.js.map +1 -1
  23. package/es/chain/index.js +4 -23
  24. package/es/chain/index.js.map +1 -1
  25. package/es/chain/node.js +292 -1018
  26. package/es/chain/node.js.map +1 -1
  27. package/es/channel/handlers.js +597 -1086
  28. package/es/channel/handlers.js.map +1 -1
  29. package/es/channel/index.js +203 -451
  30. package/es/channel/index.js.map +1 -1
  31. package/es/channel/internal.js +129 -301
  32. package/es/channel/internal.js.map +1 -1
  33. package/es/contract/aci/index.js +319 -491
  34. package/es/contract/aci/index.js.map +1 -1
  35. package/es/contract/aci/transformation.js +35 -711
  36. package/es/contract/aci/transformation.js.map +1 -1
  37. package/es/contract/compiler.js +129 -203
  38. package/es/contract/compiler.js.map +1 -1
  39. package/es/contract/ga/helpers.js +17 -122
  40. package/es/contract/ga/helpers.js.map +1 -1
  41. package/es/contract/ga/index.js +102 -247
  42. package/es/contract/ga/index.js.map +1 -1
  43. package/es/contract/index.js +1 -1
  44. package/es/contract/index.js.map +1 -1
  45. package/es/index.js +2 -3
  46. package/es/index.js.map +1 -1
  47. package/es/node-pool/index.js +54 -73
  48. package/es/node-pool/index.js.map +1 -1
  49. package/es/node.js +56 -157
  50. package/es/node.js.map +1 -1
  51. package/es/other.d.ts +1 -1
  52. package/es/tx/builder/helpers.js +49 -89
  53. package/es/tx/builder/helpers.js.map +1 -1
  54. package/es/tx/builder/index.js +205 -303
  55. package/es/tx/builder/index.js.map +1 -1
  56. package/es/tx/builder/schema.js +585 -573
  57. package/es/tx/builder/schema.js.map +1 -1
  58. package/es/tx/index.js +1 -1
  59. package/es/tx/index.js.map +1 -1
  60. package/es/tx/tx-object.js +105 -135
  61. package/es/tx/tx-object.js.map +1 -1
  62. package/es/tx/tx.js +810 -1586
  63. package/es/tx/tx.js.map +1 -1
  64. package/es/tx/validator.js +191 -426
  65. package/es/tx/validator.js.map +1 -1
  66. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +17 -21
  67. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
  68. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +38 -74
  69. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
  70. package/es/utils/aepp-wallet-communication/content-script-bridge.js +14 -15
  71. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
  72. package/es/utils/aepp-wallet-communication/helpers.js +60 -105
  73. package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
  74. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +179 -510
  75. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
  76. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +70 -89
  77. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
  78. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +354 -603
  79. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
  80. package/es/utils/aepp-wallet-communication/schema.js +43 -39
  81. package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
  82. package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
  83. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
  84. package/es/utils/amount-formatter.js +41 -61
  85. package/es/utils/amount-formatter.js.map +1 -1
  86. package/es/utils/async-init.js +28 -64
  87. package/es/utils/async-init.js.map +1 -1
  88. package/es/utils/bignumber.js +3 -11
  89. package/es/utils/bignumber.js.map +1 -1
  90. package/es/utils/bytes.js +5 -9
  91. package/es/utils/bytes.js.map +1 -1
  92. package/es/utils/crypto.js +49 -75
  93. package/es/utils/crypto.js.map +1 -1
  94. package/es/utils/hd-wallet.js +45 -81
  95. package/es/utils/hd-wallet.js.map +1 -1
  96. package/es/utils/json-big.js +16 -49
  97. package/es/utils/json-big.js.map +1 -1
  98. package/es/utils/keystore.js +81 -246
  99. package/es/utils/keystore.js.map +1 -1
  100. package/es/utils/mptree.js +88 -134
  101. package/es/utils/mptree.js.map +1 -1
  102. package/es/utils/other.js +10 -60
  103. package/es/utils/other.js.map +1 -1
  104. package/es/utils/semver-satisfies.js +9 -28
  105. package/es/utils/semver-satisfies.js.map +1 -1
  106. package/es/utils/string.js +4 -13
  107. package/es/utils/string.js.map +1 -1
  108. package/es/utils/swagger.js +85 -218
  109. package/es/utils/swagger.js.map +1 -1
  110. package/package.json +52 -43
  111. package/src/account/base.js +8 -9
  112. package/src/account/multiple.js +20 -16
  113. package/src/ae/aens.js +25 -21
  114. package/src/ae/contract.js +65 -246
  115. package/src/ae/index.js +31 -7
  116. package/src/ae/oracle.js +21 -17
  117. package/src/chain/index.js +2 -12
  118. package/src/chain/node.js +26 -29
  119. package/src/channel/handlers.js +0 -1
  120. package/src/channel/index.js +4 -5
  121. package/src/contract/aci/index.js +221 -106
  122. package/src/contract/aci/transformation.js +30 -422
  123. package/src/contract/compiler.js +45 -4
  124. package/src/contract/ga/helpers.js +2 -12
  125. package/src/contract/ga/index.js +22 -26
  126. package/src/index.js +2 -4
  127. package/src/node-pool/index.js +21 -12
  128. package/src/node.js +22 -26
  129. package/src/tx/builder/helpers.js +12 -24
  130. package/src/tx/builder/index.js +18 -15
  131. package/src/tx/builder/schema.js +43 -108
  132. package/src/tx/tx-object.js +0 -2
  133. package/src/tx/tx.js +157 -144
  134. package/src/tx/validator.js +134 -202
  135. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +1 -3
  136. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +9 -10
  137. package/src/utils/aepp-wallet-communication/schema.js +1 -3
  138. package/src/utils/amount-formatter.ts +1 -1
  139. package/src/utils/bignumber.ts +2 -1
  140. package/src/utils/crypto.js +4 -17
  141. package/src/utils/other.ts +1 -1
  142. package/src/utils/semver-satisfies.ts +1 -1
  143. package/src/utils/swagger.js +24 -7
  144. package/CHANGELOG.md +0 -1716
  145. package/src/contract/aci/helpers.js +0 -140
package/src/ae/oracle.js CHANGED
@@ -27,10 +27,9 @@
27
27
  */
28
28
 
29
29
  import Ae from './'
30
- import * as R from 'ramda'
31
- import { decodeBase64Check, assertedType } from '../utils/crypto'
30
+ import { decodeBase64Check } from '../utils/crypto'
32
31
  import { pause } from '../utils/other'
33
- import { oracleQueryId } from '../tx/builder/helpers'
32
+ import { oracleQueryId, decode } from '../tx/builder/helpers'
34
33
  import { unpackTx } from '../tx/builder'
35
34
  import { ORACLE_TTL, QUERY_FEE, QUERY_TTL, RESPONSE_TTL } from '../tx/builder/schema'
36
35
 
@@ -121,9 +120,9 @@ export async function pollForQueryResponse (oracleId, queryId, { attempts = 20,
121
120
  for (let i = 0; i < attempts; i++) {
122
121
  if (i) await pause(interval)
123
122
  const { response } = await this.api.getOracleQueryByPubkeyAndQueryId(oracleId, queryId)
124
- const responseBuffer = decodeBase64Check(assertedType(response, 'or'))
123
+ const responseBuffer = decode(response, 'or')
125
124
  if (responseBuffer.length) {
126
- return { response, decode: () => responseBuffer } // TODO: Return just responseBuffer
125
+ return String(responseBuffer)
127
126
  }
128
127
  }
129
128
  throw new Error(`Giving up after ${(attempts - 1) * interval}ms`)
@@ -146,14 +145,15 @@ export async function pollForQueryResponse (oracleId, queryId, { attempts = 20,
146
145
  * @return {Promise<Object>} Oracle object
147
146
  */
148
147
  async function registerOracle (queryFormat, responseFormat, options = {}) {
149
- const opt = R.merge(this.Ae.defaults, options) // Preset VmVersion for oracle
148
+ const opt = { ...this.Ae.defaults, ...options } // Preset VmVersion for oracle
150
149
  const accountId = await this.address(opt)
151
150
 
152
- const oracleRegisterTx = await this.oracleRegisterTx(R.merge(opt, {
151
+ const oracleRegisterTx = await this.oracleRegisterTx({
152
+ ...opt,
153
153
  accountId,
154
154
  queryFormat,
155
155
  responseFormat
156
- }))
156
+ })
157
157
  return {
158
158
  ...await this.send(oracleRegisterTx, opt),
159
159
  ...await this.getOracleObject(`ok_${accountId.slice(3)}`)
@@ -177,14 +177,16 @@ async function registerOracle (queryFormat, responseFormat, options = {}) {
177
177
  * @return {Promise<Object>} Query object
178
178
  */
179
179
  async function postQueryToOracle (oracleId, query, options = {}) {
180
- const opt = R.merge(this.Ae.defaults, options)
180
+ const queryFee = options.queryFee || (await this.api.getOracleByPubkey(oracleId)).queryFee
181
+ const opt = { ...this.Ae.defaults, queryFee, ...options }
181
182
  const senderId = await this.address(opt)
182
183
 
183
- const oracleRegisterTx = await this.oraclePostQueryTx(R.merge(opt, {
184
+ const oracleRegisterTx = await this.oraclePostQueryTx({
185
+ ...opt,
184
186
  oracleId,
185
187
  senderId,
186
188
  query
187
- }))
189
+ })
188
190
  const queryId = oracleQueryId(senderId, unpackTx(oracleRegisterTx).tx.nonce, oracleId)
189
191
  return {
190
192
  ...await this.send(oracleRegisterTx, opt),
@@ -206,14 +208,15 @@ async function postQueryToOracle (oracleId, query, options = {}) {
206
208
  * @return {Promise<Object>} Oracle object
207
209
  */
208
210
  async function extendOracleTtl (oracleId, oracleTtl, options = {}) {
209
- const opt = R.merge(this.Ae.defaults, options)
211
+ const opt = { ...this.Ae.defaults, ...options }
210
212
  const callerId = await this.address(opt)
211
213
 
212
- const oracleExtendTx = await this.oracleExtendTx(R.merge(opt, {
214
+ const oracleExtendTx = await this.oracleExtendTx({
215
+ ...opt,
213
216
  oracleId,
214
217
  callerId,
215
218
  oracleTtl
216
- }))
219
+ })
217
220
  return {
218
221
  ...await this.send(oracleExtendTx, opt),
219
222
  ...await this.getOracleObject(oracleId)
@@ -236,15 +239,16 @@ async function extendOracleTtl (oracleId, oracleTtl, options = {}) {
236
239
  * @return {Promise<Object>} Oracle object
237
240
  */
238
241
  async function respondToQuery (oracleId, queryId, response, options = {}) {
239
- const opt = R.merge(this.Ae.defaults, options)
242
+ const opt = { ...this.Ae.defaults, ...options }
240
243
  const callerId = await this.address(opt)
241
244
 
242
- const oracleRespondTx = await this.oracleRespondTx(R.merge(opt, {
245
+ const oracleRespondTx = await this.oracleRespondTx({
246
+ ...opt,
243
247
  oracleId,
244
248
  queryId,
245
249
  callerId,
246
250
  response
247
- }))
251
+ })
248
252
  return {
249
253
  ...await this.send(oracleRespondTx, opt),
250
254
  ...await this.getOracleObject(oracleId)
@@ -37,8 +37,7 @@ import { required } from '@stamp/required'
37
37
  * @return {Object} Chain instance
38
38
  */
39
39
  const Chain = stampit({
40
- deepProps: { Ae: { defaults: { waitMined: true } } },
41
- statics: { waitMined (bool) { return this.deepProps({ Ae: { defaults: { waitMined: bool } } }) } }
40
+ deepProps: { Ae: { defaults: { waitMined: true, verify: true } } }
42
41
  }, required({
43
42
  methods: {
44
43
  sendTransaction: required,
@@ -56,15 +55,6 @@ const Chain = stampit({
56
55
  }
57
56
  }))
58
57
 
59
- /**
60
- * Reconfigure Stamp to (not) wait until transactions are mined
61
- * @function waitMined
62
- * @static
63
- * @rtype (bool: Boolean) => Stamp
64
- * @param {boolean} bool - Whether to wait for transactions
65
- * @return {Stamp} Reconfigured Chain Stamp
66
- */
67
-
68
58
  /**
69
59
  * Submit a signed transaction for mining
70
60
  * @function sendTransaction
@@ -74,7 +64,7 @@ const Chain = stampit({
74
64
  * @rtype (tx: String, options?: Object) => tx: Promise[Object]|txHash: Promise[String]
75
65
  * @param {String} tx - Transaction to submit
76
66
  * @param {String} [options={}] - Options to pass to the implementation
77
- * @param {String} [options.verify = false] - Verify transaction before broadcast.
67
+ * @param {String} [options.verify=true] - Verify transaction before broadcast.
78
68
  * @return {Object} Transaction
79
69
  */
80
70
 
package/src/chain/node.js CHANGED
@@ -14,15 +14,12 @@
14
14
  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
15
  * PERFORMANCE OF THIS SOFTWARE.
16
16
  */
17
- import * as R from 'ramda'
18
-
19
17
  import Chain from './'
20
18
  import { AE_AMOUNT_FORMATS, formatAmount } from '../utils/amount-formatter'
21
- import TransactionValidator from '../tx/validator'
19
+ import verifyTransaction from '../tx/validator'
22
20
  import NodePool from '../node-pool'
23
- import { assertedType } from '../utils/crypto'
24
21
  import { pause } from '../utils/other'
25
- import { isNameValid, produceNameId } from '../tx/builder/helpers'
22
+ import { isNameValid, produceNameId, decode } from '../tx/builder/helpers'
26
23
  import { DRY_RUN_ACCOUNT, NAME_ID_KEY } from '../tx/builder/schema'
27
24
 
28
25
  /**
@@ -35,15 +32,16 @@ import { DRY_RUN_ACCOUNT, NAME_ID_KEY } from '../tx/builder/schema'
35
32
  */
36
33
 
37
34
  async function sendTransaction (tx, options = {}) {
38
- const { waitMined, verify } = R.merge(this.Ae.defaults, options)
39
- // Verify transaction before broadcast
40
- if (verify || (typeof verify !== 'boolean' && this.verifyTxBeforeSend)) {
41
- const { validation, tx: txObject, txType } = await this.unpackAndVerify(tx)
35
+ const { waitMined, verify } = { ...this.Ae.defaults, ...options }
36
+ if (verify) {
37
+ const validation = await verifyTransaction(tx, this.selectedNode.instance)
42
38
  if (validation.length) {
43
- throw Object.assign(new Error('Transaction verification error: ' + JSON.stringify(validation)), {
39
+ const message = 'Transaction verification errors: ' +
40
+ validation.map(v => v.message).join(', ')
41
+ throw Object.assign(new Error(message), {
44
42
  code: 'TX_VERIFICATION_ERROR',
45
- errorData: { validation, tx: txObject, txType },
46
- txHash: tx
43
+ validation,
44
+ transaction: tx
47
45
  })
48
46
  }
49
47
  }
@@ -61,7 +59,7 @@ async function sendTransaction (tx, options = {}) {
61
59
  }
62
60
  return { hash: txHash, rawTx: tx }
63
61
  } catch (error) {
64
- throw Object.assign(error, { rawTx: tx, verifyTx: () => this.unpackAndVerify(tx) })
62
+ throw Object.assign(error, { rawTx: tx, verifyTx: () => verifyTransaction(tx, this.selectedNode.instance) })
65
63
  }
66
64
  }
67
65
 
@@ -140,7 +138,7 @@ async function topBlock () {
140
138
  return this.api.getTopHeader()
141
139
  }
142
140
 
143
- async function poll (th, { blocks = 10, interval = 5000, allowUnsynced = false } = {}) {
141
+ async function poll (th, { blocks = 10, interval = 500, allowUnsynced = false } = {}) {
144
142
  const max = await this.height() + blocks
145
143
  do {
146
144
  const tx = await this.tx(th).catch(_ => null)
@@ -221,31 +219,33 @@ async function getName (name) {
221
219
  * @param {String} nameOrId
222
220
  * @param {String} prefix
223
221
  * @param {Object} [options]
224
- * @param {Boolean} [options.verify] Enables resolving by node, needed for compatibility with `verify` option of other methods
225
- * @param {Boolean} [options.resolveByNode] Enables pointer resolving using node (isn't more durable to resolve it on the node side?)
222
+ * @param {Boolean} [options.verify] To ensure that name exist and have a corresponding pointer
223
+ * @param {Boolean} [options.resolveByNode] Enables pointer resolving using node // TODO: avoid that to don't trust to current api gateway
226
224
  * @return {String} Address or AENS name hash
227
225
  */
228
226
  async function resolveName (nameOrId, prefix, { verify, resolveByNode } = {}) {
229
227
  if (!nameOrId || typeof nameOrId !== 'string') {
230
- throw new Error('Invalid name or address. Should be a string')
228
+ throw new Error(`Name or address should be a string: ${nameOrId}`)
231
229
  }
232
230
  const prefixes = Object.keys(NAME_ID_KEY)
233
231
  if (!prefixes.includes(prefix)) {
234
- throw new Error(`Invalid prefix ${prefix}. Should be one of [${prefixes}]`)
232
+ throw new Error(`Invalid prefix ${prefix}, should be one of [${prefixes}]`)
235
233
  }
236
- if (assertedType(nameOrId, prefix, true)) return nameOrId
237
-
234
+ try {
235
+ decode(nameOrId, prefix)
236
+ return nameOrId
237
+ } catch (error) {}
238
238
  if (isNameValid(nameOrId)) {
239
- if (resolveByNode || verify) {
239
+ if (verify || resolveByNode) {
240
240
  const name = await this.getName(nameOrId).catch(_ => null)
241
- if (!name) throw new Error('Name not found')
241
+ if (!name) throw new Error(`Name not found: ${nameOrId}`)
242
242
  const pointer = name.pointers.find(({ id }) => id.split('_')[0] === prefix)
243
- if (!pointer) throw new Error(`Name ${nameOrId} do not have pointers for ${prefix}`)
244
- return pointer.id
243
+ if (!pointer) throw new Error(`Name ${nameOrId} don't have pointers for ${prefix}`)
244
+ if (resolveByNode) return pointer.id
245
245
  }
246
246
  return produceNameId(nameOrId)
247
247
  }
248
- throw new Error('Invalid name or address')
248
+ throw new Error(`Invalid name or address: ${nameOrId}`)
249
249
  }
250
250
 
251
251
  /**
@@ -260,10 +260,7 @@ async function resolveName (nameOrId, prefix, { verify, resolveByNode } = {}) {
260
260
  * @return {Object} ChainNode instance
261
261
  * @example ChainNode({url: 'https://testnet.aeternity.io/'})
262
262
  */
263
- const ChainNode = Chain.compose(TransactionValidator, NodePool, {
264
- init ({ verifyTx = true }) {
265
- this.verifyTxBeforeSend = verifyTx
266
- },
263
+ const ChainNode = Chain.compose(NodePool, {
267
264
  methods: {
268
265
  sendTransaction,
269
266
  balance,
@@ -603,7 +603,6 @@ export async function awaitingCallContractForceProgressUpdate (channel, message,
603
603
  }
604
604
 
605
605
  export function awaitingForceProgressCompletion (channel, message, state) {
606
- console.log('From force progress await completion ->', message)
607
606
  if (message.method === 'channels.on_chain_tx') {
608
607
  if (state.onOnChainTx) {
609
608
  state.onOnChainTx(message.params.data)
@@ -39,7 +39,6 @@ import {
39
39
  disconnect as channelDisconnect,
40
40
  fsmId as channelFsmId
41
41
  } from './internal'
42
- import * as R from 'ramda'
43
42
 
44
43
  function snakeToPascalObjKeys (obj) {
45
44
  return Object.entries(obj).reduce((result, [key, val]) => ({
@@ -238,10 +237,10 @@ async function poi ({ accounts, contracts }) {
238
237
  * )
239
238
  */
240
239
  async function balances (accounts) {
241
- return R.reduce((acc, item) => ({
242
- ...acc,
243
- [item.account]: item.balance
244
- }), {}, await call(this, 'channels.get.balances', { accounts }))
240
+ return Object.fromEntries(
241
+ (await call(this, 'channels.get.balances', { accounts }))
242
+ .map(item => [item.account, item.balance])
243
+ )
245
244
  }
246
245
 
247
246
  /**