bitcoinjs-lib
bitcoinjs-lib copied to clipboard
Stricter validation for Taproot addresses
I want to ask/clarify if it is OK to add stricter validation rules for taproot addresses.
For witness v0 it is checked if the data has a length of 20 or 32, otherwise it is considered an invalid address.
For witness v1 (taproot) such a check is not performed. So a an address of the form bcrt1sw50qt2uwha would be considered valid.
Since taproot has been activated on mainnet already and it is known that the data length must be 32 then a check similar to witness v0 can be added. This would prevent loss of funds in case another wallet generates a faulty witness v1 address.
I'm not sure if witness v1 is set in stone or some other types of data will be allowed in the future. Either way, the validation can be relaxed at that point.
The changes include:
- add
if (decodeBech32.version === 1) ...check fortoOutputScript() - add
return payments.p2tr({ output, network }).address as string;tofromOutputScript()- after
p2tris merged
- after
- increase
FUTURE_SEGWIT_MIN_VERSIONto2
Yes. We will need to do this. Rather than shim some solution in, we should wait on p2tr. I am still debating with myself on how to handle p2tr.
do we have an example of, say, v7 valid address..?
nvm, found some test vectors here: https://github.com/bitcoin/bips/blob/edffe529056f6dfd33d8f716fb871467c3c09263/bip-0350.mediawiki#Addresses_for_segregated_witness_outputs
(e.g. this one is v16 BC1SW50QGDZ25J)