user128737: How can I calculate the R, S, and Z values from a raw bitcoin transaction? I can extract them with rscan.py, but that doesn't work for new transactions.

user51948: As specified in BIP-141, the witness for a P2WPKH spend is as follows:

The witness must consist of exactly 2 items (≤ 520 bytes each). The first one a signature, and the second one a public key.

The signature consists of the usual R and s values that you're looking for, as before.

Let's look at this transaction you keep linking to. Let's look at the first input.
We can see the scriptPubKey is
OP_HASH160 fcebfb01198e90e99875a913dd592650fd2df667 OP_EQUAL

This means it is a P2SH spend, where the P2SH redeem script has the hash fcebfb0....67
Let's look at that redeem script then:
0020d687015ac2304c3213491ff4fc71ea15e9c170fddedd8bed92be2d191f8adddd

This is OP_0 followed by a push of 32-bytes. That means it's a P2WSH spend. Because this was wrapped inside P2SH, it's called P2SH-P2WSH. But there is no public key or signature involved so far, just scripts.
The witness consists of three pushes onto the stack. This includes the witness script:
OP_PUSHNUM_2 OP_PUSHBYTES_33 035e1822f3a6eec3911545188bb0e6df3826eef8b630a77d1e344ba5954d9534a8 OP_PUSHBYTES_33 03694100a1f02854db3acac05c878053aba59fedfe3ebb1b7e094051aa61da6ba8 OP_PUSHBYTES_33 03e9509f6b6ad39542aa816c24d50d8ca7d83cfa6b430f0c366184957961a07fd6 OP_PUSHNUM_3 OP_CHECKMULTISIG

In other words, this is a 2-of-3 multisig. The other two items on the witness stack are therefore signatures. But this is going to be different for every possible type of script, so there isn't going to be a way to just "extract" the signature from P2WSH spends. Best to focus just on the key-based spends.

128737: <p>How can I calculate the R, S, and Z values from a raw bitcoin transaction? I can extract them with <code>rscan.py</code>, but that doesn't work for new transactions.</p>
 51948: <p>As specified in <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki" rel="nofollow noreferrer">BIP-141</a>, the witness for a P2WPKH spend is as follows:</p>
<blockquote>
<p>The witness must consist of exactly 2 items (≤ 520 bytes each). The first one a signature, and the second one a public key.</p>
</blockquote>
<p>The signature consists of the usual R and s values that you're looking for, as before.</p>
<hr />
<p>Let's look at <a href="https://www.blockchain.com/btc/tx/9ae7ce79fa8501dd92ade347fae7c1737ccefa6db204a2fae485634c265d5494" rel="nofollow noreferrer">this transaction</a> you keep linking to. Let's look at the first input.</p>
<p>We can see the scriptPubKey is</p>
<pre><code>OP_HASH160 fcebfb01198e90e99875a913dd592650fd2df667 OP_EQUAL
</code></pre>
<p>This means it is a P2SH spend, where the P2SH redeem script has the hash <code>fcebfb0....67</code></p>
<p>Let's look at that redeem script then:</p>
<pre><code>0020d687015ac2304c3213491ff4fc71ea15e9c170fddedd8bed92be2d191f8adddd
</code></pre>
<p>This is OP_0 followed by a push of 32-bytes. That means it's a P2WSH spend. Because this was wrapped inside P2SH, it's called P2SH-P2WSH. But there is no public key or signature involved so far, just scripts.</p>
<p>The witness consists of three pushes onto the stack. This includes the witness script:</p>
<pre><code>OP_PUSHNUM_2 OP_PUSHBYTES_33 035e1822f3a6eec3911545188bb0e6df3826eef8b630a77d1e344ba5954d9534a8 OP_PUSHBYTES_33 03694100a1f02854db3acac05c878053aba59fedfe3ebb1b7e094051aa61da6ba8 OP_PUSHBYTES_33 03e9509f6b6ad39542aa816c24d50d8ca7d83cfa6b430f0c366184957961a07fd6 OP_PUSHNUM_3 OP_CHECKMULTISIG
</code></pre>
<p>In other words, this is a 2-of-3 multisig. The other two items on the witness stack are therefore signatures. But this is going to be different for every possible type of script, so there isn't going to be a way to just &quot;extract&quot; the signature from P2WSH spends. Best to focus just on the key-based spends.</p>
