Bitcoin Forum
May 14, 2024, 12:47:42 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [SOLVED] Generating and verifying signed messages for Altcoins  (Read 773 times)
tuaris (OP)
Hero Member
*****
Offline Offline

Activity: 765
Merit: 500



View Profile WWW
March 18, 2015, 02:29:09 PM
Last edit: March 20, 2015, 07:32:07 PM by tuaris
 #1

I've put together some PHP code that is able to sign and verify signed message.  It is available on GitHub https://github.com/tuaris/CryptoCurrencyPHP.

The code is pretty simple to follow and it works fine for Bitcoin.

I just can't understand why it fails to generate a valid signature for Altcoins and also fails to verify a signed message from an Altcoin client.  I've made sure to set the correct address version when hashing/encoding the public key.

Besides that, is there anything different that is done when signing and verifying messages for other "address versions"?

Edit: Problem solved.  This now works properly for any crypto currency

1715690862
Hero Member
*
Offline Offline

Posts: 1715690862

View Profile Personal Message (Offline)

Ignore
1715690862
Reply with quote  #2

1715690862
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715690862
Hero Member
*
Offline Offline

Posts: 1715690862

View Profile Personal Message (Offline)

Ignore
1715690862
Reply with quote  #2

1715690862
Report to moderator
1715690862
Hero Member
*
Offline Offline

Posts: 1715690862

View Profile Personal Message (Offline)

Ignore
1715690862
Reply with quote  #2

1715690862
Report to moderator
1715690862
Hero Member
*
Offline Offline

Posts: 1715690862

View Profile Personal Message (Offline)

Ignore
1715690862
Reply with quote  #2

1715690862
Report to moderator
EcuaMobi
Legendary
*
Offline Offline

Activity: 1862
Merit: 1469


https://Ecua.Mobi


View Profile WWW
March 18, 2015, 02:30:41 PM
 #2

I've put together some PHP code that is able to sign and verify signed message.  It is available on GitHub https://github.com/tuaris/CryptoCurrencyPHP.

The code is pretty simple to follow and it works fine for Bitcoin.

I just can't understand why it fails to generate a valid signature for Altcoins and also fails to verify a signed message from an Altcoin client.  I've made sure to set the correct address version when hashing/encoding the public key.

Besides that, it there anything different that is done when signing and verifying messages for other "address versions"?

There are an address version and a private key version. Did you change both or just the address?

Nice tool! I'm checking it now.

tuaris (OP)
Hero Member
*****
Offline Offline

Activity: 765
Merit: 500



View Profile WWW
March 18, 2015, 02:46:06 PM
 #3

I've put together some PHP code that is able to sign and verify signed message.  It is available on GitHub https://github.com/tuaris/CryptoCurrencyPHP.

The code is pretty simple to follow and it works fine for Bitcoin.

I just can't understand why it fails to generate a valid signature for Altcoins and also fails to verify a signed message from an Altcoin client.  I've made sure to set the correct address version when hashing/encoding the public key.

Besides that, it there anything different that is done when signing and verifying messages for other "address versions"?

There are an address version and a private key version. Did you change both or just the address?

Nice tool! I'm checking it now.


I could be wrong, but I think for signing and verifying the private key prefix does not come into effect.  Also, I just found this page: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/networks.js  It looks like there are indeed some more items that need to be adjusted.  I just can't wrap my head around the difference in the "messagePrefix", why bitcoin uses x18 and the others use x19.

I'll continue to research this but any tips would be helpful.

Thanks.

lyth0s
Legendary
*
Offline Offline

Activity: 1260
Merit: 1000


World Class Cryptonaire


View Profile
March 18, 2015, 11:28:44 PM
 #4

If you put this thread in the technical section of the forums instead of the "Beginners" section you will get much better responses and help from other devs. I know you can't move this thread yourself so maybe just lock it and then create a new thread in the technical support section.

Monero - Truly Anonymous Digital Cash. Bitcoin Reading List 2017
tuaris (OP)
Hero Member
*****
Offline Offline

Activity: 765
Merit: 500



View Profile WWW
March 20, 2015, 05:54:08 PM
Last edit: March 20, 2015, 06:04:55 PM by tuaris
 #5

I am having trouble locating where this byte prefix "0x18" is used and defined in the Bitcoin sorce code.

This is what I found so far:
src/main.cpp#L80
Code:
const string strMessageMagic = "Bitcoin Signed Message:\n";

And where that gets used when signing/verifying a message:
src/rpcmisc.cpp#L367 and src/wallet/rpcwallet.cpp#L496
Code:
CHashWriter ss(SER_GETHASH, 0);
ss << strMessageMagic;
ss << strMessage;

But I do not see anything indicating that that byte prefix is being utilized.

tuaris (OP)
Hero Member
*****
Offline Offline

Activity: 765
Merit: 500



View Profile WWW
March 20, 2015, 06:56:43 PM
 #6

I am having trouble locating where this byte prefix "0x18" is used and defined in the Bitcoin sorce code.

This is what I found so far:
src/main.cpp#L80
Code:
const string strMessageMagic = "Bitcoin Signed Message:\n";

And where that gets used when signing/verifying a message:
src/rpcmisc.cpp#L367 and src/wallet/rpcwallet.cpp#L496
Code:
CHashWriter ss(SER_GETHASH, 0);
ss << strMessageMagic;
ss << strMessage;

But I do not see anything indicating that that byte prefix is being utilized.

Okay, figured it out with the help of this source code comment:
bitcoinj/core/Utils.java#L510.  

It's the message length for the line.  
0x18 being decimal value 24, for 24 characters in this "Bitcoin Signed Message:\n".
0x19 being decimal value 25, for 25 characters in this "Zetacoin Signed Message:\n".

Where is this officially documented?

koad
Member
**
Offline Offline

Activity: 64
Merit: 10


View Profile WWW
March 30, 2021, 10:43:00 PM
 #7

I am wondering about this too.

The prefix is used in libraries and third party apps but it doesn't seem to be the same as the bitcoin source code.  The code you referenced in the source uses `strMessageMagic` without adding the prefix so I am wondering why so many clients/libraries out there do it.

I am also wondering what kinds of bad things might happen if this prefix or message magic itself is set incorrectly,..


/koad
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!