REF: remove obsolete dep buffer-reverse

This commit is contained in:
overtorment 2024-02-25 21:57:04 +00:00
parent b612510bdc
commit 8e03eae63a
8 changed files with 24 additions and 40 deletions

View file

@ -7,7 +7,6 @@ import WidgetCommunication from './WidgetCommunication';
import presentAlert from '../components/Alert';
const bitcoin = require('bitcoinjs-lib');
const ElectrumClient = require('electrum-client');
const reverse = require('buffer-reverse');
const BigNumber = require('bignumber.js');
const net = require('net');
@ -333,7 +332,7 @@ module.exports.getBalanceByAddress = async function (address) {
if (!mainClient) throw new Error('Electrum client is not connected');
const script = bitcoin.address.toOutputScript(address);
const hash = bitcoin.crypto.sha256(script);
const reversedHash = Buffer.from(reverse(hash));
const reversedHash = Buffer.from(hash).reverse();
const balance = await mainClient.blockchainScripthash_getBalance(reversedHash.toString('hex'));
balance.addr = address;
return balance;
@ -362,7 +361,7 @@ module.exports.getTransactionsByAddress = async function (address) {
if (!mainClient) throw new Error('Electrum client is not connected');
const script = bitcoin.address.toOutputScript(address);
const hash = bitcoin.crypto.sha256(script);
const reversedHash = Buffer.from(reverse(hash));
const reversedHash = Buffer.from(hash).reverse();
const history = await mainClient.blockchainScripthash_getHistory(reversedHash.toString('hex'));
for (const h of history || []) {
if (h.tx_hash) txhashHeightCache[h.tx_hash] = h.height; // cache tx height
@ -380,7 +379,7 @@ module.exports.getMempoolTransactionsByAddress = async function (address) {
if (!mainClient) throw new Error('Electrum client is not connected');
const script = bitcoin.address.toOutputScript(address);
const hash = bitcoin.crypto.sha256(script);
const reversedHash = Buffer.from(reverse(hash));
const reversedHash = Buffer.from(hash).reverse();
return mainClient.blockchainScripthash_getMempool(reversedHash.toString('hex'));
};
@ -477,7 +476,7 @@ module.exports.multiGetBalanceByAddress = async function (addresses, batchsize)
for (const addr of chunk) {
const script = bitcoin.address.toOutputScript(addr);
const hash = bitcoin.crypto.sha256(script);
let reversedHash = Buffer.from(reverse(hash));
let reversedHash = Buffer.from(hash).reverse();
reversedHash = reversedHash.toString('hex');
scripthashes.push(reversedHash);
scripthash2addr[reversedHash] = addr;
@ -523,7 +522,7 @@ module.exports.multiGetUtxoByAddress = async function (addresses, batchsize) {
for (const addr of chunk) {
const script = bitcoin.address.toOutputScript(addr);
const hash = bitcoin.crypto.sha256(script);
let reversedHash = Buffer.from(reverse(hash));
let reversedHash = Buffer.from(hash).reverse();
reversedHash = reversedHash.toString('hex');
scripthashes.push(reversedHash);
scripthash2addr[reversedHash] = addr;
@ -566,7 +565,7 @@ module.exports.multiGetHistoryByAddress = async function (addresses, batchsize)
for (const addr of chunk) {
const script = bitcoin.address.toOutputScript(addr);
const hash = bitcoin.crypto.sha256(script);
let reversedHash = Buffer.from(reverse(hash));
let reversedHash = Buffer.from(hash).reverse();
reversedHash = reversedHash.toString('hex');
scripthashes.push(reversedHash);
scripthash2addr[reversedHash] = addr;
@ -1039,7 +1038,7 @@ function txhexToElectrumTransaction(txhex) {
if (inn.witness[1]) txinwitness.push(inn.witness[1].toString('hex'));
ret.vin.push({
txid: reverse(inn.hash).toString('hex'),
txid: Buffer.from(inn.hash).reverse().toString('hex'),
vout: inn.index,
scriptSig: { hex: inn.script.toString('hex'), asm: '' },
txinwitness,

View file

@ -2,7 +2,6 @@ import { HDSegwitBech32Wallet } from './wallets/hd-segwit-bech32-wallet';
import { SegwitBech32Wallet } from './wallets/segwit-bech32-wallet';
const bitcoin = require('bitcoinjs-lib');
const BlueElectrum = require('../blue_modules/BlueElectrum');
const reverse = require('buffer-reverse');
const BigNumber = require('bignumber.js');
/**
@ -150,7 +149,7 @@ export class HDSegwitBech32Transaction {
const prevInputs = [];
for (const inp of this._txDecoded.ins) {
let reversedHash = Buffer.from(reverse(inp.hash));
let reversedHash = Buffer.from(inp.hash).reverse();
reversedHash = reversedHash.toString('hex');
prevInputs.push(reversedHash);
}
@ -161,7 +160,7 @@ export class HDSegwitBech32Transaction {
let wentIn = 0;
const utxos = [];
for (const inp of this._txDecoded.ins) {
let reversedHash = Buffer.from(reverse(inp.hash));
let reversedHash = Buffer.from(inp.hash).reverse();
reversedHash = reversedHash.toString('hex');
if (prevTransactions[reversedHash] && prevTransactions[reversedHash].vout && prevTransactions[reversedHash].vout[inp.index]) {
let value = prevTransactions[reversedHash].vout[inp.index].value;
@ -228,7 +227,7 @@ export class HDSegwitBech32Transaction {
const spentUtxos = this._wallet.getDerivedUtxoFromOurTransaction(true);
for (const inp of this._txDecoded.ins) {
const txidInUtxo = reverse(inp.hash).toString('hex');
const txidInUtxo = Buffer.from(inp.hash).reverse().toString('hex');
let found = false;
for (const spentU of spentUtxos) {

View file

@ -19,7 +19,6 @@ import { CreateTransactionResult, CreateTransactionUtxo, Transaction, Utxo } fro
const ECPair = ECPairFactory(ecc);
const BlueElectrum: typeof BlueElectrumNs = require('../../blue_modules/BlueElectrum');
const reverse = require('buffer-reverse');
const bip32 = BIP32Factory(ecc);
const bip47 = BIP47Factory(ecc);
@ -1165,7 +1164,7 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet {
let masterFingerprintHex = Number(masterFingerprint).toString(16);
if (masterFingerprintHex.length < 8) masterFingerprintHex = '0' + masterFingerprintHex; // conversion without explicit zero might result in lost byte
const hexBuffer = Buffer.from(masterFingerprintHex, 'hex');
masterFingerprintBuffer = Buffer.from(reverse(hexBuffer));
masterFingerprintBuffer = Buffer.from(hexBuffer).reverse();
} else {
masterFingerprintBuffer = Buffer.from([0x00, 0x00, 0x00, 0x00]);
}
@ -1191,7 +1190,7 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet {
let masterFingerprintHex = Number(masterFingerprint).toString(16);
if (masterFingerprintHex.length < 8) masterFingerprintHex = '0' + masterFingerprintHex; // conversion without explicit zero might result in lost byte
const hexBuffer = Buffer.from(masterFingerprintHex, 'hex');
masterFingerprintBuffer = Buffer.from(reverse(hexBuffer));
masterFingerprintBuffer = Buffer.from(hexBuffer).reverse();
} else {
masterFingerprintBuffer = Buffer.from([0x00, 0x00, 0x00, 0x00]);
}

View file

@ -3,7 +3,6 @@ import * as bip39 from 'bip39';
import * as bitcoin from 'bitcoinjs-lib';
import { Psbt, Transaction } from 'bitcoinjs-lib';
import b58 from 'bs58check';
import reverse from 'buffer-reverse';
import createHash from 'create-hash';
import { ECPairFactory } from 'ecpair';
import * as mn from 'electrum-mnemonic';
@ -1111,7 +1110,7 @@ export class MultisigHDWallet extends AbstractHDElectrumWallet {
// means we failed to get amounts that go in previously, so lets use utxo amounts cache we've build
// from non-segwit inputs
for (const inp of psbt.txInputs) {
const cacheKey = reverse(inp.hash).toString('hex') + ':' + inp.index;
const cacheKey = Buffer.from(inp.hash).reverse().toString('hex') + ':' + inp.index;
if (cacheUtxoAmounts[cacheKey]) goesIn += cacheUtxoAmounts[cacheKey];
}
}

25
package-lock.json generated
View file

@ -38,11 +38,10 @@
"bitcoinjs-message": "2.2.0",
"bolt11": "1.4.1",
"buffer": "6.0.3",
"buffer-reverse": "1.0.1",
"coinselect": "3.1.13",
"crypto-js": "4.2.0",
"dayjs": "1.11.10",
"detox": "20.17.1",
"detox": "20.18.3",
"ecpair": "2.0.1",
"ecurve": "1.0.6",
"electrum-client": "github:BlueWallet/rn-electrum-client#1bfe3cc",
@ -8402,11 +8401,6 @@
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ=="
},
"node_modules/buffer-reverse": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/buffer-reverse/-/buffer-reverse-1.0.1.tgz",
"integrity": "sha512-M87YIUBsZ6N924W57vDwT/aOu8hw7ZgdByz6ijksLjmHJELBASmYTTlNHRgjE+pTsT9oJXGaDSgqqwfdHotDUg=="
},
"node_modules/buffer-xor": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz",
@ -9646,9 +9640,9 @@
}
},
"node_modules/detox": {
"version": "20.17.1",
"resolved": "https://registry.npmjs.org/detox/-/detox-20.17.1.tgz",
"integrity": "sha512-10pey6CR9D5GSloRkH60ObBGZ8VS11H7iuBNY7qq6jO2swiqqckHhPLRXfH9+WGR7l3vDnfU+G/gQs7JxQkJwA==",
"version": "20.18.3",
"resolved": "https://registry.npmjs.org/detox/-/detox-20.18.3.tgz",
"integrity": "sha512-ssC7pWLDOs48Rocu7TDdLaYWiDWF5A8EAf/YcCsseHIqAqr6ECX6Hve8MIh3wUkPGYWoZaJHQfT9cyZjklt8AQ==",
"hasInstallScript": true,
"dependencies": {
"ajv": "^8.6.3",
@ -28971,11 +28965,6 @@
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ=="
},
"buffer-reverse": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/buffer-reverse/-/buffer-reverse-1.0.1.tgz",
"integrity": "sha512-M87YIUBsZ6N924W57vDwT/aOu8hw7ZgdByz6ijksLjmHJELBASmYTTlNHRgjE+pTsT9oJXGaDSgqqwfdHotDUg=="
},
"buffer-xor": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz",
@ -29910,9 +29899,9 @@
"dev": true
},
"detox": {
"version": "20.17.1",
"resolved": "https://registry.npmjs.org/detox/-/detox-20.17.1.tgz",
"integrity": "sha512-10pey6CR9D5GSloRkH60ObBGZ8VS11H7iuBNY7qq6jO2swiqqckHhPLRXfH9+WGR7l3vDnfU+G/gQs7JxQkJwA==",
"version": "20.18.3",
"resolved": "https://registry.npmjs.org/detox/-/detox-20.18.3.tgz",
"integrity": "sha512-ssC7pWLDOs48Rocu7TDdLaYWiDWF5A8EAf/YcCsseHIqAqr6ECX6Hve8MIh3wUkPGYWoZaJHQfT9cyZjklt8AQ==",
"requires": {
"ajv": "^8.6.3",
"bunyan": "^1.8.12",

View file

@ -124,7 +124,6 @@
"bitcoinjs-message": "2.2.0",
"bolt11": "1.4.1",
"buffer": "6.0.3",
"buffer-reverse": "1.0.1",
"coinselect": "3.1.13",
"crypto-js": "4.2.0",
"dayjs": "1.11.10",

View file

@ -271,6 +271,10 @@ export default class Selftest extends Component {
}
//
assertStrictEqual(Buffer.from('00ff0f', 'hex').reverse().toString('hex'), '0fff00');
//
} catch (Err) {
errorMessage += Err;
isOk = false;

View file

@ -1,4 +0,0 @@
declare module 'buffer-reverse' {
declare function reverse(buffer: Buffer): Buffer;
export default reverse;
}