REF: fix ts lint errors

This commit is contained in:
overtorment 2023-03-15 21:30:00 +00:00
parent f9205eb3d6
commit 47b0177efe
3 changed files with 22 additions and 29 deletions

View file

@ -148,7 +148,7 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet {
return child.toWIF();
}
_getNodeAddressByIndex(node: number, index: number) {
_getNodeAddressByIndex(node: number, index: number): string {
index = index * 1; // cast to int
if (node === 0) {
if (this.external_addresses_cache[index]) return this.external_addresses_cache[index]; // cache hit
@ -170,22 +170,20 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet {
this._node1 = hdNode.derive(node);
}
let address;
let address: string;
if (node === 0) {
// @ts-ignore
address = this._hdNodeToAddress(this._node0.derive(index));
}
if (node === 1) {
} else {
// tbh the only possible else is node === 1
// @ts-ignore
address = this._hdNodeToAddress(this._node1.derive(index));
}
if (node === 0) {
return (this.external_addresses_cache[index] = address);
}
if (node === 1) {
} else {
// tbh the only possible else option is node === 1
return (this.internal_addresses_cache[index] = address);
}
}
@ -216,7 +214,7 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet {
throw new Error('Internal error: this._node0 or this._node1 is undefined');
}
_getExternalAddressByIndex(index: number) {
_getExternalAddressByIndex(index: number): string {
return this._getNodeAddressByIndex(0, index);
}
@ -1295,22 +1293,29 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet {
/**
* Creates Segwit Bech32 Bitcoin address
*
* @param hdNode
* @returns {String}
*/
static _nodeToBech32SegwitAddress(hdNode: BIP32Interface) {
_nodeToBech32SegwitAddress(hdNode: BIP32Interface): string {
return bitcoin.payments.p2wpkh({
pubkey: hdNode.publicKey,
}).address;
}
static _nodeToLegacyAddress(hdNode: BIP32Interface) {
_nodeToLegacyAddress(hdNode: BIP32Interface): string {
return bitcoin.payments.p2pkh({
pubkey: hdNode.publicKey,
}).address;
}
/**
* Creates Segwit P2SH Bitcoin address
*/
_nodeToP2shSegwitAddress(hdNode: BIP32Interface): string {
const { address } = bitcoin.payments.p2sh({
redeem: bitcoin.payments.p2wpkh({ pubkey: hdNode.publicKey }),
});
return address;
}
static _getTransactionsFromHistories(histories: Record<string, ElectrumHistory[]>) {
const txs = [];
for (const history of Object.values(histories)) {
@ -1496,7 +1501,7 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet {
}
_hdNodeToAddress(hdNode: BIP32Interface): string {
return this.constructor._nodeToBech32SegwitAddress(hdNode);
return this._nodeToBech32SegwitAddress(hdNode);
}
_getBIP47Address(paymentCode: string, index: number): string {

View file

@ -53,7 +53,7 @@ export class HDLegacyP2PKHWallet extends AbstractHDElectrumWallet {
}
_hdNodeToAddress(hdNode) {
return this.constructor._nodeToLegacyAddress(hdNode);
return this._nodeToLegacyAddress(hdNode);
}
async fetchUtxo() {

View file

@ -41,7 +41,7 @@ export class HDSegwitP2SHWallet extends AbstractHDElectrumWallet {
}
_hdNodeToAddress(hdNode) {
return this.constructor._nodeToP2shSegwitAddress(hdNode);
return this._nodeToP2shSegwitAddress(hdNode);
}
/**
@ -98,18 +98,6 @@ export class HDSegwitP2SHWallet extends AbstractHDElectrumWallet {
return psbt;
}
/**
* Creates Segwit P2SH Bitcoin address
* @param hdNode
* @returns {String}
*/
static _nodeToP2shSegwitAddress(hdNode) {
const { address } = bitcoin.payments.p2sh({
redeem: bitcoin.payments.p2wpkh({ pubkey: hdNode.publicKey }),
});
return address;
}
isSegwit() {
return true;
}