mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-26 08:55:56 +01:00
FIX: capital bech32 addresses
This commit is contained in:
parent
8e291a9633
commit
fc11da2aae
9 changed files with 26 additions and 10 deletions
|
@ -824,6 +824,7 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet {
|
|||
}
|
||||
|
||||
weOwnAddress(address) {
|
||||
if (!address) return false;
|
||||
let cleanAddress = address;
|
||||
|
||||
if (this.segwitType === 'p2wpkh') {
|
||||
|
|
|
@ -242,15 +242,6 @@ export class AbstractHDWallet extends LegacyWallet {
|
|||
throw new Error('Not implemented');
|
||||
}
|
||||
|
||||
weOwnAddress(addr) {
|
||||
const hashmap = {};
|
||||
for (const a of this.usedAddresses) {
|
||||
hashmap[a] = 1;
|
||||
}
|
||||
|
||||
return hashmap[addr] === 1;
|
||||
}
|
||||
|
||||
_getDerivationPathByAddress(address) {
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
|
|
|
@ -465,6 +465,7 @@ export class LegacyWallet extends AbstractWallet {
|
|||
}
|
||||
|
||||
weOwnAddress(address) {
|
||||
if (!address) return false;
|
||||
let cleanAddress = address;
|
||||
|
||||
if (this.segwitType === 'p2wpkh') {
|
||||
|
|
|
@ -221,6 +221,8 @@ export class WatchOnlyWallet extends LegacyWallet {
|
|||
throw new Error('Not initialized');
|
||||
}
|
||||
|
||||
if (address && address.startsWith('BC1')) address = address.toLowerCase();
|
||||
|
||||
return this.getAddress() === address;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,11 @@ beforeAll(async () => {
|
|||
});
|
||||
|
||||
let _cachedHdWallet = false;
|
||||
|
||||
/**
|
||||
* @returns {Promise<HDSegwitBech32Wallet>}
|
||||
* @private
|
||||
*/
|
||||
async function _getHdWallet() {
|
||||
if (_cachedHdWallet) return _cachedHdWallet;
|
||||
_cachedHdWallet = new HDSegwitBech32Wallet();
|
||||
|
|
|
@ -43,6 +43,8 @@ describe('Bech32 Segwit HD (BIP84)', () => {
|
|||
assert.ok(hd.weOwnAddress('BC1QVD6W54SYDC08Z3802SVKXR7297EZ7CUSD6266P'));
|
||||
assert.ok(hd.weOwnAddress('bc1qt4t9xl2gmjvxgmp5gev6m8e6s9c85979ta7jeh'));
|
||||
assert.ok(!hd.weOwnAddress('1HjsSTnrwWzzEV2oi4r5MsAYENkTkrCtwL'));
|
||||
assert.ok(!hd.weOwnAddress('garbage'));
|
||||
assert.ok(!hd.weOwnAddress(false));
|
||||
|
||||
assert.strictEqual(hd.timeToRefreshBalance(), true);
|
||||
assert.ok(hd._lastTxFetch === 0);
|
||||
|
|
|
@ -44,6 +44,7 @@ describe('LegacyWallet', function () {
|
|||
w._address = '115fUy41sZkAG14CmdP1VbEKcNRZJWkUWG'; // hack internals
|
||||
assert.ok(w.weOwnAddress('115fUy41sZkAG14CmdP1VbEKcNRZJWkUWG'));
|
||||
assert.ok(!w.weOwnAddress('aaa'));
|
||||
assert.ok(!w.weOwnAddress(false));
|
||||
assert.ok(w.getBalance() === 0);
|
||||
assert.ok(w.getUnconfirmedBalance() === 0);
|
||||
assert.ok(w._lastBalanceFetch === 0);
|
||||
|
@ -126,6 +127,8 @@ describe('SegwitP2SHWallet', function () {
|
|||
assert.ok(l.getAddress() === '34AgLJhwXrvmkZS1o5TrcdeevMt22Nar53', 'expected ' + l.getAddress());
|
||||
assert.ok(l.getAddress() === (await l.getAddressAsync()));
|
||||
assert.ok(l.weOwnAddress('34AgLJhwXrvmkZS1o5TrcdeevMt22Nar53'));
|
||||
assert.ok(!l.weOwnAddress('garbage'));
|
||||
assert.ok(!l.weOwnAddress(false));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -134,6 +137,9 @@ describe('SegwitBech32Wallet', function () {
|
|||
const w = new SegwitBech32Wallet();
|
||||
w._address = 'bc1qn887fmetaytw4vj68vsh529ft408q8j9x3dndc';
|
||||
assert.ok(w.weOwnAddress('bc1qn887fmetaytw4vj68vsh529ft408q8j9x3dndc'));
|
||||
assert.ok(w.weOwnAddress('BC1QN887FMETAYTW4VJ68VSH529FT408Q8J9X3DNDC'));
|
||||
assert.ok(!w.weOwnAddress('garbage'));
|
||||
assert.ok(!w.weOwnAddress(false));
|
||||
await w.fetchBalance();
|
||||
assert.strictEqual(w.getBalance(), 100000);
|
||||
});
|
||||
|
@ -173,9 +179,12 @@ describe('SegwitBech32Wallet', function () {
|
|||
});
|
||||
|
||||
it('can fetch TXs', async () => {
|
||||
const w = new LegacyWallet();
|
||||
const w = new SegwitBech32Wallet();
|
||||
w._address = 'bc1qn887fmetaytw4vj68vsh529ft408q8j9x3dndc';
|
||||
assert.ok(w.weOwnAddress('bc1qn887fmetaytw4vj68vsh529ft408q8j9x3dndc'));
|
||||
assert.ok(w.weOwnAddress('BC1QN887FMETAYTW4VJ68VSH529FT408Q8J9X3DNDC'));
|
||||
assert.ok(!w.weOwnAddress('garbage'));
|
||||
assert.ok(!w.weOwnAddress(false));
|
||||
await w.fetchTransactions();
|
||||
assert.strictEqual(w.getTransactions().length, 1);
|
||||
|
||||
|
|
|
@ -63,6 +63,9 @@ describe('Watch only wallet', () => {
|
|||
assert.strictEqual(w.getAddress(), 'bc1quhnve8q4tk3unhmjts7ymxv8cd6w9xv8wy29uv');
|
||||
assert.strictEqual(await w.getAddressAsync(), 'bc1quhnve8q4tk3unhmjts7ymxv8cd6w9xv8wy29uv');
|
||||
assert.ok(w.weOwnAddress('bc1quhnve8q4tk3unhmjts7ymxv8cd6w9xv8wy29uv'));
|
||||
assert.ok(w.weOwnAddress('BC1QUHNVE8Q4TK3UNHMJTS7YMXV8CD6W9XV8WY29UV'));
|
||||
assert.ok(!w.weOwnAddress('garbage'));
|
||||
assert.ok(!w.weOwnAddress(false));
|
||||
await w.fetchTransactions();
|
||||
|
||||
for (const tx of w.getTransactions()) {
|
||||
|
|
|
@ -113,6 +113,8 @@ describe('HDAezeedWallet', () => {
|
|||
watchOnly.init();
|
||||
assert.strictEqual(watchOnly._getExternalAddressByIndex(0), aezeed._getExternalAddressByIndex(0));
|
||||
assert.ok(watchOnly.weOwnAddress('bc1qdjj7lhj9lnjye7xq3dzv3r4z0cta294xy78txn'));
|
||||
assert.ok(!watchOnly.weOwnAddress('garbage'));
|
||||
assert.ok(!watchOnly.weOwnAddress(false));
|
||||
});
|
||||
|
||||
it('can sign and verify messages', async () => {
|
||||
|
|
Loading…
Add table
Reference in a new issue