Bitcoin Forum
October 17, 2017, 08:56:21 PM *
News: Latest stable version of Bitcoin Core: 0.15.0.1  [Torrent]. (New!)
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED] Generating and verifying signed messages for Altcoins  (Read 661 times)
tuaris
Hero Member
*****
Offline Offline

Activity: 724



View Profile WWW
March 18, 2015, 02:29:09 PM
 #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

1508273781
Hero Member
*
Offline Offline

Posts: 1508273781

View Profile Personal Message (Offline)

Ignore
1508273781
Reply with quote  #2

1508273781
Report to moderator
1508273781
Hero Member
*
Offline Offline

Posts: 1508273781

View Profile Personal Message (Offline)

Ignore
1508273781
Reply with quote  #2

1508273781
Report to moderator
1508273781
Hero Member
*
Offline Offline

Posts: 1508273781

View Profile Personal Message (Offline)

Ignore
1508273781
Reply with quote  #2

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

Posts: 1508273781

View Profile Personal Message (Offline)

Ignore
1508273781
Reply with quote  #2

1508273781
Report to moderator
EcuaMobi
Legendary
*
Offline Offline

Activity: 1246



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
Hero Member
*****
Offline Offline

Activity: 724



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: 1232


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
Hero Member
*****
Offline Offline

Activity: 724



View Profile WWW
March 20, 2015, 05:54:08 PM
 #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
Hero Member
*****
Offline Offline

Activity: 724



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?

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!