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

IsBtcAddress not working with testnet addresses #639 #1386

Closed
vlapo opened this issue Jul 21, 2020 · 9 comments · Fixed by #1548
Closed

IsBtcAddress not working with testnet addresses #639 #1386

vlapo opened this issue Jul 21, 2020 · 9 comments · Fixed by #1548

Comments

@vlapo
Copy link

vlapo commented Jul 21, 2020

Describe the bug
Could you please check issue typestack/class-validator#639 ? Cc @michaelcerne

Additional context
Issue in class-validator lib

@vlapo vlapo added the 🐛 bug label Jul 21, 2020
@kathawala
Copy link

kathawala commented Jul 28, 2020

In addition to this, there are several issues with the current IsBtcAddress validator.

Currently the following addresses are all claimed to be valid by the IsBtcAddress validator but they are in fact invalid:

"17VZNX1SN5NlKa8UQFxwQbFeFc3iqRYhem" (any string with a lowercase 'L" will also be invalid but pass as valid)
"17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhemt"

There are probably others as well. Bitcoin addresses cannot be validated solely through regex (as is currently done in this library). Looking through this other bitcoin validator you can see that there is some checksumming and encoding, decoding that needs to take place when validating a bitcoin address. Is this library open to PRs which pull in dependencies for cryptography or base58 encoding / decoding?

@profnandaa
Copy link
Member

Thanks for raising. PR welcome!

@kathawala
Copy link

@profnandaa I'm working on a PR but it requires an external dependency, and I am having trouble installing any external dependency and getting rollup and babel to bundle it nicely.

I am having exactly the same issues which were described in #926. and I have tried all the suggested rollup plugins to no avail. If you could help at all, that would be appreciated. Is there a tried-and-true way to bundle in any dependencies from npm into this library?

@profnandaa
Copy link
Member

profnandaa commented Aug 2, 2020 via email

@kathawala
Copy link

kathawala commented Aug 2, 2020

@profnandaa It's a regular dep :(

The reason I asked if the project was open to PRs which pull in deps for cryptography and all is that I don't want to hand implement crypto and encoding/decoding functions if I don't have to. But if the project is not wanting external dependencies I can reproduce those functions in code.

@genus1
Copy link

genus1 commented Aug 23, 2020

The reason this does not work is because it is only decoding the address to base58.
Once decoded you need to 256 hash the first 21 bytes and compare the 256 hash to the next four bites of the decoded address.
Rename this function to validate base58.

@ezkemboi
Copy link
Member

ezkemboi commented Dec 8, 2020

I am working on this one and I will raise a PR.

@thegrandpoobah
Copy link

I just want to point out that I don't think that @ezkemboi 's PR fixes the described issue with testnet addresses. As far as I am aware, Testnet addresses start with m and that is not captured in the regex currently in use. Arguably you would want another method named isBTCTestnetAddress or something to distinguish between the two since you (maybe?) don't want to use testnet and mainnet addresses interchangeably, but the original described issue is still open.

@profnandaa
Copy link
Member

profnandaa commented Jan 3, 2021 via email

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

Successfully merging a pull request may close this issue.

6 participants