I want to create P2WSH native like https://en.bitcoin.it/wiki/BIP_0173. I have already a script to generate P2WPKH and it works, thank the python part and re-arrange group byte works.
I read that witnessScript (scriptPubKey) is hash of SHA256 without RIPEMD160. Below a little bit of my code.
PB=0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798
#REDEEM SCRIPT <Public Key> OP_CHECKSIG
SCRIPT=210279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798AC
#SCRIPT HASH
$ printf $SCRIPT | xxd -r -p | openssl sha256| sed 's/^.* //'
1863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262
Convert scripthash to base 2
11000 01100 01100 01010 00011 11000 00101 00110 00101 00010 11001 10100 00000 01001 01111 01000 11001 00100 00000 11001 10101 01101 10110 10000 10011 01101 10010 01100 00101 01100 11110 00110 01101 01001 10100 10011 11010 00011 01110 00110 00110 00110 01010 01011 00000 01001 00100 00001 10010 01100 010
I need to add two zero at the beginning in order to Re-arrange those bits into groups of 5
00110 00011 00011 00010 10000 11110 00001 01001 10001 01000 10110 01101 00000 00010 01011 11010 00110 01001 00000 00110 01101 01011 01101 10100 00100 11011 01100 10011 00001 01011 00111 10001 10011 01010 01101 00100 11110 10000 11011 10001 10001 10001 10010 10010 11000 00010 01001 00000 01100 10011 00010
Add witness program
00000 00110 00011 00011 00010 10000 11110 00001 01001 10001 01000 10110 01101 00000 00010 01011 11010 00110 01001 00000 00110 01101 01011 01101 10100 00100 11011 01100 10011 00001 01011 00111 10001 10011 01010 01101 00100 11110 10000 11011 10001 10001 10001 10010 10010 11000 00010 01001 00000 01100 10011 00010
Convert each bits to base10
0, 6, 3, 3, 2, 16, 30, 1, 9, 17, 8, 22, 13, 0, 2, 11, 26, 6, 9, 0, 6, 13, 11, 13, 20, 4, 27, 12, 19, 1, 11, 7, 17, 19, 10, 13, 4, 30, 16, 27, 17, 17, 17, 18, 18, 24, 2, 9, 0, 12, 19, 2
Create the checksum with python code
15
29
21
28
10
6
my result is:
tb1qxrrzs7pf3gkdqzt6xfqxdtd5ymvnpt83n2dy7sm333jjczfqvnz0a4u2x
but the result in BIP 0173 is
tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7
I use the same script to generate P2WPKH that you can find in BIP_173 and it works. Of course I change Public key with public key hash, but the logic of create group of 5 bits and python part is the same.
Another question: can I create these address (P2WPKH and P2SH native) from bitcoin-cli?
SCRIPTPUBKEY
? In that way I have the same problem, I don't receive the right result. thanksSCRIPT=210279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798AC
script hash is1863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262
scriptPubKey is:00201863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262
Then I convert to base2 the scripthash1863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262
but I can't get the right result