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.
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.
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}
.
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