diff --git a/dashwallet.js b/dashwallet.js index 05e3c06..44c386c 100644 --- a/dashwallet.js +++ b/dashwallet.js @@ -1375,6 +1375,8 @@ err.code = "INCONCEIVABLE"; throw err; } + txInfoRaw.inputs.sort(DashTx.sortInputs); + txInfoRaw.outputs.sort(DashTx.sortOutputs); let dashTx = DashTx.create(); let keys; @@ -1542,13 +1544,11 @@ } let payAddresses = addrsInfo.addresses.slice(0); - fauxTxos.sort(Wallet.sortInputs); for (let output of outputs) { output = Object.assign(output, { address: payAddresses.pop(), }); } - outputs.sort(Wallet.sortOutputs); for (let output of outputs) { //@ts-ignore TODO bad export @@ -3085,84 +3085,6 @@ return usable; } - /** - * Sort deterministic by Tx, VOut, Addr (all Asc), and Sats (Dsc) - * - * Note: it's important that it's deterministic (or random) - * to maintain the cash-like quality transfer - rather than - * by payee and change, which leaks more information to bad actors. - * - * TODO move to DashTx - * - * @param {CoreUtxo} a - * @param {CoreUtxo} b - * @returns Number - */ - Wallet.sortInputs = function (a, b) { - // Ascending TxID (Lexicographical) - if (a.txId > b.txId) { - return 1; - } - if (a.txId < b.txId) { - return -1; - } - - // Ascending Vout (Numerical) - let indexDiff = a.outputIndex - b.outputIndex; - if (indexDiff !== 0) { - return indexDiff; - } - - // Ascending Address (Lexicographical) - if (a.address > b.address) { - return 1; - } - if (a.address < b.address) { - return -1; - } - - // Descending Sats (Numberical) - return b.satoshis - a.satoshis; - }; - - /** - * Sort deterministic by Addr (all Asc), and Sats (Dsc) - * - * Note: it's important that it's deterministic (or random) - * to maintain the cash-like quality transfer - rather than - * by payee and change, which leaks more information to bad actors. - * - * TODO move to DashTx - * - * @param {TxOutput} a - * @param {TxOutput} b - * @returns Number - */ - Wallet.sortOutputs = function (a, b) { - if (a.pubKeyHash && b.pubKeyHash) { - // Ascending PKH (Lexicographical) - if (a.pubKeyHash > b.pubKeyHash) { - return 1; - } - if (a.pubKeyHash < b.pubKeyHash) { - return -1; - } - } - - if (a.address && b.address) { - // Ascending Address (Lexicographical) - if (a.address > b.address) { - return 1; - } - if (a.address < b.address) { - return -1; - } - } - - // Descending Sats (Numberical) - return b.satoshis - a.satoshis; - }; - /** * Sort DenomInfos first by lowest face value first * @param {DenomInfo} a diff --git a/package.json b/package.json index 6526121..c1a1cea 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,6 @@ "bin": {}, "files": [ "index.js", - "lib/", "dashwallet.js" ], "scripts": {