@aeternity/aepp-sdk 9.0.1 → 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 (137) hide show
  1. package/dist/aepp-sdk.browser-script.js +1 -1
  2. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
  3. package/dist/aepp-sdk.browser-script.js.map +1 -1
  4. package/dist/aepp-sdk.browser.js +1 -1
  5. package/dist/aepp-sdk.browser.js.map +1 -1
  6. package/dist/aepp-sdk.js +1 -1
  7. package/dist/aepp-sdk.js.map +1 -1
  8. package/es/account/base.js +30 -122
  9. package/es/account/base.js.map +1 -1
  10. package/es/account/memory.js +17 -19
  11. package/es/account/memory.js.map +1 -1
  12. package/es/account/multiple.js +73 -164
  13. package/es/account/multiple.js.map +1 -1
  14. package/es/ae/aens.js +164 -599
  15. package/es/ae/aens.js.map +1 -1
  16. package/es/ae/contract.js +82 -759
  17. package/es/ae/contract.js.map +1 -1
  18. package/es/ae/index.js +78 -315
  19. package/es/ae/index.js.map +1 -1
  20. package/es/ae/oracle.js +130 -498
  21. package/es/ae/oracle.js.map +1 -1
  22. package/es/chain/index.js +1 -1
  23. package/es/chain/index.js.map +1 -1
  24. package/es/chain/node.js +288 -1008
  25. package/es/chain/node.js.map +1 -1
  26. package/es/channel/handlers.js +597 -1086
  27. package/es/channel/handlers.js.map +1 -1
  28. package/es/channel/index.js +203 -451
  29. package/es/channel/index.js.map +1 -1
  30. package/es/channel/internal.js +129 -301
  31. package/es/channel/internal.js.map +1 -1
  32. package/es/contract/aci/index.js +319 -480
  33. package/es/contract/aci/index.js.map +1 -1
  34. package/es/contract/aci/transformation.js +35 -711
  35. package/es/contract/aci/transformation.js.map +1 -1
  36. package/es/contract/compiler.js +129 -203
  37. package/es/contract/compiler.js.map +1 -1
  38. package/es/contract/ga/helpers.js +16 -114
  39. package/es/contract/ga/helpers.js.map +1 -1
  40. package/es/contract/ga/index.js +101 -242
  41. package/es/contract/ga/index.js.map +1 -1
  42. package/es/contract/index.js +1 -1
  43. package/es/contract/index.js.map +1 -1
  44. package/es/index.js +1 -2
  45. package/es/index.js.map +1 -1
  46. package/es/node-pool/index.js +54 -73
  47. package/es/node-pool/index.js.map +1 -1
  48. package/es/node.js +56 -157
  49. package/es/node.js.map +1 -1
  50. package/es/other.d.ts +1 -1
  51. package/es/tx/builder/helpers.js +38 -75
  52. package/es/tx/builder/helpers.js.map +1 -1
  53. package/es/tx/builder/index.js +196 -294
  54. package/es/tx/builder/index.js.map +1 -1
  55. package/es/tx/builder/schema.js +577 -459
  56. package/es/tx/builder/schema.js.map +1 -1
  57. package/es/tx/index.js +1 -1
  58. package/es/tx/index.js.map +1 -1
  59. package/es/tx/tx-object.js +105 -132
  60. package/es/tx/tx-object.js.map +1 -1
  61. package/es/tx/tx.js +808 -1628
  62. package/es/tx/tx.js.map +1 -1
  63. package/es/tx/validator.js +132 -268
  64. package/es/tx/validator.js.map +1 -1
  65. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +17 -21
  66. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
  67. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +38 -74
  68. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
  69. package/es/utils/aepp-wallet-communication/content-script-bridge.js +14 -15
  70. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
  71. package/es/utils/aepp-wallet-communication/helpers.js +60 -105
  72. package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
  73. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +179 -510
  74. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
  75. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +70 -89
  76. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
  77. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +353 -600
  78. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
  79. package/es/utils/aepp-wallet-communication/schema.js +43 -39
  80. package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
  81. package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
  82. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
  83. package/es/utils/amount-formatter.js +41 -61
  84. package/es/utils/amount-formatter.js.map +1 -1
  85. package/es/utils/async-init.js +28 -64
  86. package/es/utils/async-init.js.map +1 -1
  87. package/es/utils/bignumber.js +3 -11
  88. package/es/utils/bignumber.js.map +1 -1
  89. package/es/utils/bytes.js +5 -9
  90. package/es/utils/bytes.js.map +1 -1
  91. package/es/utils/crypto.js +47 -62
  92. package/es/utils/crypto.js.map +1 -1
  93. package/es/utils/hd-wallet.js +45 -81
  94. package/es/utils/hd-wallet.js.map +1 -1
  95. package/es/utils/json-big.js +16 -49
  96. package/es/utils/json-big.js.map +1 -1
  97. package/es/utils/keystore.js +81 -246
  98. package/es/utils/keystore.js.map +1 -1
  99. package/es/utils/mptree.js +88 -134
  100. package/es/utils/mptree.js.map +1 -1
  101. package/es/utils/other.js +10 -60
  102. package/es/utils/other.js.map +1 -1
  103. package/es/utils/semver-satisfies.js +9 -28
  104. package/es/utils/semver-satisfies.js.map +1 -1
  105. package/es/utils/string.js +4 -13
  106. package/es/utils/string.js.map +1 -1
  107. package/es/utils/swagger.js +85 -224
  108. package/es/utils/swagger.js.map +1 -1
  109. package/package.json +44 -40
  110. package/src/account/multiple.js +18 -19
  111. package/src/ae/aens.js +25 -21
  112. package/src/ae/contract.js +32 -163
  113. package/src/ae/index.js +3 -3
  114. package/src/ae/oracle.js +18 -14
  115. package/src/chain/node.js +2 -4
  116. package/src/channel/handlers.js +0 -1
  117. package/src/channel/index.js +4 -5
  118. package/src/contract/aci/index.js +221 -102
  119. package/src/contract/aci/transformation.js +30 -422
  120. package/src/contract/compiler.js +45 -4
  121. package/src/contract/ga/helpers.js +1 -8
  122. package/src/contract/ga/index.js +13 -11
  123. package/src/index.js +0 -2
  124. package/src/node-pool/index.js +21 -12
  125. package/src/node.js +22 -26
  126. package/src/tx/builder/index.js +2 -1
  127. package/src/tx/builder/schema.js +2 -1
  128. package/src/tx/tx.js +147 -143
  129. package/src/tx/validator.js +9 -7
  130. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +1 -3
  131. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +3 -3
  132. package/src/utils/aepp-wallet-communication/schema.js +1 -3
  133. package/src/utils/bignumber.ts +2 -1
  134. package/src/utils/other.ts +1 -1
  135. package/src/utils/semver-satisfies.ts +1 -1
  136. package/src/utils/swagger.js +14 -7
  137. package/src/contract/aci/helpers.js +0 -140
@@ -5,7 +5,6 @@
5
5
  * @example import { NodePool } from '@aeternity/aepp-sdk'
6
6
  */
7
7
  import stampit from '@stamp/it'
8
- import Joi from 'joi-browser'
9
8
  import { getNetworkId } from '../node'
10
9
 
11
10
  /**
@@ -141,17 +140,27 @@ export default stampit({
141
140
  }))
142
141
  },
143
142
  validateNodes (nodes) {
144
- const { error } = Joi.array().items(
145
- Joi.object({
146
- name: Joi.string().required(),
147
- instance: Joi.object({
148
- api: Joi.object().required(),
149
- consensusProtocolVersion: Joi.number().required(),
150
- genesisHash: Joi.string().required()
151
- }).unknown()
152
- })
153
- ).label('node').validate(nodes)
154
- if (error) throw error
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
+ 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`)
147
+ const wrongFields = nodes.find(n => typeof n.name !== 'string' || typeof n.instance !== 'object')
148
+ if (notObject) {
149
+ throw new Error(
150
+ 'Each node should have name (string), instance (object) ' +
151
+ `fields, got ${JSON.stringify(wrongFields)} instead`
152
+ )
153
+ }
154
+ const wrongInstanceFields = nodes
155
+ .map(n => n.instance)
156
+ .find(i => typeof i.api !== 'object' || typeof i.genesisHash !== 'string' ||
157
+ typeof i.consensusProtocolVersion !== 'number')
158
+ if (wrongInstanceFields) {
159
+ throw new Error(
160
+ 'Each node instance should have api (object), consensusProtocolVersion (number), ' +
161
+ `genesisHash (string) fields, got ${JSON.stringify(wrongInstanceFields)} instead`
162
+ )
163
+ }
155
164
  }
156
165
  },
157
166
  props: {
package/src/node.js CHANGED
@@ -39,26 +39,6 @@ export function getNetworkId ({ networkId, force = false } = {}) {
39
39
  return networkId || this.networkId || this.selectedNode.networkId
40
40
  }
41
41
 
42
- /**
43
- * get consensus protocol version
44
- * @param {Array} protocols Array of protocols
45
- * @param {Number} height Height
46
- * @return {Number} version Protocol version
47
- */
48
- async function getConsensusProtocolVersion (protocols = [], height) {
49
- if (!protocols) throw new Error('Protocols must be an array')
50
- if (!height) height = (await this.api.getCurrentKeyBlock()).height
51
- if (height < 0) throw new Error('height must be a number >= 0')
52
-
53
- return protocols
54
- .filter(({ effectiveAtHeight }) => height >= effectiveAtHeight)
55
- .reduce(
56
- (acc, p) => p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc,
57
- { effectiveAtHeight: -1, version: 0 }
58
- )
59
- .version
60
- }
61
-
62
42
  /**
63
43
  * {@link genSwaggerClient} based Node remote API Stamp
64
44
  * @function
@@ -76,7 +56,15 @@ const Node = AsyncInit.compose({
76
56
  if (!url) throw new Error('"url" required')
77
57
  this.url = url.replace(/\/$/, '')
78
58
  this.internalUrl = internalUrl ? internalUrl.replace(/\/$/, '') : this.url
79
- const client = await genSwaggerClient(`${this.url}/api?oas3`, { internalUrl: this.internalUrl })
59
+ const client = await genSwaggerClient(`${this.url}/api?oas3`, {
60
+ internalUrl: this.internalUrl,
61
+ responseInterceptor: response => {
62
+ if (response.ok) return
63
+ return Object.assign(response, {
64
+ statusText: `${new URL(response.url).pathname.slice(1)} error: ` + response.body.reason
65
+ })
66
+ }
67
+ })
80
68
  this.version = client.spec.info.version
81
69
  if (
82
70
  !semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) &&
@@ -89,8 +77,17 @@ const Node = AsyncInit.compose({
89
77
  }
90
78
  this.api = client.api
91
79
 
92
- const { nodeRevision: revision, genesisKeyBlockHash: genesisHash, networkId, protocols } = await this.api.getStatus()
93
- this.consensusProtocolVersion = await this.getConsensusProtocolVersion(protocols)
80
+ const {
81
+ nodeRevision: revision, genesisKeyBlockHash: genesisHash, networkId,
82
+ protocols, topBlockHeight
83
+ } = await this.api.getStatus()
84
+ this.consensusProtocolVersion = protocols
85
+ .filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)
86
+ .reduce(
87
+ (acc, p) => p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc,
88
+ { effectiveAtHeight: -1, version: 0 }
89
+ )
90
+ .version
94
91
  this.nodeNetworkId = networkId
95
92
  return Object.assign(this, { revision, genesisHash })
96
93
  },
@@ -103,8 +100,7 @@ const Node = AsyncInit.compose({
103
100
  version: this.version,
104
101
  consensusProtocolVersion: this.consensusProtocolVersion
105
102
  }
106
- },
107
- getConsensusProtocolVersion
103
+ }
108
104
  },
109
105
  props: {
110
106
  version: null,
@@ -113,7 +109,7 @@ const Node = AsyncInit.compose({
113
109
  }
114
110
  })
115
111
 
116
- const NODE_GE_VERSION = '6.0.0'
112
+ const NODE_GE_VERSION = '6.2.0'
117
113
  const NODE_LT_VERSION = '7.0.0'
118
114
 
119
115
  export default Node
@@ -256,7 +256,8 @@ function buildFee (txType, { params, gas = 0, multiplier, vsn }) {
256
256
  .plus(TX_FEE_OTHER_GAS(txType, txSize, {
257
257
  relativeTtl: getOracleRelativeTtl(params, txType),
258
258
  innerTxSize: [TX_TYPE.gaMeta, TX_TYPE.payingFor].includes(txType)
259
- ? params.tx.tx.encodedTx.rlpEncoded.length : 0
259
+ ? params.tx.tx.encodedTx.rlpEncoded.length
260
+ : 0
260
261
  }))
261
262
  .times(multiplier)
262
263
  }
@@ -48,7 +48,8 @@ export const NAME_ID_KEY = {
48
48
  ct: 'contract_pubkey',
49
49
  ch: 'channel'
50
50
  }
51
- // # ref: https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L290
51
+ // # https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L290
52
+ // # https://github.com/aeternity/protocol/blob/master/AENS.md#protocol-fees-and-protection-times
52
53
  // # bid ranges:
53
54
  export const NAME_BID_RANGES = {
54
55
  31: BigNumber(3).times(NAME_FEE_MULTIPLIER),