Closed supertestnet closed 10 months ago
You misunderstand what the test vectors are showing.
They are showing scriptPubkeys, not direct conversions of the words to bytes.
You have to take the segwit version from the first word and convert the 2nd word onward, then push that using an OP_PUSHDATA to make a valid scriptPubkey.
If the library were completely broken in this way, then wallets using taproot addresses with no issue wouldn't exist.
Thank you! That worked. :) I decoded the two test vectors from the second word onward and got exactly the results I expected:
var words = bech32.bech32m.decode( "tb1pqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesf3hn0c" ).words; var segwit_version = words[ 0 ]; words.splice( 0, 1 ); var pubkey = bytesToHex( bech32.bech32m.fromWords( words ) ); console.log( "pubkey:", pubkey ); //000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433 var words = bech32.bech32m.decode( "bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0" ).words; var segwit_version = words[ 0 ]; words.splice( 0, 1 ); var pubkey = bytesToHex( bech32.bech32m.fromWords( words ) ); console.log( "pubkey:", pubkey ); //79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
All I have to do is prefix 5120 to them to represent the segwit version number (OP_PUSHNUM_1) and the pushdata opcode (OP_PUSHBYTES_32) and the result is identical to the test vector. Thank you for your help!
According to bip350:
I tried these test vectors in the bech32 library and this is what I got:
I used version 2.0.0 available for the browser here:
<script src="https://bundle.run/bech32@2.0.0"></script>