-
Notifications
You must be signed in to change notification settings - Fork 272
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
base: master
Are you sure you want to change the base?
Conversation
6ffc0e7
to
d64b6cd
Compare
There was a problem hiding this 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]; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
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.