Skip to content

Commit

Permalink
fix bug on paymentcode index derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoacosta74 committed Oct 24, 2024
1 parent 1f7c179 commit 79cba8a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/wallet/qi-hdwallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1353,11 +1353,11 @@ export class QiHDWallet extends AbstractHDWallet {
const paymentCodeInfoArray = this._paymentCodeSendAddressMap.get(receiverPaymentCode);
const lastIndex = this._findLastUsedIndex(paymentCodeInfoArray, account, zone);

let addrIndex = lastIndex;
let addrIndex = lastIndex + 1;
for (let attempts = 0; attempts < MAX_ADDRESS_DERIVATION_ATTEMPTS; attempts++) {
const address = receiverPCodePublic.getPaymentAddress(walletPCodePrivate, addrIndex++);
const address = receiverPCodePublic.getPaymentAddress(walletPCodePrivate, addrIndex);
if (this.isValidAddressForZone(address, zone)) {
const pubkey = receiverPCodePublic.derivePaymentPublicKey(walletPCodePrivate, addrIndex - 1);
const pubkey = receiverPCodePublic.derivePaymentPublicKey(walletPCodePrivate, addrIndex);
const pcInfo: QiAddressInfo = {
address,
pubKey: hexlify(pubkey),
Expand All @@ -1375,6 +1375,7 @@ export class QiHDWallet extends AbstractHDWallet {
}
return pcInfo;
}
addrIndex++;
}

throw new Error(
Expand Down Expand Up @@ -1402,11 +1403,11 @@ export class QiHDWallet extends AbstractHDWallet {
const paymentCodeInfoArray = this._addressesMap.get(senderPaymentCode);
const lastIndex = this._findLastUsedIndex(paymentCodeInfoArray, account, zone);

let addrIndex = lastIndex;
let addrIndex = lastIndex + 1;
for (let attempts = 0; attempts < MAX_ADDRESS_DERIVATION_ATTEMPTS; attempts++) {
const address = walletPCodePrivate.getPaymentAddress(senderPCodePublic, addrIndex++);
const address = walletPCodePrivate.getPaymentAddress(senderPCodePublic, addrIndex);
if (this.isValidAddressForZone(address, zone)) {
const pubkey = walletPCodePrivate.derivePaymentPublicKey(senderPCodePublic, addrIndex - 1);
const pubkey = walletPCodePrivate.derivePaymentPublicKey(senderPCodePublic, addrIndex);
const pcInfo: QiAddressInfo = {
address,
pubKey: hexlify(pubkey),
Expand All @@ -1424,6 +1425,7 @@ export class QiHDWallet extends AbstractHDWallet {
}
return pcInfo;
}
addrIndex++;
}

throw new Error(
Expand Down

0 comments on commit 79cba8a

Please sign in to comment.