Skip to content

Commit 5209994

Browse files
committed
Fix issue with key replacement in address derivation
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.
1 parent 1fa2972 commit 5209994

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

bitcoin_client_js/src/lib/appClient.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,9 @@ export class AppClient {
441441
}
442442
// Replace index:
443443
expression = expression.replace(/\/\*/g, `/${addressIndex}`);
444-
// Replace origin:
445-
for (let i = 0; i < walletPolicy.keys.length; i++)
444+
// Replace origin in reverse order to prevent
445+
// misreplacements, e.g., @10 being mistaken for @1 and leaving a 0.
446+
for (let i = walletPolicy.keys.length - 1; i >= 0; i--)
446447
expression = expression.replace(
447448
new RegExp(`@${i}`, 'g'),
448449
walletPolicy.keys[i]

0 commit comments

Comments
 (0)