Post
Topic
Board Development & Technical Discussion
Merits 1 from 1 user
Re: How to calculate p2wsh signature?
by
Boussac
on 03/08/2019, 08:50:12 UTC
⭐ Merited by ETFbitcoin (1)
I wrote about native P2WSH addresses on Medium a while ago and posted the code on Github:
https://gist.github.com/pierrenoizat/6880a12a599fa03a2099e3b38e8664e0

In a nutshell, if your witness script is like (for instance):

Code:
# script multisignature "2-of-2":
witness_script = BTC::Script.new  << BTC::Script::OP_2 << @user_key.compressed_public_key << @escrow_key.compressed_public_key << BTC::Script::OP_2
witness_script << BTC::Script::OP_CHECKMULTISIG

then your witness program (script_pub_key) is:
Code:
script_pub_key = BTC::Script.new << BTC::Script::OP_0
script_pub_key<< BTC.sha256(witness_script.data) # witness program

This is a ruby example but you get the idea in any other programming language you are using. Hope this helps.