Skip to content

Commit

Permalink
Exclude imported address from derivation and fix path deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
rileystephens28 committed Nov 14, 2024
1 parent 0af51fe commit eeb5c5f
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/wallet/qi-hdwallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ export class QiHDWallet extends AbstractHDWallet<QiAddressInfo> {
* @returns {string[]} The payment codes for all open channels.
*/
get openChannels(): string[] {
return Array.from(this._addressesMap.keys()).filter((key) => !key.startsWith('BIP44:'));
return Array.from(this._addressesMap.keys()).filter(
(key) => !key.startsWith('BIP44:') && key !== QiHDWallet.PRIVATE_KEYS_PATH,
);
}

/**
Expand Down Expand Up @@ -1268,7 +1270,6 @@ export class QiHDWallet extends AbstractHDWallet<QiAddressInfo> {
*/
public serialize(): SerializedQiHDWallet {
const hdwalletSerialized = super.serialize();

return {
...hdwalletSerialized,
outpoints: this._availableOutpoints,
Expand Down Expand Up @@ -1314,16 +1315,25 @@ export class QiHDWallet extends AbstractHDWallet<QiAddressInfo> {
);
}
};
// validate and import all the wallet addresses

// First, group addresses by derivation path
const addressesByPath = new Map<string, QiAddressInfo[]>();
for (const addressInfo of serialized.addresses) {
validateQiAddressInfo(addressInfo);
let key = addressInfo.derivationPath;
if (isHexString(key, 32)) {
key = QiHDWallet.PRIVATE_KEYS_PATH;
} else if (!key.startsWith('BIP44:')) {
wallet._addressesMap.set(key, []);
}
wallet._addressesMap.get(key)!.push(addressInfo);

if (!addressesByPath.has(key)) {
addressesByPath.set(key, []);
}
addressesByPath.get(key)!.push(addressInfo);
}

// Then, set all paths in the wallet's address map
for (const [key, addresses] of addressesByPath) {
wallet._addressesMap.set(key, addresses);
}

// validate and import the counter party payment code info
Expand Down

0 comments on commit eeb5c5f

Please sign in to comment.