faker icon indicating copy to clipboard operation
faker copied to clipboard

Generated bitcoin addresses should pass validators.isBtcAddress

Open ST-DDT opened this issue 2 years ago • 4 comments

Clear and concise description of the problem

In #1181 the question came up, whether our bitcoin generator produces valid bitcoin addresses. According to validators.isBtcAddress it doesn't do so all the time.

Suggested solution

We should

  • check whether the validator.js method is correct,
  • use it in our tests,
  • and verify that the tests pass.

Alternative

No response

Additional context

No response

ST-DDT avatar Jul 23 '22 22:07 ST-DDT

I would like to try contribute to this issue if it still hasn't been resolved. Can you assign to me?

Minozzzi avatar Aug 02 '22 15:08 Minozzzi

I would like to try contribute to this issue if it still hasn't been resolved. Can you assign to me?

Sure!

import-brain avatar Aug 02 '22 16:08 import-brain

@import-brain I took the regex from our tests and manually verified it at https://regexr.com/ I believe our bitcoin address generation is wrong. Should we install the validatorjs package and apply it to bitcoin address tests with bitcoin address generation fix?

image It's allowing the i character

Minozzzi avatar Aug 07 '22 17:08 Minozzzi

@import-brain

I took the regex from our tests and manually verified it at https://regexr.com/

I believe our bitcoin address generation is wrong.

Should we install the validatorjs package and apply it to bitcoin address tests with bitcoin address generation fix?

image

It's allowing the i character

Sure, go for it!

import-brain avatar Aug 09 '22 19:08 import-brain

@ST-DDT @import-brain I've searched a little and I verified that lowercase i is permitted, the difference of validator.js and our validation on tests is the max chars.

Validator.js validation https://github.com/validatorjs/validator.js/blob/86a07ba4f3f710f639e92a62cf81dd3321ef9ee8/src/lib/isBtcAddress.js#L5

Our validation https://github.com/faker-js/faker/blob/fda44bb899efbcbac2071a199964a3e269cbd805/test/finance.spec.ts#L293

And i verified that the max generated chars is different of our tests and validator.js https://github.com/faker-js/faker/blob/15e3eed927953446d3e3aa8dcd7fca3f8472ff3e/src/modules/finance/index.ts#L214

I don't know say which is correct, I searched and almost all of the sites don't says the same thing about valid bitcoin address

Minozzzi avatar Aug 13 '22 20:08 Minozzzi

I don't know say which is correct, I searched and almost all of the sites don't says the same thing about valid bitcoin address

Yeah, pretty much all websites say different things about the max and min lengths of bitcoin addresses.

import-brain avatar Aug 13 '22 23:08 import-brain

I don't know say which is correct, I searched and almost all of the sites don't says the same thing about valid bitcoin address

Yeah, pretty much all websites say different things about the max and min lengths of bitcoin addresses.

Yep. We should keep how many to min and max? Because, basically this is the diffeference of validatorjs

Minozzzi avatar Aug 14 '22 21:08 Minozzzi

I don't know say which is correct, I searched and almost all of the sites don't says the same thing about valid bitcoin address

Yeah, pretty much all websites say different things about the max and min lengths of bitcoin addresses.

Yep. We should keep how many to min and max? Because, basically this is the diffeference of validatorjs

It's really confusing. At the top of the Bitcoin wiki page on addresses, it says that Bitcoin addresses contain "27-34 alphanumeric Latin characters (except 0, O, I)". However, further down the same page, it says "Some Bitcoin addresses can be shorter than 34 characters (as few as 26) and still be valid".

import-brain avatar Aug 15 '22 00:08 import-brain

Maybe needs decision :thinking:

Minozzzi avatar Aug 16 '22 02:08 Minozzzi

Team decision

  • We will use validatorJs for validation and will pass that library (or any other well known validation library).

ST-DDT avatar Sep 08 '22 15:09 ST-DDT

Okay @ST-DDT. I will apply the necessary changes to conform to the validatorJs validations

Minozzzi avatar Sep 08 '22 17:09 Minozzzi

PR: #1375

Minozzzi avatar Sep 13 '22 01:09 Minozzzi