1

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.

1
  • There are many (infinite) different redeem scripts based on private key. Restoring is possible if you know what kind of script was generated
    – amaclin
    Commented Oct 23, 2017 at 17:18

2 Answers 2

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.