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.
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
Let's look at that redeem script then:
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.