@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
@@ -1,36 +1,9 @@
1
- import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
2
- import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
3
- import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
4
- import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
5
- import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
6
- import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
7
- import _typeof from "@babel/runtime-corejs3/helpers/typeof";
8
- import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
9
- import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
10
- import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
11
-
12
- function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) { symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
13
-
14
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context10; _forEachInstanceProperty(_context10 = ownKeys(Object(source), true)).call(_context10, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context11; _forEachInstanceProperty(_context11 = ownKeys(Object(source))).call(_context11, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
15
-
16
- import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
17
- import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
18
- import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
19
- import _Array$isArray from "@babel/runtime-corejs3/core-js-stable/array/is-array";
20
- import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
21
- import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
22
- import _Object$entries from "@babel/runtime-corejs3/core-js-stable/object/entries";
23
- import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
24
- import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
25
- import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
26
- import _JSON$stringify from "@babel/runtime-corejs3/core-js-stable/json/stringify";
27
- import _indexOfInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/index-of";
28
1
  import BigNumber from 'bignumber.js';
29
2
  import { decode as rlpDecode, encode as rlpEncode } from 'rlp';
30
3
  import { AE_AMOUNT_FORMATS, formatAmount } from '../../utils/amount-formatter';
31
- import { assertedType } from '../../utils/crypto';
4
+ import { hash } from '../../utils/crypto';
32
5
  import { DEFAULT_FEE, FIELD_TYPES, OBJECT_ID_TX_TYPE, PREFIX_ID_TAG, TX_DESERIALIZATION_SCHEMA, TX_FEE_BASE_GAS, TX_FEE_OTHER_GAS, TX_SERIALIZATION_SCHEMA, TX_TYPE, VALIDATION_MESSAGE, VSN } from './schema';
33
- import { readInt, readId, readPointers, writeId, writeInt, buildPointers, encode, decode, buildHash } from './helpers';
6
+ import { readInt, readId, readPointers, writeId, writeInt, buildPointers, encode, decode } from './helpers';
34
7
  import { toBytes } from '../../utils/bytes';
35
8
  import MPTree from '../../utils/mptree';
36
9
  /**
@@ -40,7 +13,7 @@ import MPTree from '../../utils/mptree';
40
13
  * @example import { TxBuilder } from '@aeternity/aepp-sdk'
41
14
  */
42
15
 
43
- var ORACLE_TTL_TYPES = {
16
+ const ORACLE_TTL_TYPES = {
44
17
  delta: 'delta',
45
18
  block: 'block'
46
19
  }; // SERIALIZE AND DESERIALIZE PART
@@ -51,10 +24,7 @@ function deserializeField(value, type, prefix) {
51
24
  switch (type) {
52
25
  case FIELD_TYPES.ctVersion:
53
26
  {
54
- var _value = _slicedToArray(value, 3),
55
- vm = _value[0],
56
- abi = _value[2];
57
-
27
+ const [vm,, abi] = value;
58
28
  return {
59
29
  vmVersion: readInt(Buffer.from([vm])),
60
30
  abiVersion: readInt(Buffer.from([abi]))
@@ -64,14 +34,14 @@ function deserializeField(value, type, prefix) {
64
34
  case FIELD_TYPES.amount:
65
35
  return readInt(value);
66
36
 
67
- case FIELD_TYPES["int"]:
37
+ case FIELD_TYPES.int:
68
38
  return readInt(value);
69
39
 
70
40
  case FIELD_TYPES.id:
71
41
  return readId(value);
72
42
 
73
43
  case FIELD_TYPES.ids:
74
- return _mapInstanceProperty(value).call(value, readId);
44
+ return value.map(readId);
75
45
 
76
46
  case FIELD_TYPES.bool:
77
47
  return value[0] === 1;
@@ -95,9 +65,7 @@ function deserializeField(value, type, prefix) {
95
65
  return unpackTx(value, true);
96
66
 
97
67
  case FIELD_TYPES.rlpBinaries:
98
- return _mapInstanceProperty(value).call(value, function (v) {
99
- return unpackTx(v, true);
100
- });
68
+ return value.map(v => unpackTx(v, true));
101
69
 
102
70
  case FIELD_TYPES.rawBinary:
103
71
  return value;
@@ -106,18 +74,14 @@ function deserializeField(value, type, prefix) {
106
74
  return value.toString('hex');
107
75
 
108
76
  case FIELD_TYPES.offChainUpdates:
109
- return _mapInstanceProperty(value).call(value, function (v) {
110
- return unpackTx(v, true);
111
- });
77
+ return value.map(v => unpackTx(v, true));
112
78
 
113
79
  case FIELD_TYPES.callStack:
114
80
  // TODO: fix this
115
81
  return [readInt(value)];
116
82
 
117
83
  case FIELD_TYPES.mptrees:
118
- return _mapInstanceProperty(value).call(value, function (t) {
119
- return new MPTree(t);
120
- });
84
+ return value.map(t => new MPTree(t));
121
85
 
122
86
  case FIELD_TYPES.callReturnType:
123
87
  switch (readInt(value)) {
@@ -135,18 +99,15 @@ function deserializeField(value, type, prefix) {
135
99
  }
136
100
 
137
101
  case FIELD_TYPES.sophiaCodeTypeInfo:
138
- return _reduceInstanceProperty(value).call(value, function (acc, _ref) {
139
- var _ref2 = _slicedToArray(_ref, 4),
140
- funHash = _ref2[0],
141
- fnName = _ref2[1],
142
- argType = _ref2[2],
143
- outType = _ref2[3];
144
-
145
- return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, fnName.toString(), {
146
- funHash: funHash,
147
- argType: argType,
148
- outType: outType
149
- }));
102
+ return value.reduce((acc, _ref) => {
103
+ let [funHash, fnName, argType, outType] = _ref;
104
+ return { ...acc,
105
+ [fnName.toString()]: {
106
+ funHash,
107
+ argType,
108
+ outType
109
+ }
110
+ };
150
111
  }, {});
151
112
 
152
113
  default:
@@ -155,18 +116,16 @@ function deserializeField(value, type, prefix) {
155
116
  }
156
117
 
157
118
  function serializeField(value, type, prefix) {
158
- var _context;
159
-
160
119
  switch (type) {
161
120
  case FIELD_TYPES.amount:
162
- case FIELD_TYPES["int"]:
121
+ case FIELD_TYPES.int:
163
122
  return writeInt(value);
164
123
 
165
124
  case FIELD_TYPES.id:
166
125
  return writeId(value);
167
126
 
168
127
  case FIELD_TYPES.ids:
169
- return _mapInstanceProperty(value).call(value, writeId);
128
+ return value.map(writeId);
170
129
 
171
130
  case FIELD_TYPES.bool:
172
131
  return Buffer.from([value ? 1 : 0]);
@@ -181,7 +140,7 @@ function serializeField(value, type, prefix) {
181
140
  return Buffer.from(value, 'hex');
182
141
 
183
142
  case FIELD_TYPES.signatures:
184
- return _mapInstanceProperty(value).call(value, Buffer.from);
143
+ return value.map(Buffer.from);
185
144
 
186
145
  case FIELD_TYPES.payload:
187
146
  return typeof value === 'string' && value.split('_')[0] === 'ba' ? decode(value, 'ba') : toBytes(value);
@@ -192,13 +151,14 @@ function serializeField(value, type, prefix) {
192
151
  case FIELD_TYPES.pointers:
193
152
  return buildPointers(value);
194
153
 
154
+ case FIELD_TYPES.rlpBinary:
155
+ return value.rlpEncoded ?? value;
156
+
195
157
  case FIELD_TYPES.mptrees:
196
- return _mapInstanceProperty(value).call(value, function (t) {
197
- return t.serialize();
198
- });
158
+ return value.map(t => t.serialize());
199
159
 
200
160
  case FIELD_TYPES.ctVersion:
201
- return Buffer.from(_concatInstanceProperty(_context = []).call(_context, _toConsumableArray(toBytes(value.vmVersion)), [0], _toConsumableArray(toBytes(value.abiVersion))));
161
+ return Buffer.from([...toBytes(value.vmVersion), 0, ...toBytes(value.abiVersion)]);
202
162
 
203
163
  case FIELD_TYPES.callReturnType:
204
164
  switch (value) {
@@ -221,58 +181,51 @@ function serializeField(value, type, prefix) {
221
181
  }
222
182
 
223
183
  function validateField(value, key, type, prefix) {
224
- var assert = function assert(valid, params) {
225
- return valid ? {} : _defineProperty({}, key, VALIDATION_MESSAGE[type](params));
184
+ const assert = (valid, params) => valid ? {} : {
185
+ [key]: VALIDATION_MESSAGE[type](params)
226
186
  }; // All fields are required
227
187
 
228
188
 
229
- if (value === undefined || value === null) return _defineProperty({}, key, 'Field is required'); // Validate type of value
189
+ if (value === undefined || value === null) return {
190
+ [key]: 'Field is required'
191
+ }; // Validate type of value
230
192
 
231
193
  switch (type) {
232
194
  case FIELD_TYPES.amount:
233
- case FIELD_TYPES["int"]:
195
+ case FIELD_TYPES.int:
234
196
  {
235
- var isMinusValue = (!isNaN(value) || BigNumber.isBigNumber(value)) && BigNumber(value).lt(0);
197
+ const isMinusValue = (!isNaN(value) || BigNumber.isBigNumber(value)) && BigNumber(value).lt(0);
236
198
  return assert((!isNaN(value) || BigNumber.isBigNumber(value)) && BigNumber(value).gte(0), {
237
- value: value,
238
- isMinusValue: isMinusValue
199
+ value,
200
+ isMinusValue
239
201
  });
240
202
  }
241
203
 
242
204
  case FIELD_TYPES.id:
243
- if (_Array$isArray(prefix)) {
244
- var p = _findInstanceProperty(prefix).call(prefix, function (p) {
245
- return p === value.split('_')[0];
246
- });
247
-
205
+ {
206
+ const prefixes = Array.isArray(prefix) ? prefix : [prefix];
207
+ const p = prefixes.find(p => p === value.split('_')[0]);
248
208
  return assert(p && PREFIX_ID_TAG[value.split('_')[0]], {
249
- value: value,
250
- prefix: prefix
209
+ value,
210
+ prefix
251
211
  });
252
212
  }
253
213
 
254
- return assert(assertedType(value, prefix) && PREFIX_ID_TAG[value.split('_')[0]] && value.split('_')[0] === prefix, {
255
- value: value,
256
- prefix: prefix
257
- });
258
-
259
214
  case FIELD_TYPES.binary:
260
215
  return assert(value.split('_')[0] === prefix, {
261
- prefix: prefix,
262
- value: value
216
+ prefix,
217
+ value
263
218
  });
264
219
 
265
220
  case FIELD_TYPES.string:
266
221
  return assert(true);
267
222
 
268
223
  case FIELD_TYPES.ctVersion:
269
- return assert(_typeof(value) === 'object' && Object.prototype.hasOwnProperty.call(value, 'abiVersion') && Object.prototype.hasOwnProperty.call(value, 'vmVersion'));
224
+ return assert(typeof value === 'object' && Object.prototype.hasOwnProperty.call(value, 'abiVersion') && Object.prototype.hasOwnProperty.call(value, 'vmVersion'));
270
225
 
271
226
  case FIELD_TYPES.pointers:
272
- return assert(_Array$isArray(value) && !_findInstanceProperty(value).call(value, function (e) {
273
- return e !== Object(e);
274
- }), {
275
- value: value
227
+ return assert(Array.isArray(value) && !value.find(e => e !== Object(e)), {
228
+ value
276
229
  });
277
230
 
278
231
  default:
@@ -281,45 +234,31 @@ function validateField(value, key, type, prefix) {
281
234
  }
282
235
 
283
236
  function transformParams(params, schema) {
284
- var _context2, _context3;
285
-
286
- var _ref5 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
287
- denomination = _ref5.denomination;
288
-
289
- params = _reduceInstanceProperty(_context2 = _filterInstanceProperty(schema).call(schema, function (_ref6) {
290
- var _ref7 = _slicedToArray(_ref6, 2),
291
- _ = _ref7[0],
292
- t = _ref7[1];
293
-
237
+ let {
238
+ denomination
239
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
240
+ params = schema.filter(_ref2 => {
241
+ let [_, t] = _ref2;
294
242
  return t === FIELD_TYPES.amount;
295
- })).call(_context2, function (acc, _ref8) {
296
- var _ref9 = _slicedToArray(_ref8, 1),
297
- key = _ref9[0];
298
-
299
- return _objectSpread(_objectSpread({}, params), {}, _defineProperty({}, key, formatAmount(params[key], {
300
- denomination: denomination
301
- })));
243
+ }).reduce((acc, _ref3) => {
244
+ let [key] = _ref3;
245
+ return { ...params,
246
+ [key]: formatAmount(params[key], {
247
+ denomination
248
+ })
249
+ };
302
250
  }, params);
303
-
304
- var schemaKeys = _mapInstanceProperty(schema).call(schema, function (_ref10) {
305
- var _ref11 = _slicedToArray(_ref10, 1),
306
- k = _ref11[0];
307
-
251
+ const schemaKeys = schema.map(_ref4 => {
252
+ let [k] = _ref4;
308
253
  return k;
309
254
  });
255
+ return Object.entries(params).reduce((acc, _ref5) => {
256
+ let [key, value] = _ref5;
257
+ if (schemaKeys.includes(key)) acc[key] = value;
310
258
 
311
- return _reduceInstanceProperty(_context3 = _Object$entries(params)).call(_context3, function (acc, _ref12) {
312
- var _context4;
313
-
314
- var _ref13 = _slicedToArray(_ref12, 2),
315
- key = _ref13[0],
316
- value = _ref13[1];
317
-
318
- if (_includesInstanceProperty(schemaKeys).call(schemaKeys, key)) acc[key] = value;
319
-
320
- if (_includesInstanceProperty(_context4 = ['oracleTtl', 'queryTtl', 'responseTtl']).call(_context4, key)) {
321
- acc["".concat(key, "Type")] = value.type === ORACLE_TTL_TYPES.delta ? 0 : 1;
322
- acc["".concat(key, "Value")] = value.value;
259
+ if (['oracleTtl', 'queryTtl', 'responseTtl'].includes(key)) {
260
+ acc[`${key}Type`] = value.type === ORACLE_TTL_TYPES.delta ? 0 : 1;
261
+ acc[`${key}Value`] = value.value;
323
262
  }
324
263
 
325
264
  return acc;
@@ -328,12 +267,15 @@ function transformParams(params, schema) {
328
267
 
329
268
 
330
269
  function getOracleRelativeTtl(params, txType) {
331
- var _TX_TYPE$oracleRegist;
332
-
333
- var ttlKey = (_TX_TYPE$oracleRegist = {}, _defineProperty(_TX_TYPE$oracleRegist, TX_TYPE.oracleRegister, 'oracleTtl'), _defineProperty(_TX_TYPE$oracleRegist, TX_TYPE.oracleExtend, 'oracleTtl'), _defineProperty(_TX_TYPE$oracleRegist, TX_TYPE.oracleQuery, 'queryTtl'), _defineProperty(_TX_TYPE$oracleRegist, TX_TYPE.oracleResponse, 'responseTtl'), _TX_TYPE$oracleRegist)[txType];
334
-
335
- if (params[ttlKey] || params["".concat(ttlKey, "Value")]) {
336
- return params["".concat(ttlKey, "Value")] || params[ttlKey].value;
270
+ const ttlKey = {
271
+ [TX_TYPE.oracleRegister]: 'oracleTtl',
272
+ [TX_TYPE.oracleExtend]: 'oracleTtl',
273
+ [TX_TYPE.oracleQuery]: 'queryTtl',
274
+ [TX_TYPE.oracleResponse]: 'responseTtl'
275
+ }[txType];
276
+
277
+ if (params[ttlKey] || params[`${ttlKey}Value`]) {
278
+ return params[`${ttlKey}Value`] || params[ttlKey].value;
337
279
  }
338
280
 
339
281
  return 1;
@@ -352,32 +294,33 @@ function getOracleRelativeTtl(params, txType) {
352
294
  */
353
295
 
354
296
 
355
- export function calculateMinFee(txType, _ref14) {
356
- var _ref14$gas = _ref14.gas,
357
- gas = _ref14$gas === void 0 ? 0 : _ref14$gas,
358
- params = _ref14.params,
359
- vsn = _ref14.vsn;
360
- var multiplier = BigNumber(1e9); // 10^9 GAS_PRICE
297
+ export function calculateMinFee(txType, _ref6) {
298
+ let {
299
+ gas = 0,
300
+ params,
301
+ vsn
302
+ } = _ref6;
303
+ const multiplier = BigNumber(1e9); // 10^9 GAS_PRICE
361
304
 
362
305
  if (!params) return BigNumber(DEFAULT_FEE).times(multiplier).toString(10);
363
- var actualFee = buildFee(txType, {
364
- params: _objectSpread(_objectSpread({}, params), {}, {
306
+ let actualFee = buildFee(txType, {
307
+ params: { ...params,
365
308
  fee: 0
366
- }),
367
- multiplier: multiplier,
368
- gas: gas,
369
- vsn: vsn
309
+ },
310
+ multiplier,
311
+ gas,
312
+ vsn
370
313
  });
371
- var expected = BigNumber(0);
314
+ let expected = BigNumber(0);
372
315
 
373
316
  while (!actualFee.eq(expected)) {
374
317
  actualFee = buildFee(txType, {
375
- params: _objectSpread(_objectSpread({}, params), {}, {
318
+ params: { ...params,
376
319
  fee: actualFee
377
- }),
378
- multiplier: multiplier,
379
- gas: gas,
380
- vsn: vsn
320
+ },
321
+ multiplier,
322
+ gas,
323
+ vsn
381
324
  });
382
325
  expected = actualFee;
383
326
  }
@@ -394,22 +337,23 @@ export function calculateMinFee(txType, _ref14) {
394
337
  * @return {BigNumber}
395
338
  */
396
339
 
397
- function buildFee(txType, _ref15) {
398
- var params = _ref15.params,
399
- _ref15$gas = _ref15.gas,
400
- gas = _ref15$gas === void 0 ? 0 : _ref15$gas,
401
- multiplier = _ref15.multiplier,
402
- vsn = _ref15.vsn;
403
-
404
- var _buildTx = buildTx(_objectSpread({}, params), txType, {
405
- vsn: vsn
406
- }),
407
- txWithOutFee = _buildTx.rlpEncoded;
408
-
409
- var txSize = txWithOutFee.length;
410
- return TX_FEE_BASE_GAS(txType).plus(TX_FEE_OTHER_GAS(txType)({
411
- txSize: txSize,
412
- relativeTtl: getOracleRelativeTtl(params, txType)
340
+ function buildFee(txType, _ref7) {
341
+ let {
342
+ params,
343
+ gas = 0,
344
+ multiplier,
345
+ vsn
346
+ } = _ref7;
347
+ const {
348
+ rlpEncoded: txWithOutFee
349
+ } = buildTx({ ...params
350
+ }, txType, {
351
+ vsn
352
+ });
353
+ const txSize = txWithOutFee.length;
354
+ return TX_FEE_BASE_GAS(txType).plus(TX_FEE_OTHER_GAS(txType, txSize, {
355
+ relativeTtl: getOracleRelativeTtl(params, txType),
356
+ innerTxSize: [TX_TYPE.gaMeta, TX_TYPE.payingFor].includes(txType) ? params.tx.tx.encodedTx.rlpEncoded.length : 0
413
357
  })).times(multiplier);
414
358
  }
415
359
  /**
@@ -428,22 +372,19 @@ function buildFee(txType, _ref15) {
428
372
 
429
373
 
430
374
  export function calculateFee() {
431
- var fee = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
432
- var txType = arguments.length > 1 ? arguments[1] : undefined;
433
-
434
- var _ref16 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
435
- _ref16$gas = _ref16.gas,
436
- gas = _ref16$gas === void 0 ? 0 : _ref16$gas,
437
- params = _ref16.params,
438
- _ref16$showWarning = _ref16.showWarning,
439
- showWarning = _ref16$showWarning === void 0 ? true : _ref16$showWarning,
440
- vsn = _ref16.vsn;
441
-
442
- if (!params && showWarning) console.warn("Can't build transaction fee, we will use DEFAULT_FEE(".concat(DEFAULT_FEE, ")"));
375
+ let fee = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
376
+ let txType = arguments.length > 1 ? arguments[1] : undefined;
377
+ let {
378
+ gas = 0,
379
+ params,
380
+ showWarning = true,
381
+ vsn
382
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
383
+ if (!params && showWarning) console.warn(`Can't build transaction fee, we will use DEFAULT_FEE(${DEFAULT_FEE})`);
443
384
  return fee || calculateMinFee(txType, {
444
- params: params,
445
- gas: gas,
446
- vsn: vsn
385
+ params,
386
+ gas,
387
+ vsn
447
388
  });
448
389
  }
449
390
  /**
@@ -456,23 +397,16 @@ export function calculateFee() {
456
397
  * @return {Object} Object with validation errors
457
398
  */
458
399
 
459
- export function validateParams(params, schema, _ref17) {
460
- var _context5;
461
-
462
- var _ref17$excludeKeys = _ref17.excludeKeys,
463
- excludeKeys = _ref17$excludeKeys === void 0 ? [] : _ref17$excludeKeys;
464
- return _reduceInstanceProperty(_context5 = _filterInstanceProperty(schema).call(schema, function (_ref18) {
465
- var _ref19 = _slicedToArray(_ref18, 1),
466
- key = _ref19[0];
467
-
468
- return !_includesInstanceProperty(excludeKeys).call(excludeKeys, key) && key !== 'payload';
469
- })).call(_context5, function (acc, _ref20) {
470
- var _ref21 = _slicedToArray(_ref20, 3),
471
- key = _ref21[0],
472
- type = _ref21[1],
473
- prefix = _ref21[2];
474
-
475
- return _Object$assign(acc, validateField(params[key], key, type, prefix));
400
+ export function validateParams(params, schema, _ref8) {
401
+ let {
402
+ excludeKeys = []
403
+ } = _ref8;
404
+ return schema.filter(_ref9 => {
405
+ let [key] = _ref9;
406
+ return !excludeKeys.includes(key) && key !== 'payload';
407
+ }).reduce((acc, _ref10) => {
408
+ let [key, type, prefix] = _ref10;
409
+ return Object.assign(acc, validateField(params[key], key, type, prefix));
476
410
  }, {});
477
411
  }
478
412
  /**
@@ -482,45 +416,36 @@ export function validateParams(params, schema, _ref17) {
482
416
  * @param {Object} params Object with tx params
483
417
  * @param {Array} schema Transaction schema
484
418
  * @param {Object} [options={}] options
485
- * @param {Array} [options.excludeKeys=[]] excludeKeys Array of keys to exclude for validation and build
486
- * @param {String} [options.denomination='aettos'] denomination Denomination of amounts (default: aettos)
419
+ * @param {String[]} [options.excludeKeys=[]] Array of keys to exclude for validation and build
420
+ * @param {String} [options.denomination='aettos'] Denomination of amounts
487
421
  * @throws {Error} Validation error
488
422
  * @return {Array} Array with binary fields of transaction
489
423
  */
490
424
 
491
425
  export function buildRawTx(params, schema) {
492
- var _ref22 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
493
- _ref22$excludeKeys = _ref22.excludeKeys,
494
- excludeKeys = _ref22$excludeKeys === void 0 ? [] : _ref22$excludeKeys,
495
- _ref22$denomination = _ref22.denomination,
496
- denomination = _ref22$denomination === void 0 ? AE_AMOUNT_FORMATS.AETTOS : _ref22$denomination;
497
-
498
- var filteredSchema = _filterInstanceProperty(schema).call(schema, function (_ref23) {
499
- var _ref24 = _slicedToArray(_ref23, 1),
500
- key = _ref24[0];
501
-
502
- return !_includesInstanceProperty(excludeKeys).call(excludeKeys, key);
426
+ let {
427
+ excludeKeys = [],
428
+ denomination = AE_AMOUNT_FORMATS.AETTOS
429
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
430
+ const filteredSchema = schema.filter(_ref11 => {
431
+ let [key] = _ref11;
432
+ return !excludeKeys.includes(key);
503
433
  }); // Transform `amount` type fields to `aettos`
504
434
 
505
-
506
435
  params = transformParams(params, filteredSchema, {
507
- denomination: denomination
436
+ denomination
508
437
  }); // Validation
509
438
 
510
- var valid = validateParams(params, schema, {
511
- excludeKeys: excludeKeys
439
+ const valid = validateParams(params, schema, {
440
+ excludeKeys
512
441
  });
513
442
 
514
- if (_Object$keys(valid).length) {
515
- throw new Error('Transaction build error. ' + _JSON$stringify(valid));
443
+ if (Object.keys(valid).length) {
444
+ throw new Error('Transaction build error. ' + JSON.stringify(valid));
516
445
  }
517
446
 
518
- return _mapInstanceProperty(filteredSchema).call(filteredSchema, function (_ref25) {
519
- var _ref26 = _slicedToArray(_ref25, 3),
520
- key = _ref26[0],
521
- fieldType = _ref26[1],
522
- prefix = _ref26[2];
523
-
447
+ return filteredSchema.map(_ref12 => {
448
+ let [key, fieldType, prefix] = _ref12;
524
449
  return serializeField(params[key], fieldType, prefix);
525
450
  });
526
451
  }
@@ -534,13 +459,11 @@ export function buildRawTx(params, schema) {
534
459
  */
535
460
 
536
461
  export function unpackRawTx(binary, schema) {
537
- return _reduceInstanceProperty(schema).call(schema, function (acc, _ref27, index) {
538
- var _ref28 = _slicedToArray(_ref27, 3),
539
- key = _ref28[0],
540
- fieldType = _ref28[1],
541
- prefix = _ref28[2];
542
-
543
- return _Object$assign(acc, _defineProperty({}, key, deserializeField(binary[index], fieldType, prefix)));
462
+ return schema.reduce((acc, _ref13, index) => {
463
+ let [key, fieldType, prefix] = _ref13;
464
+ return Object.assign(acc, {
465
+ [key]: deserializeField(binary[index], fieldType, prefix)
466
+ });
544
467
  }, {});
545
468
  }
546
469
  /**
@@ -551,24 +474,22 @@ export function unpackRawTx(binary, schema) {
551
474
  * @return {Object} Schema
552
475
  */
553
476
 
554
- var getSchema = function getSchema(_ref29) {
555
- var vsn = _ref29.vsn,
556
- objId = _ref29.objId,
557
- type = _ref29.type;
558
- var isDeserialize = !!objId;
559
- var firstKey = isDeserialize ? objId : type;
560
- var schema = isDeserialize ? TX_DESERIALIZATION_SCHEMA : TX_SERIALIZATION_SCHEMA;
477
+ const getSchema = _ref14 => {
478
+ let {
479
+ vsn,
480
+ objId,
481
+ type
482
+ } = _ref14;
483
+ const isDeserialize = !!objId;
484
+ const firstKey = isDeserialize ? objId : type;
485
+ const schema = isDeserialize ? TX_DESERIALIZATION_SCHEMA : TX_SERIALIZATION_SCHEMA;
561
486
 
562
487
  if (!schema[firstKey]) {
563
- var _context6;
564
-
565
- throw new Error(_concatInstanceProperty(_context6 = "Transaction ".concat(isDeserialize ? 'deserialization' : 'serialization', " not implemented for ")).call(_context6, isDeserialize ? 'tag ' + objId : type));
488
+ throw new Error(`Transaction ${isDeserialize ? 'deserialization' : 'serialization'} not implemented for ${isDeserialize ? 'tag ' + objId : type}`);
566
489
  }
567
490
 
568
491
  if (!schema[firstKey][vsn]) {
569
- var _context7, _context8;
570
-
571
- throw new Error(_concatInstanceProperty(_context7 = _concatInstanceProperty(_context8 = "Transaction ".concat(isDeserialize ? 'deserialization' : 'serialization', " not implemented for ")).call(_context8, isDeserialize ? 'tag ' + objId : type, " version ")).call(_context7, vsn));
492
+ throw new Error(`Transaction ${isDeserialize ? 'deserialization' : 'serialization'} not implemented for ${isDeserialize ? 'tag ' + objId : type} version ${vsn}`);
572
493
  }
573
494
 
574
495
  return schema[firstKey][vsn];
@@ -580,50 +501,40 @@ var getSchema = function getSchema(_ref29) {
580
501
  * @param {Object} params Object with tx params
581
502
  * @param {String} type Transaction type
582
503
  * @param {Object} [options={}] options
583
- * @param {Object} [options.excludeKeys] excludeKeys Array of keys to exclude for validation and build
504
+ * @param {String[]} [options.excludeKeys] Array of keys to exclude for validation and build
584
505
  * @param {String} [options.prefix] Prefix of transaction
585
506
  * @throws {Error} Validation error
586
- * @return {Object} { tx, rlpEncoded, binary } Object with tx -> Base64Check transaction hash with 'tx_' prefix, rlp encoded transaction and binary transaction
507
+ * @returns {Object} object
508
+ * @returns {String} object.tx Base64Check transaction hash with 'tx_' prefix
509
+ * @returns {Buffer} object.rlpEncoded rlp encoded transaction
510
+ * @returns {Array<Buffer>} object.binary binary transaction
587
511
  */
588
512
 
589
513
 
590
514
  export function buildTx(params, type) {
591
- var _context9;
592
-
593
- var _ref30 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
594
- _ref30$excludeKeys = _ref30.excludeKeys,
595
- excludeKeys = _ref30$excludeKeys === void 0 ? [] : _ref30$excludeKeys,
596
- _ref30$prefix = _ref30.prefix,
597
- prefix = _ref30$prefix === void 0 ? 'tx' : _ref30$prefix,
598
- _ref30$vsn = _ref30.vsn,
599
- vsn = _ref30$vsn === void 0 ? VSN : _ref30$vsn,
600
- _ref30$denomination = _ref30.denomination,
601
- denomination = _ref30$denomination === void 0 ? AE_AMOUNT_FORMATS.AETTOS : _ref30$denomination;
602
-
603
- var _getSchema = getSchema({
604
- type: type,
605
- vsn: vsn
606
- }),
607
- _getSchema2 = _slicedToArray(_getSchema, 2),
608
- schema = _getSchema2[0],
609
- tag = _getSchema2[1];
610
-
611
- var binary = _filterInstanceProperty(_context9 = buildRawTx(_objectSpread(_objectSpread({}, params), {}, {
515
+ let {
516
+ excludeKeys = [],
517
+ prefix = 'tx',
518
+ vsn = VSN,
519
+ denomination = AE_AMOUNT_FORMATS.AETTOS
520
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
521
+ const [schema, tag] = getSchema({
522
+ type,
523
+ vsn
524
+ });
525
+ const binary = buildRawTx({ ...params,
612
526
  VSN: vsn,
613
- tag: tag
614
- }), schema, {
615
- excludeKeys: excludeKeys,
527
+ tag
528
+ }, schema, {
529
+ excludeKeys,
616
530
  denomination: params.denomination || denomination
617
- })).call(_context9, function (e) {
618
- return e !== undefined;
619
- });
620
-
621
- var rlpEncoded = rlpEncode(binary);
622
- var tx = encode(rlpEncoded, prefix);
531
+ }).filter(e => e !== undefined);
532
+ const rlpEncoded = rlpEncode(binary);
533
+ const tx = encode(rlpEncoded, prefix);
623
534
  return {
624
- tx: tx,
625
- rlpEncoded: rlpEncoded,
626
- binary: binary,
535
+ tx,
536
+ rlpEncoded,
537
+ binary,
627
538
  txObject: unpackRawTx(binary, schema)
628
539
  };
629
540
  }
@@ -631,32 +542,32 @@ export function buildTx(params, type) {
631
542
  * Unpack transaction hash
632
543
  * @function
633
544
  * @alias module:@aeternity/aepp-sdk/es/tx/builder
634
- * @param {String|Buffer} encodedTx String or RLP encoded transaction array (if fromRlpBinary flag is true)
545
+ * @param {String|Buffer} encodedTx String or RLP encoded transaction array
546
+ * (if fromRlpBinary flag is true)
635
547
  * @param {Boolean} fromRlpBinary Unpack from RLP encoded transaction (default: false)
636
548
  * @param {String} prefix - Prefix of data
637
- * @return {Object} { tx, rlpEncoded, binary } Object with tx -> Object with transaction param's, rlp encoded transaction and binary transaction
549
+ * @returns {Object} object
550
+ * @returns {Object} object.tx Object with transaction param's
551
+ * @returns {Buffer} object.rlpEncoded rlp encoded transaction
552
+ * @returns {Array<Buffer>} object.binary binary transaction
638
553
  */
639
554
 
640
555
  export function unpackTx(encodedTx) {
641
- var fromRlpBinary = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
642
- var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'tx';
643
- var rlpEncoded = fromRlpBinary ? encodedTx : decode(encodedTx, prefix);
644
- var binary = rlpDecode(rlpEncoded);
645
- var objId = readInt(binary[0]);
646
- var vsn = readInt(binary[1]);
647
-
648
- var _getSchema3 = getSchema({
649
- objId: objId,
650
- vsn: vsn
651
- }),
652
- _getSchema4 = _slicedToArray(_getSchema3, 1),
653
- schema = _getSchema4[0];
654
-
556
+ let fromRlpBinary = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
557
+ let prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'tx';
558
+ const rlpEncoded = fromRlpBinary ? encodedTx : decode(encodedTx, prefix);
559
+ const binary = rlpDecode(rlpEncoded);
560
+ const objId = readInt(binary[0]);
561
+ const vsn = readInt(binary[1]);
562
+ const [schema] = getSchema({
563
+ objId,
564
+ vsn
565
+ });
655
566
  return {
656
567
  txType: OBJECT_ID_TX_TYPE[objId],
657
568
  tx: unpackRawTx(binary, schema),
658
- rlpEncoded: rlpEncoded,
659
- binary: binary
569
+ rlpEncoded,
570
+ binary
660
571
  };
661
572
  }
662
573
  /**
@@ -664,23 +575,21 @@ export function unpackTx(encodedTx) {
664
575
  * @function
665
576
  * @alias module:@aeternity/aepp-sdk/es/tx/builder
666
577
  * @param {String | Buffer} rawTx base64 or rlp encoded transaction
667
- * @param {Object} options
668
- * @param {Boolean} options.raw
669
578
  * @return {String} Transaction hash
670
579
  */
671
580
 
672
- export function buildTxHash(rawTx, options) {
673
- if (typeof rawTx === 'string' && _indexOfInstanceProperty(rawTx).call(rawTx, 'tx_') !== -1) return buildHash('th', unpackTx(rawTx).rlpEncoded, options);
674
- return buildHash('th', rawTx, options);
581
+ export function buildTxHash(rawTx) {
582
+ const data = typeof rawTx === 'string' && rawTx.startsWith('tx_') ? decode(rawTx, 'tx') : rawTx;
583
+ return encode(hash(data), 'th');
675
584
  }
676
585
  export default {
677
- calculateMinFee: calculateMinFee,
678
- calculateFee: calculateFee,
679
- unpackTx: unpackTx,
680
- unpackRawTx: unpackRawTx,
681
- buildTx: buildTx,
682
- buildRawTx: buildRawTx,
683
- validateParams: validateParams,
684
- buildTxHash: buildTxHash
586
+ calculateMinFee,
587
+ calculateFee,
588
+ unpackTx,
589
+ unpackRawTx,
590
+ buildTx,
591
+ buildRawTx,
592
+ validateParams,
593
+ buildTxHash
685
594
  };
686
595
  //# sourceMappingURL=index.js.map