Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P2SH Segwit address from uncompressed WIF #1405

Closed
Overtorment opened this issue May 28, 2019 · 1 comment
Closed

P2SH Segwit address from uncompressed WIF #1405

Overtorment opened this issue May 28, 2019 · 1 comment

Comments

@Overtorment
Copy link

Overtorment commented May 28, 2019

I happened to have old WIF for the uncompressed public key.

Then I made a p2sh segwit address out of it, using bitcoinjs v3:

      let keyPair = bitcoin.ECPair.fromWIF(secret);
      let pubKey = keyPair.getPublicKeyBuffer();
      let witnessScript = bitcoin.script.witnessPubKeyHash.output.encode(bitcoin.crypto.hash160(pubKey));
      let scriptPubKey = bitcoin.script.scriptHash.output.encode(bitcoin.crypto.hash160(witnessScript));
      address = bitcoin.address.fromOutputScript(scriptPubKey);

And sent some bitcoins there.
Now apparently it is unspendable..? Or is there a way to recover those funds?
Error Im getting is BIP143 rejects uncompressed public keys in P2WPKH or P2WSH

Thanks!

@junderw
Copy link
Member

junderw commented May 28, 2019

It has always been unspendable.

Since the beginning of segwit any segwit key must use compressed pubkeys.

Since v3 only had a very manual process (like you showed) there was no way to check, since encode only received a hash.

In v4 and higher, your code would be:

let keyPair = bitcoin.ECPair.fromWIF(secret);
let pubKey = keyPair.publicKey;
let address = bitcoin.payments.p2sh({
  redeem: bitcoin.payments.p2wpkh({
    pubkey: pubKey,
    network: keyPair.network,
  }),
  network: keyPair.network,
}).address;

If the pubkey is uncompressed it will throw an error.

Unfortunately, there is no way to recover coins sent to an uncompressed pubkey using segwit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants