The BIP173 specification defines how to create Bech32 Segwit native addresses.
In the examples section a public key is given:
Based on that key it is somewhat easy to generate a P2WPKH address, one hashes the key with SHA256, then with RIPEMD160 and use the hex decoded result as the witness program (first two commands are simple CLI and the last is from the Dart bech32 library):
$ echo 0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798 | xxd -r -p | openssl sha256 (stdin)= 0f715baf5d4c2ed329785cef29e562f73488c8a2bb9dbc5700b361d54b9b0554 $ echo 0f715baf5d4c2ed329785cef29e562f73488c8a2bb9dbc5700b361d54b9b0554 | xxd -r -p | openssl ripemd160 (stdin)= 751e76e8199196d454941c45d1b3a323f1433bd Segwit('bc', 0, HEX.decode("751e76e8199196d454941c45d1b3a323f1433bd")) // bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3
Generating a P2WSH involves the script
key OP_CHECKSIG followed by once SHA256 hashing. I'm at a loss how to construct said script. The opcode
OP_CHECKSIG is encoded as
0xac. But appending that to the key seems silly (and doesn't work). Besides the
CHECKSIG opcode requires two parameters. What do I hash?