For future reference:
My goal is recognize that a string is bitcoin address or not.(Offline Mode)
I need a method that returns TRUE or FALSE.
You just have to check if the returned type is
not Invalid (eg. wrong checksum, wrong length, etc.) or Unknown (eg. Bech32m with witness version 2+).
AddressType t = GetAddressType(...);
bool result = (t != AddressType.Invalid && t != AddressType.Unknown);
Would you please show some examples of usage these methods :
Bitcoin.Net has a huge number of tests that you could use as examples. Each test file is in the Test project with the same namespace name.
/Tests/Bitcoin/Encoders/AddressTests.csWhat is NetworkType netType?
3 different network types are defined in Bitcoin: MainNet, TestNet and RegTest and some of the prefixes used when encoding addresses (and other variables elsewhere) are different for these networks.
Is this method working offline?
There is no reason not to!
This is a very bad approach and will have a lot of false positives and false negatives.
- Address length in Base58 is not fixed. It may be as small as 26 and as big as 35 (the article uses wrong values).
- First character being 1 or 3 doesn't mean the address's first byte was correct. Eg. 3R2cuiTJNvFDn18H7i7h7pvwYuvaRTNaJq is an invalid address because it uses 6 as the first byte instead of 5
- Regex doesn't validate the address checksum for either legacy or Bech32
- Due to lack of checksum validation there is no way to reject Bech32 addresses for version 1+ witness programs
- Certain edge cases aren't considered such as "bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqyqskt8xg" being an invalid Bech32 address