Hi. We are adding Zcash in our system and we don’t find a way, how to validate (shielded) address.
We know, that we need to:
Try parsing as a Unified Address
Try parsing as a Sapling address —> Bech32 encoding
Try parsing as a Sprout address —> Base58 encoding
Try parsing as transparent
Is there any documentation that will tell us how to implement validation of shielded addresses? Or maybe some examples? How can we validate unified address? We are implementing validation in Java.
We don’t have any direct support for address validation in Java, but what I would recommend is that you build a Rust binary to do the validation you need (this code from zcash-inspect is relevant), and then execute it from Java. If you were to submit a patch to zcash-inspect for an option to do just address validation, we’d be happy to review that.
If you want to reimplement, the relevant specifications are ZIP 316 and section 5.6 of the Zcash protocol specification. Be aware that they’re complicated, especially taking into account the need to implement the Pallas and Jubjub elliptic curves if you want to do full validation. (secp256k1 does not need to be implemented since transparent addresses only contain hashes, not curve points.)
zcash-inspect is not a published production binary (yet) and not intended for this kind of usage
What I would recommend however is doing exactly what zcash-inspect itself is doing, which is using the zcash_address crate to attempt to parse the string. You can use the jni crate to write a Rust JNI wrapper around the crate usage, and then call it from your Java application.