Is there a collection of regexes for viewing keys, sapling address, taddress, UAs, etc … ?
Hey, good q. I’m a humble man so I just rock stuff like:
Sapling zaddr: /^zs[a-z0-9]{76}$/
VK: /^zxviews[a-z0-9]{278}$/
Full UA looks like it’s something like: /^u1[a-z0-9]{211}$/
Orchard-only / Sapling-only UA’s something like: /^u1[a-z0-9]{104}$/
Looks like there’s room for variance on UA’s, and I will confess ZIP-32 and other cryptographic specs are near-meaningless to me! YMMV
Yeah they’re simplistic and only partially validate the key. I think there are some invalid characters we could omit from matching, but these have been good enough for my purposes so far.
I guess the short answer is, (I think) no. There’s not an organized collection! Hopefully this discussion gives us one!
This isn’t quite regexes, but we have been working on a new zcash_address
Rust crate specifically for parsing Zcash addresses (and now also Unified Full/Incoming Viewing Keys). The first version of this crate will be published in the next week or so, ahead of zcashd 5.0.0
. In the meantime, you can view its current API (and WIP documentation) here:
So, this would be called a “Sapling Incoming Viewing Key” specifically? I wonder if there is a quick resource that just explains the different kinds of viewing keys briefly and has their formats/regex? Orchard VKs are different and have different pattern?
That’s a sapling extended full viewing key. For a complete description, refer to Zip 32.
https://zips.z.cash/zip-0032
I’m seeing ^u1[a-z0-9]{104}$
- did you put 176 for a reason or … ?
UAs are of variable length, depending on the receivers they contain.
Or … what? Did I do it for no reason?
Yes, I did it for a reason. But I certainly don’t remember what it was. It’s not what I ended up using on the testnet faucet So while it’s possible it was a special case, it’s also reasonably likely the reason was “user error”. I updated my post with what I ended up using in the faucet: {211}
It looks like there’s variance in length! I think the 104 is for orchard-only (sapling-only looks the same to me at a glance). Let us know what you learn and please share when you’ve hammered out a nicer regex!
Hrm, I’m thinking about limiting and validating the p2p address on free2z …
BUT, with the different kinds of addresses and also the potential to do zip321 payment URIs, it’s a much harder problem than I was thinking … maybe I will continue to allow anything. But, I’ve also begun thinking about security of this…
To validate UA addresses in Zenith, I’m using a regex of ^u1[a-z0-9]$
and validating that the string is Bech32m encoded.