Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BTC-1553: fix isValidAddress by returning false for valid cashaddr bch addresses #5019

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kcheng-bitgo
Copy link
Contributor

@kcheng-bitgo kcheng-bitgo commented Oct 11, 2024

TICKET: BTC-1553
Previously, isValidAddress verified the address by converting it to script and back. However, the previous implementation converts the script back to the legacy address and compares it against the original address. Thus, if the original was cashaddr format, it would fail. Fix this by generating addresses in all formats from the script and check if the original address is included.

@kcheng-bitgo kcheng-bitgo marked this pull request as ready for review October 11, 2024 16:34
@kcheng-bitgo kcheng-bitgo requested review from a team as code owners October 11, 2024 16:34
@kcheng-bitgo kcheng-bitgo changed the title BTC-1553: fix isValidAddress by using toCanonicalFormat BTC-1553: fix isValidAddress by returning false for valid cashaddr bch addresses Oct 11, 2024
@kcheng-bitgo kcheng-bitgo force-pushed the BTC-1553-false-invalid-bch-cashaddr branch from 6ffc0e7 to d64b6cd Compare October 11, 2024 19:03
Copy link
Contributor

@OttoAllmendinger OttoAllmendinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the commit title / PR title should state what it does: with your change we return true

@@ -415,10 +415,15 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
throw new Error('deprecated');
}

const formats = param && param.anyFormat ? undefined : ['default' as const];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So previously the anyFormat flag controlled this behavior. What you want to do here is make anyFormat = true the default.

try {
const script = utxolib.addressFormat.toOutputScriptTryFormats(address, this.network, formats);
return address === utxolib.address.fromOutputScript(script, this.network);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just remove this line - toOutputScriptsTryFormats will fail if it cannot parse the address with any of the formats

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants