MetacoSA / NBitcoin

Comprehensive Bitcoin library for the .NET framework.
MIT License
1.87k stars 846 forks source link

How to Verify a Message from a P2SH Address #993

Open betocastelo opened 3 years ago

betocastelo commented 3 years ago

I'm following the example on the Programming the Blockchain in C# book, but would like to use a P2SH address. How to produce a BitcoinPubKeyAddress object from that p2sh address to verify the message with? Or is there another path?

lontivero commented 3 years ago

p2sh doesn't contain a key and then there is no way to sign/verify a message.

betocastelo commented 3 years ago

How do you prove ownership of a transaction involving a p2sh address? Is it possible?

Using a trezor wallet I'm able to do the following: create a new wallet (using a passphrase). Obtain a receive address (a 3* address, which I assume indicates a P2SH address). Sign a message with the address. Switch to a different wallet (different passphrase). Verify the message successfully. How do I verify the same message using NBitcoin?

Sorry about the really basic questions, I'm using NBitcoin along with the book and trying to match what I read with my usage of btc, to learn more about bitcoin development. I'd appreciate any pointers.

lontivero commented 3 years ago

You prove ownership of a p2sh by providing the script that was committed.

If trezor gives you an address starting with '3' then it is by sure a p2wpkh wrapped around a p2sh and in that case there is a key pair you can use to sign and verify messages.

I don't know how to do it, I only know that you will need the pubkey because it is not possible to extract it from a p2sh i believe.

Murphyfmg commented 1 year ago

Please if you have compile it, can you send me the NBitcoin.dll to my email murphycelestine28@gmail.com, thanks