Skip to content

Commit

Permalink
Fix issue with key replacement in address derivation
Browse files Browse the repository at this point in the history
Revised the key replacement logic in the `validateAddress` function to prevent misinterpretation of key indices. The loop now iterates in reverse order to avoid scenarios where, for example, @10 is mistakenly replaced as @1, leaving an extra 0. This change ensures that the correct keys are replaced when deriving the wallet address.
  • Loading branch information
landabaso committed Jul 20, 2023
1 parent 1fa2972 commit 5209994
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bitcoin_client_js/src/lib/appClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,9 @@ export class AppClient {
}
// Replace index:
expression = expression.replace(/\/\*/g, `/${addressIndex}`);
// Replace origin:
for (let i = 0; i < walletPolicy.keys.length; i++)
// Replace origin in reverse order to prevent
// misreplacements, e.g., @10 being mistaken for @1 and leaving a 0.
for (let i = walletPolicy.keys.length - 1; i >= 0; i--)
expression = expression.replace(
new RegExp(`@${i}`, 'g'),
walletPolicy.keys[i]
Expand Down

0 comments on commit 5209994

Please sign in to comment.