<p>The redeem script for a P2SH-P2WPKH address is relatively simple. You take the RIPEMD160 hash of the SHA256 hash of the public key (same as P2PKH), this is known as the keyhash. The public key <em>must</em> be in compressed form. Then the P2SH redeem script is just OP_0 followed by a push of the keyhash. The keyhash is 20 bytes so the redeem script will always be 22 bytes long: <code>0014{keyhash}</code>.</p>

CC BY-SA 3.0
2017-11-22T21:24:45.453Z
2017-11-22T21:24:45.453Z
meshcollider
<p>You can obtain the redeem script from the public key. See line 86 here: <a href="https://github.com/Samourai-Wallet/samourai-wallet-android/blob/develop/app/src/main/java/com/samourai/wallet/segwit/P2SH_P2WPKH.java" rel="nofollow noreferrer">https://github.com/Samourai-Wallet/samourai-wallet-android/blob/develop/app/src/main/java/com/samourai/wallet/segwit/P2SH_P2WPKH.java</a></p>

CC BY-SA 3.0
2017-10-23T18:34:19.803Z
2017-10-23T18:34:19.803Z
T. DeV D
<p>I'm experimenting with Segwit transactions.</p>

<p>Is it possible to restore redeem script, if I know
1. Address (Segwit)
2. Public key
3. Private key</p>

<p>Thank you.</p>

CC BY-SA 3.0
2017-10-23T17:18:38.547Z
There are many (infinite) different redeem scripts based on private key. Restoring is possible if you know what kind of script was generated
amaclin
<bitcoin-core><segregated-witness>
SegWit. Redeem script
itogo
# SegWit. Redeem script

(Asked by: username_0 on 2017-10-23)

I'm experimenting with Segwit transactions.

Is it possible to restore redeem script, if I know
1. Address (Segwit)
2. Public key
3. Private key

Thank you.

**Tags:** bitcoin-core, segregated-witness

> **Comments:**
> **username_1**: There are many (infinite) different redeem scripts based on private key. Restoring is possible if you know what kind of script was generated  

---

## 2 answers

### Answer by username_2 on 2017-11-22. Score: 2

The redeem script for a P2SH-P2WPKH address is relatively simple. You take the RIPEMD160 hash of the SHA256 hash of the public key (same as P2PKH), this is known as the keyhash. The public key *must* be in compressed form. Then the P2SH redeem script is just OP\_0 followed by a push of the keyhash. The keyhash is 20 bytes so the redeem script will always be 22 bytes long: `0014{keyhash}`.


---

### Answer by username_3 on 2017-10-23. Score: 1

You can obtain the redeem script from the public key. See line 86 here: <https://github.com/Samourai-Wallet/samourai-wallet-android/blob/develop/app/src/main/java/com/samourai/wallet/segwit/P2SH_P2WPKH.java>


---

