FIX: Check Bech32 uppercase address

This commit is contained in:
João Vítor Dias 2021-05-19 12:52:56 -03:00 committed by GitHub
parent 163f275a06
commit 79f21946fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

View File

@ -824,11 +824,17 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet {
}
weOwnAddress(address) {
let cleanAddress = address;
if (this.segwitType === 'p2wpkh') {
cleanAddress = address.toLowerCase();
}
for (let c = 0; c < this.next_free_address_index + this.gap_limit; c++) {
if (this._getExternalAddressByIndex(c) === address) return true;
if (this._getExternalAddressByIndex(c) === cleanAddress) return true;
}
for (let c = 0; c < this.next_free_change_address_index + this.gap_limit; c++) {
if (this._getInternalAddressByIndex(c) === address) return true;
if (this._getInternalAddressByIndex(c) === cleanAddress) return true;
}
return false;
}

View File

@ -465,7 +465,13 @@ export class LegacyWallet extends AbstractWallet {
}
weOwnAddress(address) {
return this.getAddress() === address || this._address === address;
let cleanAddress = address;
if (this.segwitType === 'p2wpkh') {
cleanAddress = address.toLowerCase();
}
return this.getAddress() === cleanAddress || this._address === cleanAddress;
}
weOwnTransaction(txid) {

View File

@ -40,6 +40,7 @@ describe('Bech32 Segwit HD (BIP84)', () => {
assert.strictEqual(hd._getInternalAddressByIndex(1), 'bc1qwp58x4c9e5cplsnw5096qzdkae036ug7a34x3r');
assert.ok(hd.weOwnAddress('bc1qvd6w54sydc08z3802svkxr7297ez7cusd6266p'));
assert.ok(hd.weOwnAddress('BC1QVD6W54SYDC08Z3802SVKXR7297EZ7CUSD6266P'));
assert.ok(hd.weOwnAddress('bc1qt4t9xl2gmjvxgmp5gev6m8e6s9c85979ta7jeh'));
assert.ok(!hd.weOwnAddress('1HjsSTnrwWzzEV2oi4r5MsAYENkTkrCtwL'));