Skip to content

Commit 9a8e122

Browse files
committed
REF: replace Buffer with Uint8Array where possible
- remove double conversion Uint8Array(hexToUint8Array(..)) - replace TextDecoder with uint8ArrayToString - remove redundant if block - revert unnecessary conversion in class/wallets/multisig-hd-wallet.ts - remove Buffer from ecc.isPoint
1 parent 67f440b commit 9a8e122

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

class/contact-list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class ContactList {
3232
const decoded = bitcoin.address.fromBech32(address);
3333
if (decoded.version === 0) return true;
3434
if (decoded.version === 1 && decoded.data.length !== 32) return false;
35-
if (decoded.version === 1 && !ecc.isPoint(Buffer.from(concatUint8Arrays([new Uint8Array([2]), decoded.data])))) return false;
35+
if (decoded.version === 1 && !ecc.isPoint(concatUint8Arrays([new Uint8Array([2]), decoded.data]))) return false;
3636
if (decoded.version > 1) return false;
3737
// ^^^ some day, when versions above 1 will be actually utilized, we would need to unhardcode this
3838
return true;

class/wallets/abstract-hd-electrum-wallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet {
16851685
bobBip47,
16861686
keyPair.privateKey as Buffer,
16871687
// txid is reversed, as well as output number
1688-
uint8ArrayToHex(new Uint8Array(hexToUint8Array(inputsTemp[0].txid)).reverse()) + uint8ArrayToHex(outputNumber),
1688+
uint8ArrayToHex(hexToUint8Array(inputsTemp[0].txid).reverse()) + outputNumber.toString('hex'),
16891689
);
16901690

16911691
// targets:

class/wallets/multisig-hd-wallet.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import ecc from '../../blue_modules/noble_ecc';
1313
import { decodeUR } from '../../blue_modules/ur';
1414
import { AbstractHDElectrumWallet } from './abstract-hd-electrum-wallet';
1515
import { CreateTransactionResult, CreateTransactionTarget, CreateTransactionUtxo } from './types';
16-
import { uint8ArrayToHex, hexToUint8Array, concatUint8Arrays } from '../../blue_modules/uint8array-extras';
16+
import { uint8ArrayToHex, hexToUint8Array, concatUint8Arrays, uint8ArrayToString } from '../../blue_modules/uint8array-extras';
1717

1818
const ECPair = ECPairFactory(ecc);
1919
const bip32 = BIP32Factory(ecc);
@@ -517,7 +517,7 @@ export class MultisigHDWallet extends AbstractHDElectrumWallet {
517517
if (secret.toUpperCase().startsWith('UR:BYTES')) {
518518
const decoded = decodeUR([secret]) as string;
519519
const b = hexToUint8Array(decoded);
520-
secret = new TextDecoder().decode(b);
520+
secret = uint8ArrayToString(b);
521521
}
522522

523523
// is it Coldcard json file?
@@ -629,10 +629,7 @@ export class MultisigHDWallet extends AbstractHDElectrumWallet {
629629
const re = /\[([^\]]+)\](.*)/;
630630
const m = s3[c].match(re);
631631
if (m && m.length === 3) {
632-
let hexFingerprint = m[1].split('/')[0];
633-
if (hexFingerprint.length === 8) {
634-
hexFingerprint = uint8ArrayToHex(hexToUint8Array(hexFingerprint));
635-
}
632+
const hexFingerprint = m[1].split('/')[0];
636633

637634
let path = 'm/' + m[1].split('/').slice(1).join('/').replace(/[h]/g, "'");
638635
if (path === 'm/') {
@@ -1071,7 +1068,7 @@ export class MultisigHDWallet extends AbstractHDElectrumWallet {
10711068
}
10721069

10731070
static isPathValid(path: string): boolean {
1074-
const root = bip32.fromSeed(Buffer.from(new Uint8Array(32)));
1071+
const root = bip32.fromSeed(Buffer.alloc(32));
10751072
try {
10761073
root.derivePath(path);
10771074
return true;

0 commit comments

Comments
 (0)