@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.
- package/CHANGELOG.md +216 -337
- 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 +36 -120
- 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 +79 -156
- package/es/account/multiple.js.map +1 -1
- package/es/ae/aens.js +205 -626
- package/es/ae/aens.js.map +1 -1
- package/es/ae/contract.js +114 -918
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +90 -250
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +136 -504
- package/es/ae/oracle.js.map +1 -1
- package/es/ae/universal.js.map +1 -1
- package/es/chain/index.js +12 -27
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +289 -1020
- 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 +238 -465
- 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 +328 -495
- 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 +131 -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 +108 -249
- package/es/contract/ga/index.js.map +1 -1
- package/es/contract/index.js +7 -3
- package/es/contract/index.js.map +1 -1
- package/es/index.js +3 -3
- package/es/index.js.map +1 -1
- package/es/node-pool/index.js +57 -74
- package/es/node-pool/index.js.map +1 -1
- package/es/node.js +65 -161
- package/es/node.js.map +1 -1
- package/es/other.d.ts +1 -1
- package/es/tx/builder/helpers.js +62 -115
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +218 -309
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +586 -573
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/index.js +102 -13
- package/es/tx/index.js.map +1 -1
- package/es/tx/tx-object.js +114 -138
- 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 +20 -23
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +53 -80
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +1 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +24 -19
- 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 +191 -514
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +78 -93
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +381 -613
- 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 +41 -106
- 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 +87 -224
- package/es/utils/swagger.js.map +1 -1
- package/package.json +51 -44
- package/src/account/base.js +11 -10
- package/src/account/multiple.js +24 -18
- package/src/ae/aens.js +64 -61
- package/src/ae/contract.js +71 -248
- package/src/ae/index.js +34 -9
- package/src/ae/oracle.js +30 -22
- package/src/ae/universal.js +3 -1
- package/src/chain/index.js +10 -16
- package/src/chain/node.js +38 -38
- package/src/channel/handlers.js +10 -4
- package/src/channel/index.js +44 -20
- package/src/contract/aci/index.js +234 -112
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +50 -5
- package/src/contract/ga/helpers.js +6 -14
- package/src/contract/ga/index.js +28 -28
- package/src/contract/index.js +6 -2
- package/src/index.js +4 -4
- package/src/node-pool/index.js +24 -13
- package/src/node.js +29 -30
- package/src/tx/builder/helpers.js +31 -56
- package/src/tx/builder/index.js +67 -28
- package/src/tx/builder/schema.js +79 -121
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +25 -8
- package/src/tx/tx.js +229 -150
- package/src/tx/validator.js +134 -202
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +3 -2
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +25 -7
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +10 -4
- package/src/utils/aepp-wallet-communication/helpers.js +4 -2
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +33 -12
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +9 -5
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +59 -29
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/aepp-wallet-communication/wallet-detector.js +4 -1
- package/src/utils/amount-formatter.ts +1 -1
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/crypto.js +4 -68
- package/src/utils/keystore.js +10 -2
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +22 -10
- package/src/contract/aci/helpers.js +0 -140
package/es/tx/validator.js
CHANGED
|
@@ -1,443 +1,208 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
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 _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
|
|
10
|
-
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
11
|
-
import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
|
|
12
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
|
|
13
|
-
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
14
|
-
|
|
15
|
-
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; }
|
|
16
|
-
|
|
17
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context11; _forEachInstanceProperty(_context11 = ownKeys(Object(source), true)).call(_context11, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context12; _forEachInstanceProperty(_context12 = ownKeys(Object(source))).call(_context12, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
18
|
-
|
|
19
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
20
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
21
|
-
import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
|
|
22
|
-
import _Object$entries from "@babel/runtime-corejs3/core-js-stable/object/entries";
|
|
23
|
-
import _parseInt from "@babel/runtime-corejs3/core-js-stable/parse-int";
|
|
24
|
-
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
25
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
26
|
-
import { verify, decodeBase58Check, assertedType } from '../utils/crypto';
|
|
27
|
-
import { encode } from '../tx/builder/helpers';
|
|
1
|
+
import { verify, hash } from '../utils/crypto';
|
|
2
|
+
import { encode, decode } from './builder/helpers';
|
|
28
3
|
import BigNumber from 'bignumber.js';
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import NodePool from '../node-pool';
|
|
4
|
+
import { MIN_GAS_PRICE, PROTOCOL_VM_ABI, TX_TYPE } from './builder/schema';
|
|
5
|
+
import { calculateFee, unpackTx } from './builder';
|
|
32
6
|
/**
|
|
33
7
|
* Transaction validator
|
|
34
8
|
* @module @aeternity/aepp-sdk/es/tx/validator
|
|
35
|
-
* @export
|
|
36
|
-
* @example import {
|
|
9
|
+
* @export verifyTransaction
|
|
10
|
+
* @example import { verifyTransaction } from '@aeternity/aepp-sdk'
|
|
37
11
|
*/
|
|
38
12
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
_context5.t6 = {
|
|
176
|
-
height: _context5.t2,
|
|
177
|
-
balance: _context5.t3,
|
|
178
|
-
accountNonce: _context5.t4,
|
|
179
|
-
ownerPublicKey: _context5.t5
|
|
180
|
-
};
|
|
181
|
-
_context5.t7 = chain.getNodeInfo();
|
|
182
|
-
return _context5.abrupt("return", (0, _context5.t1)(_context5.t6, _context5.t7));
|
|
183
|
-
|
|
184
|
-
case 26:
|
|
185
|
-
case "end":
|
|
186
|
-
return _context5.stop();
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}, _callee, null, [[3, 13]]);
|
|
190
|
-
}));
|
|
191
|
-
|
|
192
|
-
return function resolveDataForBase(_x, _x2) {
|
|
193
|
-
return _ref14.apply(this, arguments);
|
|
13
|
+
const validators = [async (_ref, _ref2) => {
|
|
14
|
+
let {
|
|
15
|
+
encodedTx,
|
|
16
|
+
signatures
|
|
17
|
+
} = _ref;
|
|
18
|
+
let {
|
|
19
|
+
account,
|
|
20
|
+
node,
|
|
21
|
+
parentTxTypes
|
|
22
|
+
} = _ref2;
|
|
23
|
+
if ((encodedTx ?? signatures) === undefined) return [];
|
|
24
|
+
if (signatures.length !== 1) return []; // TODO: Support multisignature?
|
|
25
|
+
|
|
26
|
+
const prefix = Buffer.from([node.nodeNetworkId, ...(parentTxTypes.includes(TX_TYPE.payingFor) ? ['inner_tx'] : [])].join('-'));
|
|
27
|
+
const txWithNetworkId = Buffer.concat([prefix, encodedTx.rlpEncoded]);
|
|
28
|
+
const txHashWithNetworkId = Buffer.concat([prefix, hash(encodedTx.rlpEncoded)]);
|
|
29
|
+
const decodedPub = decode(account.id, 'ak');
|
|
30
|
+
if (verify(txWithNetworkId, signatures[0], decodedPub) || verify(txHashWithNetworkId, signatures[0], decodedPub)) return [];
|
|
31
|
+
return [{
|
|
32
|
+
message: 'Signature cannot be verified, please ensure that you transaction have' + ' the correct prefix and the correct private key for the sender address',
|
|
33
|
+
key: 'InvalidSignature',
|
|
34
|
+
checkedKeys: ['encodedTx', 'signatures']
|
|
35
|
+
}];
|
|
36
|
+
}, async (_ref3, _ref4) => {
|
|
37
|
+
let {
|
|
38
|
+
encodedTx,
|
|
39
|
+
tx
|
|
40
|
+
} = _ref3;
|
|
41
|
+
let {
|
|
42
|
+
node,
|
|
43
|
+
parentTxTypes,
|
|
44
|
+
txType
|
|
45
|
+
} = _ref4;
|
|
46
|
+
if ((encodedTx ?? tx) === undefined) return [];
|
|
47
|
+
return verifyTransaction(encode((encodedTx ?? tx).rlpEncoded, 'tx'), node, [...parentTxTypes, txType]);
|
|
48
|
+
}, (tx, _ref5) => {
|
|
49
|
+
let {
|
|
50
|
+
txType
|
|
51
|
+
} = _ref5;
|
|
52
|
+
if (tx.fee === undefined) return [];
|
|
53
|
+
const minFee = calculateFee(0, txType, {
|
|
54
|
+
gas: +tx.gas || 0,
|
|
55
|
+
params: tx,
|
|
56
|
+
showWarning: false,
|
|
57
|
+
vsn: tx.VSN
|
|
58
|
+
});
|
|
59
|
+
if (new BigNumber(minFee).lte(tx.fee)) return [];
|
|
60
|
+
return [{
|
|
61
|
+
message: `Fee ${tx.fee} is too low, minimum fee for this transaction is ${minFee}`,
|
|
62
|
+
key: 'InsufficientFee',
|
|
63
|
+
checkedKeys: ['fee']
|
|
64
|
+
}];
|
|
65
|
+
}, (_ref6, _ref7) => {
|
|
66
|
+
let {
|
|
67
|
+
ttl
|
|
68
|
+
} = _ref6;
|
|
69
|
+
let {
|
|
70
|
+
height
|
|
71
|
+
} = _ref7;
|
|
72
|
+
if (ttl === undefined) return [];
|
|
73
|
+
ttl = +ttl;
|
|
74
|
+
if (ttl === 0 || ttl >= height) return [];
|
|
75
|
+
return [{
|
|
76
|
+
message: `TTL ${ttl} is already expired, current height is ${height}`,
|
|
77
|
+
key: 'ExpiredTTL',
|
|
78
|
+
checkedKeys: ['ttl']
|
|
79
|
+
}];
|
|
80
|
+
}, (_ref8, _ref9) => {
|
|
81
|
+
let {
|
|
82
|
+
amount,
|
|
83
|
+
fee,
|
|
84
|
+
nameFee,
|
|
85
|
+
tx
|
|
86
|
+
} = _ref8;
|
|
87
|
+
let {
|
|
88
|
+
account,
|
|
89
|
+
parentTxTypes,
|
|
90
|
+
txType
|
|
91
|
+
} = _ref9;
|
|
92
|
+
if ((amount ?? fee ?? nameFee) === undefined) return [];
|
|
93
|
+
const cost = new BigNumber(fee).plus(nameFee || 0).plus(amount || 0).plus(txType === TX_TYPE.payingFor ? tx.tx.encodedTx.tx.fee : 0).minus(parentTxTypes.includes(TX_TYPE.payingFor) ? fee : 0);
|
|
94
|
+
if (cost.lte(account.balance)) return [];
|
|
95
|
+
return [{
|
|
96
|
+
message: `Account balance ${account.balance} is not enough to execute the transaction that costs ${cost.toFixed()}`,
|
|
97
|
+
key: 'InsufficientBalance',
|
|
98
|
+
checkedKeys: ['amount', 'fee', 'nameFee']
|
|
99
|
+
}];
|
|
100
|
+
}, (_ref10, _ref11) => {
|
|
101
|
+
let {
|
|
102
|
+
nonce
|
|
103
|
+
} = _ref10;
|
|
104
|
+
let {
|
|
105
|
+
account,
|
|
106
|
+
parentTxTypes
|
|
107
|
+
} = _ref11;
|
|
108
|
+
if (nonce === undefined || parentTxTypes.includes(TX_TYPE.gaMeta)) return [];
|
|
109
|
+
nonce = +nonce;
|
|
110
|
+
const validNonce = account.nonce + 1;
|
|
111
|
+
if (nonce === validNonce) return [];
|
|
112
|
+
return [{ ...(nonce < validNonce ? {
|
|
113
|
+
message: `Nonce ${nonce} is already used, valid nonce is ${validNonce}`,
|
|
114
|
+
key: 'NonceAlreadyUsed'
|
|
115
|
+
} : {
|
|
116
|
+
message: `Nonce ${nonce} is too high, valid nonce is ${validNonce}`,
|
|
117
|
+
key: 'NonceHigh'
|
|
118
|
+
}),
|
|
119
|
+
checkedKeys: ['nonce']
|
|
120
|
+
}];
|
|
121
|
+
}, _ref12 => {
|
|
122
|
+
let {
|
|
123
|
+
gasPrice
|
|
124
|
+
} = _ref12;
|
|
125
|
+
if (gasPrice === undefined) return [];
|
|
126
|
+
if (gasPrice >= MIN_GAS_PRICE) return [];
|
|
127
|
+
return [{
|
|
128
|
+
message: `Gas price ${gasPrice} must be bigger then ${MIN_GAS_PRICE}`,
|
|
129
|
+
key: 'MinGasPrice',
|
|
130
|
+
checkedKeys: ['gasPrice']
|
|
131
|
+
}];
|
|
132
|
+
}, (_ref13, _ref14) => {
|
|
133
|
+
let {
|
|
134
|
+
ctVersion,
|
|
135
|
+
abiVersion
|
|
136
|
+
} = _ref13;
|
|
137
|
+
let {
|
|
138
|
+
txType,
|
|
139
|
+
node
|
|
140
|
+
} = _ref14;
|
|
141
|
+
const {
|
|
142
|
+
consensusProtocolVersion
|
|
143
|
+
} = node.getNodeInfo();
|
|
144
|
+
const protocol = PROTOCOL_VM_ABI[consensusProtocolVersion];
|
|
145
|
+
if (!protocol) throw new Error(`Unsupported protocol: ${consensusProtocolVersion}`); // If not contract create tx
|
|
146
|
+
|
|
147
|
+
if (!ctVersion) ctVersion = {
|
|
148
|
+
abiVersion
|
|
194
149
|
};
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (!VALIDATORS[validatorKey](data)) acc.push({
|
|
210
|
-
msg: msg(data),
|
|
211
|
-
txKey: txKey,
|
|
212
|
-
type: type
|
|
213
|
-
});
|
|
214
|
-
return acc;
|
|
215
|
-
}, []);
|
|
216
|
-
};
|
|
217
|
-
/**
|
|
218
|
-
* Unpack and verify transaction (verify nonce, ttl, fee, signature, account balance)
|
|
219
|
-
* @function
|
|
220
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/validator
|
|
221
|
-
*
|
|
222
|
-
* @param {String} txHash Base64Check transaction hash
|
|
223
|
-
* @param {Object} [options={}] Options
|
|
224
|
-
* @param {String} [options.networkId] networkId Use in signature verification
|
|
225
|
-
* @return {Promise<Object>} Object with verification errors and warnings
|
|
226
|
-
*/
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
function unpackAndVerify(_x3) {
|
|
230
|
-
return _unpackAndVerify.apply(this, arguments);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function _unpackAndVerify() {
|
|
234
|
-
_unpackAndVerify = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(txHash) {
|
|
235
|
-
var _ref18,
|
|
236
|
-
networkId,
|
|
237
|
-
_unpackTx,
|
|
238
|
-
unpackedTx,
|
|
239
|
-
rlpEncoded,
|
|
240
|
-
txType,
|
|
241
|
-
_context7,
|
|
242
|
-
_unpackedTx$encodedTx,
|
|
243
|
-
_txType,
|
|
244
|
-
tx,
|
|
245
|
-
signatures,
|
|
246
|
-
rlpEncodedTx,
|
|
247
|
-
_args2 = arguments;
|
|
248
|
-
|
|
249
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context8) {
|
|
250
|
-
while (1) {
|
|
251
|
-
switch (_context8.prev = _context8.next) {
|
|
252
|
-
case 0:
|
|
253
|
-
_ref18 = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {}, networkId = _ref18.networkId;
|
|
254
|
-
_unpackTx = unpackTx(txHash), unpackedTx = _unpackTx.tx, rlpEncoded = _unpackTx.rlpEncoded, txType = _unpackTx.txType;
|
|
255
|
-
|
|
256
|
-
if (!(+unpackedTx.tag === OBJECT_TAG_SIGNED_TRANSACTION)) {
|
|
257
|
-
_context8.next = 13;
|
|
258
|
-
break;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
_unpackedTx$encodedTx = unpackedTx.encodedTx, _txType = _unpackedTx$encodedTx.txType, tx = _unpackedTx$encodedTx.tx;
|
|
262
|
-
signatures = _mapInstanceProperty(_context7 = unpackedTx.signatures).call(_context7, function (raw) {
|
|
263
|
-
return {
|
|
264
|
-
raw: raw,
|
|
265
|
-
hash: encode(raw, 'sg')
|
|
266
|
-
};
|
|
267
|
-
});
|
|
268
|
-
rlpEncodedTx = unpackedTx.encodedTx.rlpEncoded;
|
|
269
|
-
_context8.next = 8;
|
|
270
|
-
return this.verifyTx({
|
|
271
|
-
tx: tx,
|
|
272
|
-
signatures: signatures,
|
|
273
|
-
rlpEncoded: rlpEncodedTx
|
|
274
|
-
}, networkId);
|
|
275
|
-
|
|
276
|
-
case 8:
|
|
277
|
-
_context8.t0 = _context8.sent;
|
|
278
|
-
_context8.t1 = tx;
|
|
279
|
-
_context8.t2 = signatures;
|
|
280
|
-
_context8.t3 = _txType;
|
|
281
|
-
return _context8.abrupt("return", {
|
|
282
|
-
validation: _context8.t0,
|
|
283
|
-
tx: _context8.t1,
|
|
284
|
-
signatures: _context8.t2,
|
|
285
|
-
txType: _context8.t3
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
case 13:
|
|
289
|
-
_context8.next = 15;
|
|
290
|
-
return this.verifyTx({
|
|
291
|
-
tx: unpackedTx,
|
|
292
|
-
rlpEncoded: rlpEncoded
|
|
293
|
-
}, networkId);
|
|
294
|
-
|
|
295
|
-
case 15:
|
|
296
|
-
_context8.t4 = _context8.sent;
|
|
297
|
-
_context8.t5 = unpackedTx;
|
|
298
|
-
_context8.t6 = txType;
|
|
299
|
-
return _context8.abrupt("return", {
|
|
300
|
-
validation: _context8.t4,
|
|
301
|
-
tx: _context8.t5,
|
|
302
|
-
txType: _context8.t6
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
case 19:
|
|
306
|
-
case "end":
|
|
307
|
-
return _context8.stop();
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}, _callee2, this);
|
|
311
|
-
}));
|
|
312
|
-
return _unpackAndVerify.apply(this, arguments);
|
|
313
|
-
}
|
|
150
|
+
const txProtocol = protocol[txType];
|
|
151
|
+
if (!txProtocol) return [];
|
|
152
|
+
|
|
153
|
+
if (Object.entries(ctVersion).some(_ref15 => {
|
|
154
|
+
let [key, value] = _ref15;
|
|
155
|
+
return !txProtocol[key].includes(+value);
|
|
156
|
+
})) {
|
|
157
|
+
return [{
|
|
158
|
+
message: `ABI/VM version ${JSON.stringify(ctVersion)} is wrong, supported is: ${JSON.stringify(txProtocol)}`,
|
|
159
|
+
key: 'VmAndAbiVersionMismatch',
|
|
160
|
+
checkedKeys: ['ctVersion', 'abiVersion']
|
|
161
|
+
}];
|
|
162
|
+
}
|
|
314
163
|
|
|
315
|
-
|
|
316
|
-
|
|
164
|
+
return [];
|
|
165
|
+
}];
|
|
317
166
|
|
|
318
|
-
|
|
319
|
-
return tx[key];
|
|
320
|
-
})].replace('ok_', 'ak_');
|
|
321
|
-
};
|
|
167
|
+
const getSenderAddress = tx => ['senderId', 'accountId', 'ownerId', 'callerId', 'oracleId', 'fromId', 'initiator', 'gaId', 'payerId'].map(key => tx[key]).filter(a => a).map(a => a.replace(/^ok_/, 'ak_'))[0];
|
|
322
168
|
/**
|
|
323
|
-
*
|
|
169
|
+
* Transaction Validator
|
|
170
|
+
* This function validates some of transaction properties,
|
|
171
|
+
* to make sure it can be posted it to the chain
|
|
324
172
|
* @function
|
|
325
173
|
* @alias module:@aeternity/aepp-sdk/es/tx/validator
|
|
326
|
-
*
|
|
327
|
-
* @param {
|
|
328
|
-
* @param {
|
|
329
|
-
* @param {
|
|
330
|
-
* @
|
|
331
|
-
* @
|
|
332
|
-
* @return {Promise<Array>} Object with verification errors and warnings
|
|
174
|
+
* @rtype (tx: String, node) => void
|
|
175
|
+
* @param {String} transaction Base64Check-encoded transaction
|
|
176
|
+
* @param {Object} node Node to validate transaction against
|
|
177
|
+
* @param {String[]} [parentTxTypes] Types of parent transactions
|
|
178
|
+
* @return {Promise<Object[]>} Array with verification errors
|
|
179
|
+
* @example const errors = await verifyTransaction(transaction, node)
|
|
333
180
|
*/
|
|
334
181
|
|
|
335
182
|
|
|
336
|
-
function
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
gas = Object.prototype.hasOwnProperty.call(tx, 'gas') ? +tx.gas : 0;
|
|
361
|
-
txType = OBJECT_ID_TX_TYPE[+tx.tag];
|
|
362
|
-
_context10.t0 = _objectSpread;
|
|
363
|
-
_context10.t1 = _objectSpread;
|
|
364
|
-
_context10.t2 = _objectSpread;
|
|
365
|
-
_context10.t3 = {
|
|
366
|
-
minFee: calculateFee(0, txType, {
|
|
367
|
-
gas: gas,
|
|
368
|
-
params: tx,
|
|
369
|
-
showWarning: false,
|
|
370
|
-
vsn: tx.VSN
|
|
371
|
-
})
|
|
372
|
-
};
|
|
373
|
-
_context10.next = 11;
|
|
374
|
-
return resolveDataForBase(this, {
|
|
375
|
-
ownerPublicKey: ownerPublicKey
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
case 11:
|
|
379
|
-
_context10.t4 = _context10.sent;
|
|
380
|
-
_context10.t5 = (0, _context10.t2)(_context10.t3, _context10.t4);
|
|
381
|
-
_context10.t6 = tx;
|
|
382
|
-
_context10.t7 = (0, _context10.t1)(_context10.t5, _context10.t6);
|
|
383
|
-
_context10.t8 = {};
|
|
384
|
-
_context10.t9 = {
|
|
385
|
-
txType: txType
|
|
386
|
-
};
|
|
387
|
-
resolvedData = (0, _context10.t0)(_context10.t7, _context10.t8, _context10.t9);
|
|
388
|
-
signatureVerification = signatures && signatures.length ? verifySchema(SIGNATURE_VERIFICATION_SCHEMA, {
|
|
389
|
-
rlpEncoded: rlpEncoded,
|
|
390
|
-
signature: signatures[0].raw,
|
|
391
|
-
ownerPublicKey: ownerPublicKey,
|
|
392
|
-
networkId: networkId
|
|
393
|
-
}) : [];
|
|
394
|
-
baseVerification = verifySchema(BASE_VERIFICATION_SCHEMA, resolvedData);
|
|
395
|
-
return _context10.abrupt("return", _concatInstanceProperty(_context9 = []).call(_context9, _toConsumableArray(baseVerification), _toConsumableArray(signatureVerification), _toConsumableArray(customVerification(txType, resolvedData))));
|
|
396
|
-
|
|
397
|
-
case 21:
|
|
398
|
-
case "end":
|
|
399
|
-
return _context10.stop();
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}, _callee3, this);
|
|
403
|
-
}));
|
|
404
|
-
return _verifyTx.apply(this, arguments);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
function customVerification(txType, data) {
|
|
408
|
-
switch (txType) {
|
|
409
|
-
case TX_TYPE.contractCreate:
|
|
410
|
-
case TX_TYPE.contractCall:
|
|
411
|
-
case TX_TYPE.oracleRegister:
|
|
412
|
-
return verifySchema(CONTRACT_VERIFICATION_SCHEMA, data);
|
|
413
|
-
|
|
414
|
-
case TX_TYPE.nameClaim:
|
|
415
|
-
return verifySchema(NAME_CLAIM_VERIFICATION_SCHEMA, data);
|
|
416
|
-
|
|
417
|
-
default:
|
|
418
|
-
return [];
|
|
419
|
-
}
|
|
183
|
+
export default async function verifyTransaction(transaction, node) {
|
|
184
|
+
let parentTxTypes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
185
|
+
const {
|
|
186
|
+
tx,
|
|
187
|
+
txType
|
|
188
|
+
} = unpackTx(transaction);
|
|
189
|
+
const address = getSenderAddress(tx) ?? (txType === TX_TYPE.signed ? getSenderAddress(tx.encodedTx.tx) : null);
|
|
190
|
+
const [account, height] = await Promise.all([address && node.api.getAccountByPubkey(address).catch(() => ({
|
|
191
|
+
id: address,
|
|
192
|
+
balance: new BigNumber(0),
|
|
193
|
+
nonce: 0
|
|
194
|
+
})), node.api.getCurrentKeyBlockHeight().then(_ref16 => {
|
|
195
|
+
let {
|
|
196
|
+
height
|
|
197
|
+
} = _ref16;
|
|
198
|
+
return height;
|
|
199
|
+
})]);
|
|
200
|
+
return (await Promise.all(validators.map(v => v(tx, {
|
|
201
|
+
txType,
|
|
202
|
+
node,
|
|
203
|
+
account,
|
|
204
|
+
height,
|
|
205
|
+
parentTxTypes
|
|
206
|
+
})))).flat();
|
|
420
207
|
}
|
|
421
|
-
/**
|
|
422
|
-
* Transaction Validator Stamp
|
|
423
|
-
* This stamp give us possibility to unpack and validate some of transaction properties,
|
|
424
|
-
* to make sure we can post it to the chain
|
|
425
|
-
* @function
|
|
426
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/validator
|
|
427
|
-
* @rtype Stamp
|
|
428
|
-
* @param {Object} [options={}] - Initializer object
|
|
429
|
-
* @param {Object} [options.url] - Node url
|
|
430
|
-
* @param {Object} [options.internalUrl] - Node internal url
|
|
431
|
-
* @return {Object} Transaction Validator instance
|
|
432
|
-
* @example TransactionValidator({url: 'https://testnet.aeternity.io'})
|
|
433
|
-
*/
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
var TransactionValidator = NodePool.compose({
|
|
437
|
-
methods: {
|
|
438
|
-
verifyTx: verifyTx,
|
|
439
|
-
unpackAndVerify: unpackAndVerify
|
|
440
|
-
}
|
|
441
|
-
});
|
|
442
|
-
export default TransactionValidator;
|
|
443
208
|
//# sourceMappingURL=validator.js.map
|