@aeternity/aepp-sdk 8.2.1 → 10.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 (159) hide show
  1. package/CHANGELOG.md +216 -337
  2. package/README.md +16 -9
  3. package/dist/aepp-sdk.browser-script.js +1 -1
  4. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
  5. package/dist/aepp-sdk.browser-script.js.map +1 -1
  6. package/dist/aepp-sdk.browser.js +1 -1
  7. package/dist/aepp-sdk.browser.js.map +1 -1
  8. package/dist/aepp-sdk.js +1 -1
  9. package/dist/aepp-sdk.js.map +1 -1
  10. package/es/account/base.js +36 -120
  11. package/es/account/base.js.map +1 -1
  12. package/es/account/memory.js +17 -19
  13. package/es/account/memory.js.map +1 -1
  14. package/es/account/multiple.js +79 -156
  15. package/es/account/multiple.js.map +1 -1
  16. package/es/ae/aens.js +205 -626
  17. package/es/ae/aens.js.map +1 -1
  18. package/es/ae/contract.js +114 -918
  19. package/es/ae/contract.js.map +1 -1
  20. package/es/ae/index.js +90 -250
  21. package/es/ae/index.js.map +1 -1
  22. package/es/ae/oracle.js +136 -504
  23. package/es/ae/oracle.js.map +1 -1
  24. package/es/ae/universal.js.map +1 -1
  25. package/es/chain/index.js +12 -27
  26. package/es/chain/index.js.map +1 -1
  27. package/es/chain/node.js +289 -1020
  28. package/es/chain/node.js.map +1 -1
  29. package/es/channel/handlers.js +597 -1086
  30. package/es/channel/handlers.js.map +1 -1
  31. package/es/channel/index.js +238 -465
  32. package/es/channel/index.js.map +1 -1
  33. package/es/channel/internal.js +129 -301
  34. package/es/channel/internal.js.map +1 -1
  35. package/es/contract/aci/index.js +328 -495
  36. package/es/contract/aci/index.js.map +1 -1
  37. package/es/contract/aci/transformation.js +35 -711
  38. package/es/contract/aci/transformation.js.map +1 -1
  39. package/es/contract/compiler.js +131 -203
  40. package/es/contract/compiler.js.map +1 -1
  41. package/es/contract/ga/helpers.js +17 -122
  42. package/es/contract/ga/helpers.js.map +1 -1
  43. package/es/contract/ga/index.js +108 -249
  44. package/es/contract/ga/index.js.map +1 -1
  45. package/es/contract/index.js +7 -3
  46. package/es/contract/index.js.map +1 -1
  47. package/es/index.js +3 -3
  48. package/es/index.js.map +1 -1
  49. package/es/node-pool/index.js +57 -74
  50. package/es/node-pool/index.js.map +1 -1
  51. package/es/node.js +65 -161
  52. package/es/node.js.map +1 -1
  53. package/es/other.d.ts +1 -1
  54. package/es/tx/builder/helpers.js +62 -115
  55. package/es/tx/builder/helpers.js.map +1 -1
  56. package/es/tx/builder/index.js +218 -309
  57. package/es/tx/builder/index.js.map +1 -1
  58. package/es/tx/builder/schema.js +586 -573
  59. package/es/tx/builder/schema.js.map +1 -1
  60. package/es/tx/index.js +102 -13
  61. package/es/tx/index.js.map +1 -1
  62. package/es/tx/tx-object.js +114 -138
  63. package/es/tx/tx-object.js.map +1 -1
  64. package/es/tx/tx.js +810 -1586
  65. package/es/tx/tx.js.map +1 -1
  66. package/es/tx/validator.js +191 -426
  67. package/es/tx/validator.js.map +1 -1
  68. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +20 -23
  69. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
  70. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +53 -80
  71. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
  72. package/es/utils/aepp-wallet-communication/connection/index.js +2 -1
  73. package/es/utils/aepp-wallet-communication/connection/index.js.map +1 -1
  74. package/es/utils/aepp-wallet-communication/content-script-bridge.js +24 -19
  75. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
  76. package/es/utils/aepp-wallet-communication/helpers.js +60 -105
  77. package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
  78. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +191 -514
  79. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
  80. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +78 -93
  81. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
  82. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +381 -613
  83. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
  84. package/es/utils/aepp-wallet-communication/schema.js +43 -39
  85. package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
  86. package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
  87. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
  88. package/es/utils/amount-formatter.js +41 -61
  89. package/es/utils/amount-formatter.js.map +1 -1
  90. package/es/utils/async-init.js +28 -64
  91. package/es/utils/async-init.js.map +1 -1
  92. package/es/utils/bignumber.js +3 -11
  93. package/es/utils/bignumber.js.map +1 -1
  94. package/es/utils/bytes.js +5 -9
  95. package/es/utils/bytes.js.map +1 -1
  96. package/es/utils/crypto.js +41 -106
  97. package/es/utils/crypto.js.map +1 -1
  98. package/es/utils/hd-wallet.js +45 -81
  99. package/es/utils/hd-wallet.js.map +1 -1
  100. package/es/utils/json-big.js +16 -49
  101. package/es/utils/json-big.js.map +1 -1
  102. package/es/utils/keystore.js +81 -246
  103. package/es/utils/keystore.js.map +1 -1
  104. package/es/utils/mptree.js +88 -134
  105. package/es/utils/mptree.js.map +1 -1
  106. package/es/utils/other.js +10 -60
  107. package/es/utils/other.js.map +1 -1
  108. package/es/utils/semver-satisfies.js +9 -28
  109. package/es/utils/semver-satisfies.js.map +1 -1
  110. package/es/utils/string.js +4 -13
  111. package/es/utils/string.js.map +1 -1
  112. package/es/utils/swagger.js +87 -224
  113. package/es/utils/swagger.js.map +1 -1
  114. package/package.json +51 -44
  115. package/src/account/base.js +11 -10
  116. package/src/account/multiple.js +24 -18
  117. package/src/ae/aens.js +64 -61
  118. package/src/ae/contract.js +71 -248
  119. package/src/ae/index.js +34 -9
  120. package/src/ae/oracle.js +30 -22
  121. package/src/ae/universal.js +3 -1
  122. package/src/chain/index.js +10 -16
  123. package/src/chain/node.js +38 -38
  124. package/src/channel/handlers.js +10 -4
  125. package/src/channel/index.js +44 -20
  126. package/src/contract/aci/index.js +234 -112
  127. package/src/contract/aci/transformation.js +30 -422
  128. package/src/contract/compiler.js +50 -5
  129. package/src/contract/ga/helpers.js +6 -14
  130. package/src/contract/ga/index.js +28 -28
  131. package/src/contract/index.js +6 -2
  132. package/src/index.js +4 -4
  133. package/src/node-pool/index.js +24 -13
  134. package/src/node.js +29 -30
  135. package/src/tx/builder/helpers.js +31 -56
  136. package/src/tx/builder/index.js +67 -28
  137. package/src/tx/builder/schema.js +79 -121
  138. package/src/tx/index.js +101 -12
  139. package/src/tx/tx-object.js +25 -8
  140. package/src/tx/tx.js +229 -150
  141. package/src/tx/validator.js +134 -202
  142. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +3 -2
  143. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +25 -7
  144. package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
  145. package/src/utils/aepp-wallet-communication/content-script-bridge.js +10 -4
  146. package/src/utils/aepp-wallet-communication/helpers.js +4 -2
  147. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +33 -12
  148. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +9 -5
  149. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +59 -29
  150. package/src/utils/aepp-wallet-communication/schema.js +1 -3
  151. package/src/utils/aepp-wallet-communication/wallet-detector.js +4 -1
  152. package/src/utils/amount-formatter.ts +1 -1
  153. package/src/utils/bignumber.ts +2 -1
  154. package/src/utils/crypto.js +4 -68
  155. package/src/utils/keystore.js +10 -2
  156. package/src/utils/other.ts +1 -1
  157. package/src/utils/semver-satisfies.ts +1 -1
  158. package/src/utils/swagger.js +22 -10
  159. package/src/contract/aci/helpers.js +0 -140
package/src/tx/index.js CHANGED
@@ -72,7 +72,15 @@ const Tx = stampit(required({
72
72
  * @instance
73
73
  * @abstract
74
74
  * @category async
75
- * @rtype ({sender?: String, recipientId: String, amount: Number, fee?: Number, ttl?: Number, nonce?: Number, payload?: String}) => tx: Promise[String]
75
+ * @rtype ({
76
+ * sender?: String,
77
+ * recipientId: String,
78
+ * amount: Number,
79
+ * fee?: Number,
80
+ * ttl?: Number,
81
+ * nonce?: Number,
82
+ * payload?: String
83
+ * }) => tx: Promise[String]
76
84
  * @param {Object} options - The object to extract properties from
77
85
  * @return {String} `spend_tx` transaction
78
86
  */
@@ -83,7 +91,9 @@ const Tx = stampit(required({
83
91
  * @instance
84
92
  * @abstract
85
93
  * @category async
86
- * @rtype ({account?: String, commitment: String, fee?: Number, ttl?: Number, nonce?: Number}) => tx: Promise[String]
94
+ * @rtype ({
95
+ * account?: String, commitment: String, fee?: Number, ttl?: Number, nonce?: Number
96
+ * }) => tx: Promise[String]
87
97
  * @param {Object} options - The object to extract properties from
88
98
  * @return {String} `name_preclaim_tx` transaction
89
99
  */
@@ -94,7 +104,9 @@ const Tx = stampit(required({
94
104
  * @instance
95
105
  * @abstract
96
106
  * @category async
97
- * @rtype ({account?: String, name: String, nameSalt: String, fee?: Number, ttl?: Number, nonce?: Number}) => tx: Promise[String]
107
+ * @rtype ({
108
+ * account?: String, name: String, nameSalt: String, fee?: Number, ttl?: Number, nonce?: Number
109
+ * }) => tx: Promise[String]
98
110
  * @param {Object} options - The object to extract properties from
99
111
  * @return {String} `name_claim_tx` transaction
100
112
  */
@@ -105,7 +117,14 @@ const Tx = stampit(required({
105
117
  * @instance
106
118
  * @abstract
107
119
  * @category async
108
- * @rtype ({account?: String, nameId: String, recipientId: String, fee?: Number, ttl?: Number, nonce?: Number}) => tx: Promise[String]
120
+ * @rtype ({
121
+ * account?: String,
122
+ * nameId: String,
123
+ * recipientId: String,
124
+ * fee?: Number,
125
+ * ttl?: Number,
126
+ * nonce?: Number
127
+ * }) => tx: Promise[String]
109
128
  * @param {Object} options - The object to extract properties from
110
129
  * @return {String} `name_transfer_tx` transaction
111
130
  */
@@ -116,7 +135,16 @@ const Tx = stampit(required({
116
135
  * @instance
117
136
  * @abstract
118
137
  * @category async
119
- * @rtype ({account?: String, nameId: String, pointers: Object, nameTtl: Number, clientTtl: Number, fee?: Number, ttl?: Number, nonce?: Number}) => tx: Promise[String]
138
+ * @rtype ({
139
+ * account?: String,
140
+ * nameId: String,
141
+ * pointers: Object,
142
+ * nameTtl: Number,
143
+ * clientTtl: Number,
144
+ * fee?: Number,
145
+ * ttl?: Number,
146
+ * nonce?: Number
147
+ * }) => tx: Promise[String]
120
148
  * @param {Object} options - The object to extract properties from
121
149
  * @return {String} `name_update_tx` transaction
122
150
  */
@@ -127,7 +155,9 @@ const Tx = stampit(required({
127
155
  * @instance
128
156
  * @abstract
129
157
  * @category async
130
- * @rtype ({account?: String, nameId: String, fee?: Number, ttl?: Number, nonce?: Number}) => tx: Promise[String]
158
+ * @rtype ({
159
+ * account?: String, nameId: String, fee?: Number, ttl?: Number, nonce?: Number
160
+ * }) => tx: Promise[String]
131
161
  * @param {Object} options - The object to extract properties from
132
162
  * @return {String} `name_revoke_tx` transaction
133
163
  */
@@ -138,7 +168,19 @@ const Tx = stampit(required({
138
168
  * @instance
139
169
  * @abstract
140
170
  * @category async
141
- * @rtype ({owner: String, code: String, callData: String, vmVersion: Number, deposit: Number, amount: Number, gas: Number, gasPrice: Number, fee?: Number, ttl?: Number, nonce?: Number}) => tx: Promise[String]
171
+ * @rtype ({
172
+ * owner: String,
173
+ * code: String,
174
+ * callData: String,
175
+ * vmVersion: Number,
176
+ * deposit: Number,
177
+ * amount: Number,
178
+ * gas: Number,
179
+ * gasPrice: Number,
180
+ * fee?: Number,
181
+ * ttl?: Number,
182
+ * nonce?: Number
183
+ * }) => tx: Promise[String]
142
184
  * @param {Object} options - The object to extract properties from
143
185
  * @return {String} `contract_create_tx` transaction
144
186
  */
@@ -149,7 +191,18 @@ const Tx = stampit(required({
149
191
  * @instance
150
192
  * @abstract
151
193
  * @category async
152
- * @rtype ({callerId: String, contract: String, callData: String, vmVersion: Number, amount: Number, gas: Number, gasPrice: Number, fee?: Number, ttl?: Number, nonce?: Number}) => tx: Promise[String]
194
+ * @rtype ({
195
+ * callerId: String,
196
+ * contract: String,
197
+ * callData: String,
198
+ * vmVersion: Number,
199
+ * amount: Number,
200
+ * gas: Number,
201
+ * gasPrice: Number,
202
+ * fee?: Number,
203
+ * ttl?: Number,
204
+ * nonce?: Number
205
+ * }) => tx: Promise[String]
153
206
  * @param {Object} options - The object to extract properties from
154
207
  * @return {String} `contract_call_tx` transaction
155
208
  */
@@ -160,7 +213,17 @@ const Tx = stampit(required({
160
213
  * @instance
161
214
  * @abstract
162
215
  * @category async
163
- * @rtype ({ accountId: String, queryFormat: String, responseFormat: String, queryFee: String|Number, oracleTtl: Object, vmVersion: Number = ORACLE_VM_VERSION, fee?: Number, ttl?: Number, nonce?: Number }) => tx: Promise[String]
216
+ * @rtype ({
217
+ * accountId: String,
218
+ * queryFormat: String,
219
+ * responseFormat: String,
220
+ * queryFee: String|Number,
221
+ * oracleTtl: Object,
222
+ * vmVersion: Number = ORACLE_VM_VERSION,
223
+ * fee?: Number,
224
+ * ttl?: Number,
225
+ * nonce?: Number
226
+ * }) => tx: Promise[String]
164
227
  * @param {Object} options - The object to extract properties from
165
228
  * @return {String} `oracle_register_tx` transaction
166
229
  */
@@ -171,7 +234,14 @@ const Tx = stampit(required({
171
234
  * @instance
172
235
  * @abstract
173
236
  * @category async
174
- * @rtype ({ oracleId: String, callerId: String, oracleTtl: Object, fee?: Number, ttl: Number, nonce?: Number}) => tx: Promise[String]
237
+ * @rtype ({
238
+ * oracleId: String,
239
+ * callerId: String,
240
+ * oracleTtl: Object,
241
+ * fee?: Number,
242
+ * ttl: Number,
243
+ * nonce?: Number
244
+ * }) => tx: Promise[String]
175
245
  * @param {Object} options - The object to extract properties from
176
246
  * @return {String} `oracle_extend_tx` transaction
177
247
  */
@@ -182,7 +252,17 @@ const Tx = stampit(required({
182
252
  * @instance
183
253
  * @abstract
184
254
  * @category async
185
- * @rtype ({ oracleId: String, responseTtl: Object, query: String, queryTtl: Object, queryFee: String|Number, senderId: String, fee?: Number, ttl: Number, nonce?: Number}) => tx: Promise[String]
255
+ * @rtype ({
256
+ * oracleId: String,
257
+ * responseTtl: Object,
258
+ * query: String,
259
+ * queryTtl: Object,
260
+ * queryFee: String|Number,
261
+ * senderId: String,
262
+ * fee?: Number,
263
+ * ttl: Number,
264
+ * nonce?: Number
265
+ * }) => tx: Promise[String]
186
266
  * @param {Object} options - The object to extract properties from
187
267
  * @return {String} `oracle_post_query_tx` transaction
188
268
  */
@@ -193,7 +273,16 @@ const Tx = stampit(required({
193
273
  * @instance
194
274
  * @abstract
195
275
  * @category async
196
- * @rtype ({ oracleId: String, callerId: String, responseTtl: Object, queryId: String, response: String, fee?: Number, ttl?: Number, nonce?: Number}) => tx: Promise[String]
276
+ * @rtype ({
277
+ * oracleId: String,
278
+ * callerId: String,
279
+ * responseTtl: Object,
280
+ * queryId: String,
281
+ * response: String,
282
+ * fee?: Number,
283
+ * ttl?: Number,
284
+ * nonce?: Number
285
+ * }) => tx: Promise[String]
197
286
  * @param {Object} options - The object to extract properties from
198
287
  * @return {String} `oracle_respond_tx` transaction
199
288
  */
@@ -5,7 +5,6 @@
5
5
  * @example import TxObject from '@aeternity/aepp-sdk/es/tx/tx-object'
6
6
  */
7
7
  import stampit from '@stamp/it'
8
- import { assertedType } from '../utils/crypto'
9
8
  import { buildTx, calculateFee, unpackTx } from './builder'
10
9
  import { TX_TYPE } from './builder/schema'
11
10
  import { encode } from './builder/helpers'
@@ -18,13 +17,17 @@ import { isHex } from '../utils/string'
18
17
  * @param {Object} params Transaction params
19
18
  * @param {Object} [options={}] Options
20
19
  * @throws {Error} Arguments validation error's
21
- * @return {{ encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, params: Object, type: String }}
20
+ * @return {{
21
+ * encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, params: Object, type: String
22
+ * }}
22
23
  */
23
24
  const buildTransaction = (type, params, options = {}) => {
24
25
  if (typeof params !== 'object') throw new Error('"params" should be an object')
25
26
  if (typeof type !== 'string' || !Object.values(TX_TYPE).includes(type)) throw new Error(`Unknown transaction type ${type}`)
26
27
  const fee = calculateFee(params.fee, type, { gas: params.gas, params, vsn: params.vsn })
27
- const { rlpEncoded, binary, tx: encodedTx, txObject } = buildTx({ ...params, fee }, type, { vsn: params.vsn, ...options })
28
+ const { rlpEncoded, binary, tx: encodedTx, txObject } = buildTx(
29
+ { ...params, fee }, type, { vsn: params.vsn, ...options }
30
+ )
28
31
  return { rlpEncoded, binary, encodedTx, params: txObject, type }
29
32
  }
30
33
 
@@ -33,12 +36,13 @@ const buildTransaction = (type, params, options = {}) => {
33
36
  * @alias module:@aeternity/aepp-sdk/es/tx/tx-object
34
37
  * @param {Buffer|String} tx RLP encoded binary or base64c(rlpBinary) string
35
38
  * @throws {Error} Arguments validation error's
36
- * @return {{ encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, type: String, params: Object }}
39
+ * @return {{
40
+ * encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, type: String, params: Object
41
+ * }}
37
42
  */
38
43
  const unpackTransaction = (tx) => {
39
44
  if (!tx) throw new Error(`Invalid transaction: ${tx}`)
40
45
  if (typeof tx === 'string') {
41
- if (!assertedType(tx, 'tx', true)) throw new Error('Invalid transaction string. Tx should be `tx` prefixed base58c string')
42
46
  const { txType: type, tx: params, rlpEncoded, binary } = unpackTx(tx)
43
47
  return { encodedTx: tx, type, params, rlpEncoded, binary }
44
48
  }
@@ -57,7 +61,9 @@ const unpackTransaction = (tx) => {
57
61
  * @param {String} type Transaction type
58
62
  * @param {Object} [options={}] Options
59
63
  * @throws {Error} Arguments validation error's
60
- * @return {{encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, type: String, params: Object}}
64
+ * @return {{
65
+ * encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, type: String, params: Object
66
+ * }}
61
67
  */
62
68
  const initTransaction = ({ tx, params, type, options = {} } = {}) => {
63
69
  if (params && type) return buildTransaction(type, params, options)
@@ -124,7 +130,12 @@ export const TxObject = stampit({
124
130
  if (typeof props !== 'object') throw new Error('Props should be an object')
125
131
  this.isSigned = false
126
132
  this.signatures = []
127
- Object.assign(this, buildTransaction(this.type, { ...this.params, ...props, fee: null }, { ...this.options, ...options }))
133
+ Object.assign(
134
+ this,
135
+ buildTransaction(
136
+ this.type, { ...this.params, ...props, fee: null }, { ...this.options, ...options }
137
+ )
138
+ )
128
139
  return this
129
140
  },
130
141
  /**
@@ -145,7 +156,13 @@ export const TxObject = stampit({
145
156
  addSignature (signature) {
146
157
  signature = isHex(signature) ? Buffer.from(signature, 'hex') : signature
147
158
  if (!Buffer.isBuffer(signature) && !(signature instanceof Uint8Array)) throw new Error('Invalid signature, signature must be of type Buffer or Uint8Array')
148
- Object.assign(this, buildTransaction(TX_TYPE.signed, { encodedTx: this.rlpEncoded, signatures: [[...this.signatures, signature]] }))
159
+ Object.assign(
160
+ this,
161
+ buildTransaction(
162
+ TX_TYPE.signed,
163
+ { encodedTx: this.rlpEncoded, signatures: [[...this.signatures, signature]] }
164
+ )
165
+ )
149
166
 
150
167
  const { signatures, encodedTx: { txType, tx } } = this.params
151
168
  this.signatures = signatures