@aeternity/aepp-sdk 8.2.0 → 10.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -9
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/account/base.js +33 -119
- package/es/account/base.js.map +1 -1
- package/es/account/memory.js +17 -19
- package/es/account/memory.js.map +1 -1
- package/es/account/multiple.js +75 -154
- package/es/account/multiple.js.map +1 -1
- package/es/ae/aens.js +164 -599
- package/es/ae/aens.js.map +1 -1
- package/es/ae/contract.js +108 -916
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +89 -250
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +132 -500
- package/es/ae/oracle.js.map +1 -1
- package/es/chain/index.js +4 -23
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +292 -1018
- package/es/chain/node.js.map +1 -1
- package/es/channel/handlers.js +597 -1086
- package/es/channel/handlers.js.map +1 -1
- package/es/channel/index.js +203 -451
- package/es/channel/index.js.map +1 -1
- package/es/channel/internal.js +129 -301
- package/es/channel/internal.js.map +1 -1
- package/es/contract/aci/index.js +319 -491
- package/es/contract/aci/index.js.map +1 -1
- package/es/contract/aci/transformation.js +35 -711
- package/es/contract/aci/transformation.js.map +1 -1
- package/es/contract/compiler.js +129 -203
- package/es/contract/compiler.js.map +1 -1
- package/es/contract/ga/helpers.js +17 -122
- package/es/contract/ga/helpers.js.map +1 -1
- package/es/contract/ga/index.js +102 -247
- package/es/contract/ga/index.js.map +1 -1
- package/es/contract/index.js +1 -1
- package/es/contract/index.js.map +1 -1
- package/es/index.js +2 -3
- package/es/index.js.map +1 -1
- package/es/node-pool/index.js +54 -73
- package/es/node-pool/index.js.map +1 -1
- package/es/node.js +56 -157
- package/es/node.js.map +1 -1
- package/es/other.d.ts +1 -1
- package/es/tx/builder/helpers.js +49 -89
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +205 -303
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +585 -573
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/index.js +1 -1
- package/es/tx/index.js.map +1 -1
- package/es/tx/tx-object.js +105 -135
- package/es/tx/tx-object.js.map +1 -1
- package/es/tx/tx.js +810 -1586
- package/es/tx/tx.js.map +1 -1
- package/es/tx/validator.js +191 -426
- package/es/tx/validator.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +17 -21
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +38 -74
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +14 -15
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
- package/es/utils/aepp-wallet-communication/helpers.js +60 -105
- package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +179 -510
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +70 -89
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +354 -603
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/schema.js +43 -39
- package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
- package/es/utils/amount-formatter.js +41 -61
- package/es/utils/amount-formatter.js.map +1 -1
- package/es/utils/async-init.js +28 -64
- package/es/utils/async-init.js.map +1 -1
- package/es/utils/bignumber.js +3 -11
- package/es/utils/bignumber.js.map +1 -1
- package/es/utils/bytes.js +5 -9
- package/es/utils/bytes.js.map +1 -1
- package/es/utils/crypto.js +49 -75
- package/es/utils/crypto.js.map +1 -1
- package/es/utils/hd-wallet.js +45 -81
- package/es/utils/hd-wallet.js.map +1 -1
- package/es/utils/json-big.js +16 -49
- package/es/utils/json-big.js.map +1 -1
- package/es/utils/keystore.js +81 -246
- package/es/utils/keystore.js.map +1 -1
- package/es/utils/mptree.js +88 -134
- package/es/utils/mptree.js.map +1 -1
- package/es/utils/other.js +10 -60
- package/es/utils/other.js.map +1 -1
- package/es/utils/semver-satisfies.js +9 -28
- package/es/utils/semver-satisfies.js.map +1 -1
- package/es/utils/string.js +4 -13
- package/es/utils/string.js.map +1 -1
- package/es/utils/swagger.js +85 -218
- package/es/utils/swagger.js.map +1 -1
- package/package.json +52 -43
- package/src/account/base.js +8 -9
- package/src/account/multiple.js +20 -16
- package/src/ae/aens.js +25 -21
- package/src/ae/contract.js +65 -246
- package/src/ae/index.js +31 -7
- package/src/ae/oracle.js +21 -17
- package/src/chain/index.js +2 -12
- package/src/chain/node.js +26 -29
- package/src/channel/handlers.js +0 -1
- package/src/channel/index.js +4 -5
- package/src/contract/aci/index.js +221 -106
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +45 -4
- package/src/contract/ga/helpers.js +2 -12
- package/src/contract/ga/index.js +22 -26
- package/src/index.js +2 -4
- package/src/node-pool/index.js +21 -12
- package/src/node.js +22 -26
- package/src/tx/builder/helpers.js +12 -24
- package/src/tx/builder/index.js +18 -15
- package/src/tx/builder/schema.js +43 -108
- package/src/tx/tx-object.js +0 -2
- package/src/tx/tx.js +157 -144
- package/src/tx/validator.js +134 -202
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +1 -3
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +9 -10
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/amount-formatter.ts +1 -1
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/crypto.js +4 -17
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +24 -7
- package/CHANGELOG.md +0 -1716
- package/src/contract/aci/helpers.js +0 -140
package/es/tx/tx-object.js
CHANGED
|
@@ -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
|
|
@@ -26,7 +5,6 @@ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/insta
|
|
|
26
5
|
* @example import TxObject from '@aeternity/aepp-sdk/es/tx/tx-object'
|
|
27
6
|
*/
|
|
28
7
|
import stampit from '@stamp/it';
|
|
29
|
-
import { assertedType } from '../utils/crypto';
|
|
30
8
|
import { buildTx, calculateFee, unpackTx } from './builder';
|
|
31
9
|
import { TX_TYPE } from './builder/schema';
|
|
32
10
|
import { encode } from './builder/helpers';
|
|
@@ -41,34 +19,32 @@ import { isHex } from '../utils/string';
|
|
|
41
19
|
* @return {{ encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, params: Object, type: String }}
|
|
42
20
|
*/
|
|
43
21
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (typeof type !== 'string' || !_includesInstanceProperty(_context = _Object$values(TX_TYPE)).call(_context, type)) throw new Error("Unknown transaction type ".concat(type));
|
|
50
|
-
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, {
|
|
51
27
|
gas: params.gas,
|
|
52
|
-
params
|
|
28
|
+
params,
|
|
53
29
|
vsn: params.vsn
|
|
54
30
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
+
});
|
|
66
42
|
return {
|
|
67
|
-
rlpEncoded
|
|
68
|
-
binary
|
|
69
|
-
encodedTx
|
|
43
|
+
rlpEncoded,
|
|
44
|
+
binary,
|
|
45
|
+
encodedTx,
|
|
70
46
|
params: txObject,
|
|
71
|
-
type
|
|
47
|
+
type
|
|
72
48
|
};
|
|
73
49
|
};
|
|
74
50
|
/**
|
|
@@ -80,40 +56,38 @@ var buildTransaction = function buildTransaction(type, params) {
|
|
|
80
56
|
*/
|
|
81
57
|
|
|
82
58
|
|
|
83
|
-
|
|
84
|
-
if (!tx) throw new Error(
|
|
59
|
+
const unpackTransaction = tx => {
|
|
60
|
+
if (!tx) throw new Error(`Invalid transaction: ${tx}`);
|
|
85
61
|
|
|
86
62
|
if (typeof tx === 'string') {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
binary = _unpackTx.binary;
|
|
94
|
-
|
|
63
|
+
const {
|
|
64
|
+
txType: type,
|
|
65
|
+
tx: params,
|
|
66
|
+
rlpEncoded,
|
|
67
|
+
binary
|
|
68
|
+
} = unpackTx(tx);
|
|
95
69
|
return {
|
|
96
70
|
encodedTx: tx,
|
|
97
|
-
type
|
|
98
|
-
params
|
|
99
|
-
rlpEncoded
|
|
100
|
-
binary
|
|
71
|
+
type,
|
|
72
|
+
params,
|
|
73
|
+
rlpEncoded,
|
|
74
|
+
binary
|
|
101
75
|
};
|
|
102
76
|
}
|
|
103
77
|
|
|
104
78
|
if (Buffer.isBuffer(tx)) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
79
|
+
const {
|
|
80
|
+
txType: type,
|
|
81
|
+
tx: params,
|
|
82
|
+
rlpEncoded,
|
|
83
|
+
binary
|
|
84
|
+
} = unpackTx(tx, true);
|
|
111
85
|
return {
|
|
112
86
|
encodedTx: encode(tx, 'tx'),
|
|
113
|
-
type
|
|
114
|
-
params
|
|
115
|
-
rlpEncoded
|
|
116
|
-
binary
|
|
87
|
+
type,
|
|
88
|
+
params,
|
|
89
|
+
rlpEncoded,
|
|
90
|
+
binary
|
|
117
91
|
};
|
|
118
92
|
}
|
|
119
93
|
};
|
|
@@ -130,14 +104,13 @@ var unpackTransaction = function unpackTransaction(tx) {
|
|
|
130
104
|
*/
|
|
131
105
|
|
|
132
106
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
107
|
+
const initTransaction = function () {
|
|
108
|
+
let {
|
|
109
|
+
tx,
|
|
110
|
+
params,
|
|
111
|
+
type,
|
|
112
|
+
options = {}
|
|
113
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
141
114
|
if (params && type) return buildTransaction(type, params, options);
|
|
142
115
|
if (tx) return unpackTransaction(tx);
|
|
143
116
|
throw new Error('Invalid TxObject arguments. Please provide one of { tx: "tx_asdasd23..." } or { type: "spendTx", params: {...} }');
|
|
@@ -159,37 +132,38 @@ var initTransaction = function initTransaction() {
|
|
|
159
132
|
*/
|
|
160
133
|
|
|
161
134
|
|
|
162
|
-
export
|
|
163
|
-
init
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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] : {};
|
|
171
143
|
this.options = options;
|
|
172
144
|
this.signatures = [];
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
options: options
|
|
145
|
+
Object.assign(this, initTransaction({
|
|
146
|
+
tx,
|
|
147
|
+
params,
|
|
148
|
+
type,
|
|
149
|
+
options
|
|
179
150
|
}));
|
|
180
151
|
|
|
181
152
|
if (this.type === TX_TYPE.signed) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
txType
|
|
186
|
-
|
|
153
|
+
const {
|
|
154
|
+
signatures,
|
|
155
|
+
encodedTx: {
|
|
156
|
+
txType,
|
|
157
|
+
tx
|
|
158
|
+
}
|
|
159
|
+
} = this.params;
|
|
187
160
|
this.signatures = signatures;
|
|
188
|
-
this.params =
|
|
161
|
+
this.params = tx;
|
|
189
162
|
this.type = txType;
|
|
190
163
|
this.isSigned = true;
|
|
191
164
|
}
|
|
192
165
|
},
|
|
166
|
+
|
|
193
167
|
statics: {
|
|
194
168
|
/**
|
|
195
169
|
* Create txObject from base64c RLP encoded transaction string with 'tx_' prefix
|
|
@@ -198,11 +172,9 @@ export var TxObject = stampit({
|
|
|
198
172
|
* @param {String} tx Transaction string (tx_23fsdgsdfg...)
|
|
199
173
|
* @return {TxObject}
|
|
200
174
|
*/
|
|
201
|
-
fromString:
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
});
|
|
205
|
-
},
|
|
175
|
+
fromString: tx => TxObject({
|
|
176
|
+
tx
|
|
177
|
+
}),
|
|
206
178
|
|
|
207
179
|
/**
|
|
208
180
|
* Create txObject from transaction RLP binary
|
|
@@ -211,11 +183,9 @@ export var TxObject = stampit({
|
|
|
211
183
|
* @param {Buffer} tx Transaction RLP binary
|
|
212
184
|
* @return {TxObject}
|
|
213
185
|
*/
|
|
214
|
-
fromRlp:
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
});
|
|
218
|
-
}
|
|
186
|
+
fromRlp: tx => TxObject({
|
|
187
|
+
tx
|
|
188
|
+
})
|
|
219
189
|
},
|
|
220
190
|
methods: {
|
|
221
191
|
/**
|
|
@@ -225,17 +195,18 @@ export var TxObject = stampit({
|
|
|
225
195
|
* @param options
|
|
226
196
|
* @return {TxObject}
|
|
227
197
|
*/
|
|
228
|
-
setProp
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (
|
|
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');
|
|
232
202
|
this.isSigned = false;
|
|
233
203
|
this.signatures = [];
|
|
234
|
-
|
|
235
|
-
|
|
204
|
+
Object.assign(this, buildTransaction(this.type, { ...this.params,
|
|
205
|
+
...props,
|
|
236
206
|
fee: null
|
|
237
|
-
}
|
|
238
|
-
|
|
207
|
+
}, { ...this.options,
|
|
208
|
+
...options
|
|
209
|
+
}));
|
|
239
210
|
return this;
|
|
240
211
|
},
|
|
241
212
|
|
|
@@ -244,7 +215,7 @@ export var TxObject = stampit({
|
|
|
244
215
|
* @alias module:@aeternity/aepp-sdk/es/tx/tx-object
|
|
245
216
|
* @return {Array} Array of signatures
|
|
246
217
|
*/
|
|
247
|
-
getSignatures
|
|
218
|
+
getSignatures() {
|
|
248
219
|
if (!this.isSigned) throw new Error('Signature not found, transaction is not signed');
|
|
249
220
|
return this.signatures;
|
|
250
221
|
},
|
|
@@ -255,22 +226,20 @@ export var TxObject = stampit({
|
|
|
255
226
|
* @param {Buffer|String} signature Signature to add ( Can be: Buffer | Uint8Array | HexString )
|
|
256
227
|
* @return {void}
|
|
257
228
|
*/
|
|
258
|
-
addSignature
|
|
259
|
-
var _context2;
|
|
260
|
-
|
|
229
|
+
addSignature(signature) {
|
|
261
230
|
signature = isHex(signature) ? Buffer.from(signature, 'hex') : signature;
|
|
262
231
|
if (!Buffer.isBuffer(signature) && !(signature instanceof Uint8Array)) throw new Error('Invalid signature, signature must be of type Buffer or Uint8Array');
|
|
263
|
-
|
|
264
|
-
_Object$assign(this, buildTransaction(TX_TYPE.signed, {
|
|
232
|
+
Object.assign(this, buildTransaction(TX_TYPE.signed, {
|
|
265
233
|
encodedTx: this.rlpEncoded,
|
|
266
|
-
signatures: [
|
|
234
|
+
signatures: [[...this.signatures, signature]]
|
|
267
235
|
}));
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
236
|
+
const {
|
|
237
|
+
signatures,
|
|
238
|
+
encodedTx: {
|
|
239
|
+
txType,
|
|
240
|
+
tx
|
|
241
|
+
}
|
|
242
|
+
} = this.params;
|
|
274
243
|
this.signatures = signatures;
|
|
275
244
|
this.params = tx;
|
|
276
245
|
this.type = txType;
|
|
@@ -283,17 +252,18 @@ export var TxObject = stampit({
|
|
|
283
252
|
* @param {Object} props
|
|
284
253
|
* @return {String} fee
|
|
285
254
|
*/
|
|
286
|
-
calculateMinFee
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
255
|
+
calculateMinFee() {
|
|
256
|
+
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
257
|
+
const params = { ...this.params,
|
|
258
|
+
...props
|
|
259
|
+
};
|
|
291
260
|
return calculateFee(0, this.type, {
|
|
292
261
|
gas: params.gas,
|
|
293
|
-
params
|
|
262
|
+
params,
|
|
294
263
|
vsn: params.vsn
|
|
295
264
|
});
|
|
296
265
|
}
|
|
266
|
+
|
|
297
267
|
}
|
|
298
268
|
});
|
|
299
269
|
export default TxObject;
|
package/es/tx/tx-object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tx/tx-object.js"],"names":["stampit","assertedType","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,YAAT,QAA6B,iBAA7B;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,EAAgC,MAAM,IAAIE,K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,SAAhB,CAAD,IAA+B,EAAEA,SAAS,YAAYE,UAAvB,CAAnC,EAAuE,MAAM,IAAI7B,KAAJ,CAAU,mEAAV,CAAN;;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 { assertedType } from '../utils/crypto'\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 if (!assertedType(tx, 'tx', true)) throw new Error('Invalid transaction string. Tx should be `tx` prefixed base58c 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;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A,MAAM,CAACmB,MAAP,CAAc,IAAd,EAAoBxB,gBAAgB,CAACH,OAAO,CAAC4B,MAAT,EAAiB;AAAEX,QAAAA,SAAS,EAAE,KAAKH,UAAlB;AAA8BY,QAAAA,UAAU,EAAE,CAAC,CAAC,GAAG,KAAKA,UAAT,EAAqBY,SAArB,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"}
|