0

can i use the sign message function to sign the serialized hex for a p2sh transaction? Are the ecdsa functions used the same or are they different? It looks like the output is in a different format than a traditional tx signature? How can one use this function to sign?

1

You cannot. While both message and transaction signing use ECDSA and double sha256, signed messages slightly modify the message such that it is impossible to create a signature that works for that key in a transaction.

Specifically, bitcoin signed messages are prefixed with the string Bitcoin Signed Message:\n (\n is the newline character, not literally \ and n). This means that the data that is actually signed cannot be for a transaction since the data signed for a transaction cannot begin with that string. This design is intentional so that users cannot be tricked into signing a message which can be used in a transaction to take their money.

The output looks different just due to serialization. If the signatures were compatible, you would just deserialize the signed message signature and reserialize it differently. But because the signatures are not compatible, this point is moot.

| improve this answer | |
  • Perhaps point out that this is by design: otherwise you could try to get someone to sign a specific message, and then use it to steal their money. – Pieter Wuille Apr 14 at 6:48
  • if i have the rawhex that i want to sign. Why can't i construct a message with 'Bitcoin Signed Message:' in front of it and then sign it? – user3554230 Apr 14 at 7:51
  • i guess i am asking if the actual ecdsa function and hashing are identical. It seems like adding a string in front of signed data is pretty easy to do ? how is this serialized vs a traditional tx signature ? – user3554230 Apr 14 at 7:52
  • @user3554230 Signatures for transactions follow a very specific format. They are, for the most part, just the transaction itself with a couple modifications. The data that is signed is not included in the transaction explicitly, verifiers construct it from the transaction that they receive. So you can't just "add a string in front of the signed data" for a signature in a transaction. – Andrew Chow Apr 14 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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