@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
@@ -1,24 +1,3 @@
1
- import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
2
- import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
3
- import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
4
- import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
5
- import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
6
- import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
7
- import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
8
- import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
9
- import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
10
- import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
11
- import _typeof from "@babel/runtime-corejs3/helpers/typeof";
12
-
13
- 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; }
14
-
15
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty(_context3 = ownKeys(Object(source), true)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context4; _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
16
-
17
- import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
18
- import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values";
19
- import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
20
- import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
21
-
22
1
  /**
23
2
  * TxObject module
24
3
  * @module @aeternity/aepp-sdk/es/tx/tx-object
@@ -40,34 +19,32 @@ import { isHex } from '../utils/string';
40
19
  * @return {{ encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, params: Object, type: String }}
41
20
  */
42
21
 
43
- var buildTransaction = function buildTransaction(type, params) {
44
- var _context;
45
-
46
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
47
- if (_typeof(params) !== 'object') throw new Error('"params" should be an object');
48
- if (typeof type !== 'string' || !_includesInstanceProperty(_context = _Object$values(TX_TYPE)).call(_context, type)) throw new Error("Unknown transaction type ".concat(type));
49
- var fee = calculateFee(params.fee, type, {
22
+ const buildTransaction = function (type, params) {
23
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
24
+ if (typeof params !== 'object') throw new Error('"params" should be an object');
25
+ if (typeof type !== 'string' || !Object.values(TX_TYPE).includes(type)) throw new Error(`Unknown transaction type ${type}`);
26
+ const fee = calculateFee(params.fee, type, {
50
27
  gas: params.gas,
51
- params: params,
28
+ params,
52
29
  vsn: params.vsn
53
30
  });
54
-
55
- var _buildTx = buildTx(_objectSpread(_objectSpread({}, params), {}, {
56
- fee: fee
57
- }), type, _objectSpread({
58
- vsn: params.vsn
59
- }, options)),
60
- rlpEncoded = _buildTx.rlpEncoded,
61
- binary = _buildTx.binary,
62
- encodedTx = _buildTx.tx,
63
- txObject = _buildTx.txObject;
64
-
31
+ const {
32
+ rlpEncoded,
33
+ binary,
34
+ tx: encodedTx,
35
+ txObject
36
+ } = buildTx({ ...params,
37
+ fee
38
+ }, type, {
39
+ vsn: params.vsn,
40
+ ...options
41
+ });
65
42
  return {
66
- rlpEncoded: rlpEncoded,
67
- binary: binary,
68
- encodedTx: encodedTx,
43
+ rlpEncoded,
44
+ binary,
45
+ encodedTx,
69
46
  params: txObject,
70
- type: type
47
+ type
71
48
  };
72
49
  };
73
50
  /**
@@ -79,38 +56,38 @@ var buildTransaction = function buildTransaction(type, params) {
79
56
  */
80
57
 
81
58
 
82
- var unpackTransaction = function unpackTransaction(tx) {
83
- if (!tx) throw new Error("Invalid transaction: ".concat(tx));
59
+ const unpackTransaction = tx => {
60
+ if (!tx) throw new Error(`Invalid transaction: ${tx}`);
84
61
 
85
62
  if (typeof tx === 'string') {
86
- var _unpackTx = unpackTx(tx),
87
- type = _unpackTx.txType,
88
- params = _unpackTx.tx,
89
- rlpEncoded = _unpackTx.rlpEncoded,
90
- binary = _unpackTx.binary;
91
-
63
+ const {
64
+ txType: type,
65
+ tx: params,
66
+ rlpEncoded,
67
+ binary
68
+ } = unpackTx(tx);
92
69
  return {
93
70
  encodedTx: tx,
94
- type: type,
95
- params: params,
96
- rlpEncoded: rlpEncoded,
97
- binary: binary
71
+ type,
72
+ params,
73
+ rlpEncoded,
74
+ binary
98
75
  };
99
76
  }
100
77
 
101
78
  if (Buffer.isBuffer(tx)) {
102
- var _unpackTx2 = unpackTx(tx, true),
103
- _type = _unpackTx2.txType,
104
- _params = _unpackTx2.tx,
105
- _rlpEncoded = _unpackTx2.rlpEncoded,
106
- _binary = _unpackTx2.binary;
107
-
79
+ const {
80
+ txType: type,
81
+ tx: params,
82
+ rlpEncoded,
83
+ binary
84
+ } = unpackTx(tx, true);
108
85
  return {
109
86
  encodedTx: encode(tx, 'tx'),
110
- type: _type,
111
- params: _params,
112
- rlpEncoded: _rlpEncoded,
113
- binary: _binary
87
+ type,
88
+ params,
89
+ rlpEncoded,
90
+ binary
114
91
  };
115
92
  }
116
93
  };
@@ -127,14 +104,13 @@ var unpackTransaction = function unpackTransaction(tx) {
127
104
  */
128
105
 
129
106
 
130
- var initTransaction = function initTransaction() {
131
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
132
- tx = _ref.tx,
133
- params = _ref.params,
134
- type = _ref.type,
135
- _ref$options = _ref.options,
136
- options = _ref$options === void 0 ? {} : _ref$options;
137
-
107
+ const initTransaction = function () {
108
+ let {
109
+ tx,
110
+ params,
111
+ type,
112
+ options = {}
113
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
138
114
  if (params && type) return buildTransaction(type, params, options);
139
115
  if (tx) return unpackTransaction(tx);
140
116
  throw new Error('Invalid TxObject arguments. Please provide one of { tx: "tx_asdasd23..." } or { type: "spendTx", params: {...} }');
@@ -156,37 +132,38 @@ var initTransaction = function initTransaction() {
156
132
  */
157
133
 
158
134
 
159
- export var TxObject = stampit({
160
- init: function init() {
161
- var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
162
- tx = _ref2.tx,
163
- params = _ref2.params,
164
- type = _ref2.type,
165
- _ref2$options = _ref2.options,
166
- options = _ref2$options === void 0 ? {} : _ref2$options;
167
-
135
+ export const TxObject = stampit({
136
+ init() {
137
+ let {
138
+ tx,
139
+ params,
140
+ type,
141
+ options = {}
142
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
168
143
  this.options = options;
169
144
  this.signatures = [];
170
-
171
- _Object$assign(this, initTransaction({
172
- tx: tx,
173
- params: params,
174
- type: type,
175
- options: options
145
+ Object.assign(this, initTransaction({
146
+ tx,
147
+ params,
148
+ type,
149
+ options
176
150
  }));
177
151
 
178
152
  if (this.type === TX_TYPE.signed) {
179
- var _this$params = this.params,
180
- signatures = _this$params.signatures,
181
- _this$params$encodedT = _this$params.encodedTx,
182
- txType = _this$params$encodedT.txType,
183
- _tx = _this$params$encodedT.tx;
153
+ const {
154
+ signatures,
155
+ encodedTx: {
156
+ txType,
157
+ tx
158
+ }
159
+ } = this.params;
184
160
  this.signatures = signatures;
185
- this.params = _tx;
161
+ this.params = tx;
186
162
  this.type = txType;
187
163
  this.isSigned = true;
188
164
  }
189
165
  },
166
+
190
167
  statics: {
191
168
  /**
192
169
  * Create txObject from base64c RLP encoded transaction string with 'tx_' prefix
@@ -195,11 +172,9 @@ export var TxObject = stampit({
195
172
  * @param {String} tx Transaction string (tx_23fsdgsdfg...)
196
173
  * @return {TxObject}
197
174
  */
198
- fromString: function fromString(tx) {
199
- return TxObject({
200
- tx: tx
201
- });
202
- },
175
+ fromString: tx => TxObject({
176
+ tx
177
+ }),
203
178
 
204
179
  /**
205
180
  * Create txObject from transaction RLP binary
@@ -208,11 +183,9 @@ export var TxObject = stampit({
208
183
  * @param {Buffer} tx Transaction RLP binary
209
184
  * @return {TxObject}
210
185
  */
211
- fromRlp: function fromRlp(tx) {
212
- return TxObject({
213
- tx: tx
214
- });
215
- }
186
+ fromRlp: tx => TxObject({
187
+ tx
188
+ })
216
189
  },
217
190
  methods: {
218
191
  /**
@@ -222,17 +195,18 @@ export var TxObject = stampit({
222
195
  * @param options
223
196
  * @return {TxObject}
224
197
  */
225
- setProp: function setProp() {
226
- var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
227
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
228
- if (_typeof(props) !== 'object') throw new Error('Props should be an object');
198
+ setProp() {
199
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
200
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
201
+ if (typeof props !== 'object') throw new Error('Props should be an object');
229
202
  this.isSigned = false;
230
203
  this.signatures = [];
231
-
232
- _Object$assign(this, buildTransaction(this.type, _objectSpread(_objectSpread(_objectSpread({}, this.params), props), {}, {
204
+ Object.assign(this, buildTransaction(this.type, { ...this.params,
205
+ ...props,
233
206
  fee: null
234
- }), _objectSpread(_objectSpread({}, this.options), options)));
235
-
207
+ }, { ...this.options,
208
+ ...options
209
+ }));
236
210
  return this;
237
211
  },
238
212
 
@@ -241,7 +215,7 @@ export var TxObject = stampit({
241
215
  * @alias module:@aeternity/aepp-sdk/es/tx/tx-object
242
216
  * @return {Array} Array of signatures
243
217
  */
244
- getSignatures: function getSignatures() {
218
+ getSignatures() {
245
219
  if (!this.isSigned) throw new Error('Signature not found, transaction is not signed');
246
220
  return this.signatures;
247
221
  },
@@ -252,22 +226,20 @@ export var TxObject = stampit({
252
226
  * @param {Buffer|String} signature Signature to add ( Can be: Buffer | Uint8Array | HexString )
253
227
  * @return {void}
254
228
  */
255
- addSignature: function addSignature(signature) {
256
- var _context2;
257
-
229
+ addSignature(signature) {
258
230
  signature = isHex(signature) ? Buffer.from(signature, 'hex') : signature;
259
231
  if (!Buffer.isBuffer(signature) && !(signature instanceof Uint8Array)) throw new Error('Invalid signature, signature must be of type Buffer or Uint8Array');
260
-
261
- _Object$assign(this, buildTransaction(TX_TYPE.signed, {
232
+ Object.assign(this, buildTransaction(TX_TYPE.signed, {
262
233
  encodedTx: this.rlpEncoded,
263
- signatures: [_concatInstanceProperty(_context2 = []).call(_context2, _toConsumableArray(this.signatures), [signature])]
234
+ signatures: [[...this.signatures, signature]]
264
235
  }));
265
-
266
- var _this$params2 = this.params,
267
- signatures = _this$params2.signatures,
268
- _this$params2$encoded = _this$params2.encodedTx,
269
- txType = _this$params2$encoded.txType,
270
- tx = _this$params2$encoded.tx;
236
+ const {
237
+ signatures,
238
+ encodedTx: {
239
+ txType,
240
+ tx
241
+ }
242
+ } = this.params;
271
243
  this.signatures = signatures;
272
244
  this.params = tx;
273
245
  this.type = txType;
@@ -280,17 +252,18 @@ export var TxObject = stampit({
280
252
  * @param {Object} props
281
253
  * @return {String} fee
282
254
  */
283
- calculateMinFee: function calculateMinFee() {
284
- var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
285
-
286
- var params = _objectSpread(_objectSpread({}, this.params), props);
287
-
255
+ calculateMinFee() {
256
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
257
+ const params = { ...this.params,
258
+ ...props
259
+ };
288
260
  return calculateFee(0, this.type, {
289
261
  gas: params.gas,
290
- params: params,
262
+ params,
291
263
  vsn: params.vsn
292
264
  });
293
265
  }
266
+
294
267
  }
295
268
  });
296
269
  export default TxObject;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/tx/tx-object.js"],"names":["stampit","buildTx","calculateFee","unpackTx","TX_TYPE","encode","isHex","buildTransaction","type","params","options","Error","fee","gas","vsn","rlpEncoded","binary","encodedTx","tx","txObject","unpackTransaction","txType","Buffer","isBuffer","initTransaction","TxObject","init","signatures","signed","isSigned","statics","fromString","fromRlp","methods","setProp","props","getSignatures","addSignature","signature","from","Uint8Array","calculateMinFee"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,WAApB;AACA,SAASC,OAAT,EAAkBC,YAAlB,EAAgCC,QAAhC,QAAgD,WAAhD;AACA,SAASC,OAAT,QAAwB,kBAAxB;AACA,SAASC,MAAT,QAAuB,mBAAvB;AACA,SAASC,KAAT,QAAsB,iBAAtB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,gBAAgB,GAAG,SAAnBA,gBAAmB,CAACC,IAAD,EAAOC,MAAP,EAAgC;AAAA;;AAAA,MAAjBC,OAAiB,uEAAP,EAAO;AACvD,MAAI,QAAOD,MAAP,MAAkB,QAAtB,EAA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AAN;;AACvE,qBAAc,IAAd,EAAoBJ,gBAAgB,CAACH,OAAO,CAACwB,MAAT,EAAiB;AAAEX,QAAAA,SAAS,EAAE,KAAKF,UAAlB;AAA8BY,QAAAA,UAAU,EAAE,4EAAK,KAAKA,UAAV,IAAsBW,SAAtB;AAA1C,OAAjB,CAApC;;AAEA,0BAAkD,KAAK7B,MAAvD;AAAA,UAAQkB,UAAR,iBAAQA,UAAR;AAAA,gDAAoBV,SAApB;AAAA,UAAiCI,MAAjC,yBAAiCA,MAAjC;AAAA,UAAyCH,EAAzC,yBAAyCA,EAAzC;AACA,WAAKS,UAAL,GAAkBA,UAAlB;AACA,WAAKlB,MAAL,GAAcS,EAAd;AACA,WAAKV,IAAL,GAAYa,MAAZ;AACA,WAAKQ,QAAL,GAAgB,IAAhB;AACD,KAxCM;;AAyCP;AACJ;AACA;AACA;AACA;AACA;AACIY,IAAAA,eA/CO,6BA+CsB;AAAA,UAAZN,KAAY,uEAAJ,EAAI;;AAC3B,UAAM1B,MAAM,mCAAQ,KAAKA,MAAb,GAAwB0B,KAAxB,CAAZ;;AACA,aAAOjC,YAAY,CAAC,CAAD,EAAI,KAAKM,IAAT,EAAe;AAAEK,QAAAA,GAAG,EAAEJ,MAAM,CAACI,GAAd;AAAmBJ,QAAAA,MAAM,EAANA,MAAnB;AAA2BK,QAAAA,GAAG,EAAEL,MAAM,CAACK;AAAvC,OAAf,CAAnB;AACD;AAlDM;AAhCqB,CAAD,CAAxB;AAsFP,eAAeW,QAAf","sourcesContent":["/**\n * TxObject module\n * @module @aeternity/aepp-sdk/es/tx/tx-object\n * @export TxObject\n * @example import TxObject from '@aeternity/aepp-sdk/es/tx/tx-object'\n */\nimport stampit from '@stamp/it'\nimport { buildTx, calculateFee, unpackTx } from './builder'\nimport { TX_TYPE } from './builder/schema'\nimport { encode } from './builder/helpers'\nimport { isHex } from '../utils/string'\n\n/**\n * Build transaction from object\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @param {String} type Transaction type\n * @param {Object} params Transaction params\n * @param {Object} [options={}] Options\n * @throws {Error} Arguments validation error's\n * @return {{ encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, params: Object, type: String }}\n */\nconst buildTransaction = (type, params, options = {}) => {\n if (typeof params !== 'object') throw new Error('\"params\" should be an object')\n if (typeof type !== 'string' || !Object.values(TX_TYPE).includes(type)) throw new Error(`Unknown transaction type ${type}`)\n const fee = calculateFee(params.fee, type, { gas: params.gas, params, vsn: params.vsn })\n const { rlpEncoded, binary, tx: encodedTx, txObject } = buildTx({ ...params, fee }, type, { vsn: params.vsn, ...options })\n return { rlpEncoded, binary, encodedTx, params: txObject, type }\n}\n\n/**\n * Unpack transaction from RLP encoded binary or base64c string\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @param {Buffer|String} tx RLP encoded binary or base64c(rlpBinary) string\n * @throws {Error} Arguments validation error's\n * @return {{ encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, type: String, params: Object }}\n */\nconst unpackTransaction = (tx) => {\n if (!tx) throw new Error(`Invalid transaction: ${tx}`)\n if (typeof tx === 'string') {\n const { txType: type, tx: params, rlpEncoded, binary } = unpackTx(tx)\n return { encodedTx: tx, type, params, rlpEncoded, binary }\n }\n if (Buffer.isBuffer(tx)) {\n const { txType: type, tx: params, rlpEncoded, binary } = unpackTx(tx, true)\n return { encodedTx: encode(tx, 'tx'), type, params, rlpEncoded, binary }\n }\n}\n\n/**\n * Helper which build or unpack transaction base on constructor arguments\n * Need to provide one of arguments: [tx] -> unpack flow or [params, type] -> build flow\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @param {Buffer|String} [tx] Transaction rlp binary or vase64c string\n * @param {Object} params Transaction params\n * @param {String} type Transaction type\n * @param {Object} [options={}] Options\n * @throws {Error} Arguments validation error's\n * @return {{encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, type: String, params: Object}}\n */\nconst initTransaction = ({ tx, params, type, options = {} } = {}) => {\n if (params && type) return buildTransaction(type, params, options)\n if (tx) return unpackTransaction(tx)\n throw new Error('Invalid TxObject arguments. Please provide one of { tx: \"tx_asdasd23...\" } or { type: \"spendTx\", params: {...} }')\n}\n\n/**\n * Transaction Validator Stamp\n * This stamp give us possibility to unpack and validate some of transaction properties,\n * to make sure we can post it to the chain\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @param {Buffer|String} [options.tx] - Rlp binary or base64c transaction\n * @param {Object} [options.params] - Transaction params\n * @param {String} [options.type] - Transaction type\n * @param {Object} [options.options] - Build options\n * @return {Object} TxObject instance\n * @example TxObject({ params: {...}, type: 'spendTx' })\n */\nexport const TxObject = stampit({\n init ({ tx, params, type, options = {} } = {}) {\n this.options = options\n this.signatures = []\n Object.assign(this, initTransaction({ tx, params, type, options }))\n\n if (this.type === TX_TYPE.signed) {\n const { signatures, encodedTx: { txType, tx } } = this.params\n this.signatures = signatures\n this.params = tx\n this.type = txType\n this.isSigned = true\n }\n },\n statics: {\n /**\n * Create txObject from base64c RLP encoded transaction string with 'tx_' prefix\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @static\n * @param {String} tx Transaction string (tx_23fsdgsdfg...)\n * @return {TxObject}\n */\n fromString: (tx) => TxObject({ tx }),\n /**\n * Create txObject from transaction RLP binary\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @static\n * @param {Buffer} tx Transaction RLP binary\n * @return {TxObject}\n */\n fromRlp: (tx) => TxObject({ tx })\n },\n methods: {\n /**\n * Rebuild transaction with new params and recalculate fee\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @param {Object} props Transaction properties for update\n * @param options\n * @return {TxObject}\n */\n setProp (props = {}, options = {}) {\n if (typeof props !== 'object') throw new Error('Props should be an object')\n this.isSigned = false\n this.signatures = []\n Object.assign(this, buildTransaction(this.type, { ...this.params, ...props, fee: null }, { ...this.options, ...options }))\n return this\n },\n /**\n * Get signatures\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @return {Array} Array of signatures\n */\n getSignatures () {\n if (!this.isSigned) throw new Error('Signature not found, transaction is not signed')\n return this.signatures\n },\n /**\n * Add signature\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @param {Buffer|String} signature Signature to add ( Can be: Buffer | Uint8Array | HexString )\n * @return {void}\n */\n addSignature (signature) {\n signature = isHex(signature) ? Buffer.from(signature, 'hex') : signature\n if (!Buffer.isBuffer(signature) && !(signature instanceof Uint8Array)) throw new Error('Invalid signature, signature must be of type Buffer or Uint8Array')\n Object.assign(this, buildTransaction(TX_TYPE.signed, { encodedTx: this.rlpEncoded, signatures: [[...this.signatures, signature]] }))\n\n const { signatures, encodedTx: { txType, tx } } = this.params\n this.signatures = signatures\n this.params = tx\n this.type = txType\n this.isSigned = true\n },\n /**\n * Calculate fee\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @param {Object} props\n * @return {String} fee\n */\n calculateMinFee (props = {}) {\n const params = { ...this.params, ...props }\n return calculateFee(0, this.type, { gas: params.gas, params, vsn: params.vsn })\n }\n }\n})\n\nexport default TxObject\n"],"file":"tx-object.js"}
1
+ {"version":3,"sources":["../../src/tx/tx-object.js"],"names":["stampit","buildTx","calculateFee","unpackTx","TX_TYPE","encode","isHex","buildTransaction","type","params","options","Error","Object","values","includes","fee","gas","vsn","rlpEncoded","binary","tx","encodedTx","txObject","unpackTransaction","txType","Buffer","isBuffer","initTransaction","TxObject","init","signatures","assign","signed","isSigned","statics","fromString","fromRlp","methods","setProp","props","getSignatures","addSignature","signature","from","Uint8Array","calculateMinFee"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,WAApB;AACA,SAASC,OAAT,EAAkBC,YAAlB,EAAgCC,QAAhC,QAAgD,WAAhD;AACA,SAASC,OAAT,QAAwB,kBAAxB;AACA,SAASC,MAAT,QAAuB,mBAAvB;AACA,SAASC,KA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ArB,CAAD;AAA1C,OAAjB,CAApC;AAEA,YAAM;AAAEZ,QAAAA,UAAF;AAAcT,QAAAA,SAAS,EAAE;AAAEG,UAAAA,MAAF;AAAUJ,UAAAA;AAAV;AAAzB,UAA4C,KAAKX,MAAvD;AACA,WAAKqB,UAAL,GAAkBA,UAAlB;AACA,WAAKrB,MAAL,GAAcW,EAAd;AACA,WAAKZ,IAAL,GAAYgB,MAAZ;AACA,WAAKS,QAAL,GAAgB,IAAhB;AACD,KAxCM;;AAyCP;AACJ;AACA;AACA;AACA;AACA;AACIY,IAAAA,eAAe,GAAc;AAAA,UAAZN,KAAY,uEAAJ,EAAI;AAC3B,YAAM9B,MAAM,GAAG,EAAE,GAAG,KAAKA,MAAV;AAAkB,WAAG8B;AAArB,OAAf;AACA,aAAOrC,YAAY,CAAC,CAAD,EAAI,KAAKM,IAAT,EAAe;AAAEQ,QAAAA,GAAG,EAAEP,MAAM,CAACO,GAAd;AAAmBP,QAAAA,MAAnB;AAA2BQ,QAAAA,GAAG,EAAER,MAAM,CAACQ;AAAvC,OAAf,CAAnB;AACD;;AAlDM;AAhCqB,CAAD,CAAxB;AAsFP,eAAeW,QAAf","sourcesContent":["/**\n * TxObject module\n * @module @aeternity/aepp-sdk/es/tx/tx-object\n * @export TxObject\n * @example import TxObject from '@aeternity/aepp-sdk/es/tx/tx-object'\n */\nimport stampit from '@stamp/it'\nimport { buildTx, calculateFee, unpackTx } from './builder'\nimport { TX_TYPE } from './builder/schema'\nimport { encode } from './builder/helpers'\nimport { isHex } from '../utils/string'\n\n/**\n * Build transaction from object\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @param {String} type Transaction type\n * @param {Object} params Transaction params\n * @param {Object} [options={}] Options\n * @throws {Error} Arguments validation error's\n * @return {{ encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, params: Object, type: String }}\n */\nconst buildTransaction = (type, params, options = {}) => {\n if (typeof params !== 'object') throw new Error('\"params\" should be an object')\n if (typeof type !== 'string' || !Object.values(TX_TYPE).includes(type)) throw new Error(`Unknown transaction type ${type}`)\n const fee = calculateFee(params.fee, type, { gas: params.gas, params, vsn: params.vsn })\n const { rlpEncoded, binary, tx: encodedTx, txObject } = buildTx({ ...params, fee }, type, { vsn: params.vsn, ...options })\n return { rlpEncoded, binary, encodedTx, params: txObject, type }\n}\n\n/**\n * Unpack transaction from RLP encoded binary or base64c string\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @param {Buffer|String} tx RLP encoded binary or base64c(rlpBinary) string\n * @throws {Error} Arguments validation error's\n * @return {{ encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, type: String, params: Object }}\n */\nconst unpackTransaction = (tx) => {\n if (!tx) throw new Error(`Invalid transaction: ${tx}`)\n if (typeof tx === 'string') {\n const { txType: type, tx: params, rlpEncoded, binary } = unpackTx(tx)\n return { encodedTx: tx, type, params, rlpEncoded, binary }\n }\n if (Buffer.isBuffer(tx)) {\n const { txType: type, tx: params, rlpEncoded, binary } = unpackTx(tx, true)\n return { encodedTx: encode(tx, 'tx'), type, params, rlpEncoded, binary }\n }\n}\n\n/**\n * Helper which build or unpack transaction base on constructor arguments\n * Need to provide one of arguments: [tx] -> unpack flow or [params, type] -> build flow\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @param {Buffer|String} [tx] Transaction rlp binary or vase64c string\n * @param {Object} params Transaction params\n * @param {String} type Transaction type\n * @param {Object} [options={}] Options\n * @throws {Error} Arguments validation error's\n * @return {{encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, type: String, params: Object}}\n */\nconst initTransaction = ({ tx, params, type, options = {} } = {}) => {\n if (params && type) return buildTransaction(type, params, options)\n if (tx) return unpackTransaction(tx)\n throw new Error('Invalid TxObject arguments. Please provide one of { tx: \"tx_asdasd23...\" } or { type: \"spendTx\", params: {...} }')\n}\n\n/**\n * Transaction Validator Stamp\n * This stamp give us possibility to unpack and validate some of transaction properties,\n * to make sure we can post it to the chain\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @param {Buffer|String} [options.tx] - Rlp binary or base64c transaction\n * @param {Object} [options.params] - Transaction params\n * @param {String} [options.type] - Transaction type\n * @param {Object} [options.options] - Build options\n * @return {Object} TxObject instance\n * @example TxObject({ params: {...}, type: 'spendTx' })\n */\nexport const TxObject = stampit({\n init ({ tx, params, type, options = {} } = {}) {\n this.options = options\n this.signatures = []\n Object.assign(this, initTransaction({ tx, params, type, options }))\n\n if (this.type === TX_TYPE.signed) {\n const { signatures, encodedTx: { txType, tx } } = this.params\n this.signatures = signatures\n this.params = tx\n this.type = txType\n this.isSigned = true\n }\n },\n statics: {\n /**\n * Create txObject from base64c RLP encoded transaction string with 'tx_' prefix\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @static\n * @param {String} tx Transaction string (tx_23fsdgsdfg...)\n * @return {TxObject}\n */\n fromString: (tx) => TxObject({ tx }),\n /**\n * Create txObject from transaction RLP binary\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @static\n * @param {Buffer} tx Transaction RLP binary\n * @return {TxObject}\n */\n fromRlp: (tx) => TxObject({ tx })\n },\n methods: {\n /**\n * Rebuild transaction with new params and recalculate fee\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @param {Object} props Transaction properties for update\n * @param options\n * @return {TxObject}\n */\n setProp (props = {}, options = {}) {\n if (typeof props !== 'object') throw new Error('Props should be an object')\n this.isSigned = false\n this.signatures = []\n Object.assign(this, buildTransaction(this.type, { ...this.params, ...props, fee: null }, { ...this.options, ...options }))\n return this\n },\n /**\n * Get signatures\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @return {Array} Array of signatures\n */\n getSignatures () {\n if (!this.isSigned) throw new Error('Signature not found, transaction is not signed')\n return this.signatures\n },\n /**\n * Add signature\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @param {Buffer|String} signature Signature to add ( Can be: Buffer | Uint8Array | HexString )\n * @return {void}\n */\n addSignature (signature) {\n signature = isHex(signature) ? Buffer.from(signature, 'hex') : signature\n if (!Buffer.isBuffer(signature) && !(signature instanceof Uint8Array)) throw new Error('Invalid signature, signature must be of type Buffer or Uint8Array')\n Object.assign(this, buildTransaction(TX_TYPE.signed, { encodedTx: this.rlpEncoded, signatures: [[...this.signatures, signature]] }))\n\n const { signatures, encodedTx: { txType, tx } } = this.params\n this.signatures = signatures\n this.params = tx\n this.type = txType\n this.isSigned = true\n },\n /**\n * Calculate fee\n * @alias module:@aeternity/aepp-sdk/es/tx/tx-object\n * @param {Object} props\n * @return {String} fee\n */\n calculateMinFee (props = {}) {\n const params = { ...this.params, ...props }\n return calculateFee(0, this.type, { gas: params.gas, params, vsn: params.vsn })\n }\n }\n})\n\nexport default TxObject\n"],"file":"tx-object.js"}