1 | "use strict";
|
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3 | if (k2 === undefined) k2 = k;
|
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5 | }) : (function(o, m, k, k2) {
|
6 | if (k2 === undefined) k2 = k;
|
7 | o[k2] = m[k];
|
8 | }));
|
9 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11 | }) : function(o, v) {
|
12 | o["default"] = v;
|
13 | });
|
14 | var __importStar = (this && this.__importStar) || function (mod) {
|
15 | if (mod && mod.__esModule) return mod;
|
16 | var result = {};
|
17 | if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18 | __setModuleDefault(result, mod);
|
19 | return result;
|
20 | };
|
21 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
22 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
23 | };
|
24 | Object.defineProperty(exports, "__esModule", { value: true });
|
25 | const _ = __importStar(require("lodash"));
|
26 | const ripple_binary_codec_1 = __importDefault(require("ripple-binary-codec"));
|
27 | const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
28 | const errors_1 = require("../common/errors");
|
29 | const ripple_address_codec_1 = require("ripple-address-codec");
|
30 | const common_1 = require("../common");
|
31 | const hashes_1 = require("../common/hashes");
|
32 | function validateTransactionEquivalence(transactions) {
|
33 | const exampleTransaction = JSON.stringify(Object.assign(Object.assign({}, transactions[0]), { Signers: null }));
|
34 | if (transactions.slice(1).some(tx => JSON.stringify(Object.assign(Object.assign({}, tx), { Signers: null })) !== exampleTransaction)) {
|
35 | throw new errors_1.ValidationError('txJSON is not the same for all signedTransactions');
|
36 | }
|
37 | }
|
38 | function addressToBigNumber(address) {
|
39 | const hex = Buffer.from(ripple_address_codec_1.decodeAccountID(address)).toString('hex');
|
40 | return new bignumber_js_1.default(hex, 16);
|
41 | }
|
42 | function compareSigners(a, b) {
|
43 | return addressToBigNumber(a.Signer.Account).comparedTo(addressToBigNumber(b.Signer.Account));
|
44 | }
|
45 | function getTransactionWithAllSigners(transactions) {
|
46 | const sortedSigners = _.flatMap(transactions, tx => tx.Signers)
|
47 | .filter(signer => signer)
|
48 | .sort(compareSigners);
|
49 | return Object.assign(Object.assign({}, transactions[0]), { Signers: sortedSigners });
|
50 | }
|
51 | function combine(signedTransactions) {
|
52 | common_1.validate.combine({ signedTransactions });
|
53 | const transactions = signedTransactions.map(ripple_binary_codec_1.default.decode);
|
54 | validateTransactionEquivalence(transactions);
|
55 | const signedTransaction = ripple_binary_codec_1.default.encode(getTransactionWithAllSigners(transactions));
|
56 | return {
|
57 | signedTransaction: signedTransaction,
|
58 | id: hashes_1.computeBinaryTransactionHash(signedTransaction)
|
59 | };
|
60 | }
|
61 | exports.default = combine;
|
62 |
|
\ | No newline at end of file |