Author

Topic: [CANCELLED] C# guru's - Need signmessage & verifymessage fill in the blanks (Read 3187 times)

hero member
Activity: 765
Merit: 503
i think doof deserve the bounty.

Thanks guys.

Well, I got it to compile (remove uncommented code) and cast to c#.  However, the requirements are a lot more than that.  Without unit tests to compare its very hard to confirm.
legendary
Activity: 1260
Merit: 1000
Drunk Posts
I messed with it a bit but couldn't get it to work... most of the ecdsa stuff just goes over my head, i just followed examples and tested till it worked for the existing code
tfk
newbie
Activity: 39
Merit: 0
I think that this is a wise choice. Skipping over something like that is never a good idea. It's there for a reason. So indeed I recommend you to retain the longer sig.

You could ofcourse contact the author to ask why he seems to be skipping this part. Maybe he can give you some extra insight.

TFK
sr. member
Activity: 369
Merit: 250
I don't intend to earn the bounty but I know of a .NET bitcoin implementation, which maybe already works for you: https://github.com/jkoberg/FCoin

Thanks knocte, that looks like what I'm after, although not f# but it might not be hard to translate. I'll test it out tonight.

The project I have up on GitHub is very close to having a working solution, the only bit I cant get working is the function "recoverFromSignature" which also includes "decompressKey".. they contain some pretty funky crypto arithmetic which was why I offered up this bounty, for someone to finish it off.

The amusing part, is that F# implementation by jkoberg looks to have completely skipped the recoverFromSignature routine and he simply loops through the 4 recId iterations doing a verifyMessage call each pass to see if the hashes match and assuming the current recId is correct..  Not exactly optimized when you have to perform 4 ECDSA verification calls to sign one message.

To be honest this Bitcoin specific compressed signature format is proving to be more trouble than its worth, i'm thinking it may be better to retain a longer signature just to be more standard complient and compatible with existing ECDSA libraries.
sr. member
Activity: 369
Merit: 250
I don't intend to earn the bounty but I know of a .NET bitcoin implementation, which maybe already works for you: https://github.com/jkoberg/FCoin

Thanks knocte, that looks like what I'm after, although not f# but it might not be hard to translate. I'll test it out tonight.

Hi!

I've also taken a look at this code.

You need to get a whole bunch of classes translated. Classes from SpongyCastle ( https://github.com/rtyley/spongycastle ) which is a repackage of Bouncy Castle ( http://www.bouncycastle.org ) for Android and various classes from jbitcoin itself ( https://code.google.com/p/bitcoinj/source/browse/core/src/main/java/com/google/bitcoin/ )

Where Bouncy Castle has C# libraries availlable, SpongyCastle hasn't. Here lies the huge amount of work.

Do you know this library? http://bitcoincs.codeplex.com/SourceControl/latest

Before going further -and loose a good bitcoin on this- it may be a good thing to look around for solutions that are further in development. Do you need specifically jbitcoin translated?

TFK

Thanks tfk, I hadn't heard of spongy castle.
tfk
newbie
Activity: 39
Merit: 0
Hi!

I've also taken a look at this code.

You need to get a whole bunch of classes translated. Classes from SpongyCastle ( https://github.com/rtyley/spongycastle ) which is a repackage of Bouncy Castle ( http://www.bouncycastle.org ) for Android and various classes from jbitcoin itself ( https://code.google.com/p/bitcoinj/source/browse/core/src/main/java/com/google/bitcoin/ )

Where Bouncy Castle has C# libraries availlable, SpongyCastle hasn't. Here lies the huge amount of work.

Do you know this library? http://bitcoincs.codeplex.com/SourceControl/latest

Before going further -and loose a good bitcoin on this- it may be a good thing to look around for solutions that are further in development. Do you need specifically jbitcoin translated?

TFK
full member
Activity: 196
Merit: 100
You want working solution right ?
newbie
Activity: 44
Merit: 0
I don't intend to earn the bounty but I know of a .NET bitcoin implementation, which maybe already works for you: https://github.com/jkoberg/FCoin

Let me know if it is helpful to you! I cannot test it now due to lack of time*
Cheers


* However, in some months I will be much more free, and I'm interested on having some developer contacts interested around Bitcoin in the .NET/Mono framework, PM me!
sr. member
Activity: 369
Merit: 250
I was hoping to use the bitcoin-qt style message sign & verify with compressed signatures... but for the time being I think I can use the signData, verifySignature from mb300sb' library to achieve what I need (albeit with much longer signatures).

Nevertheless, It would be nice to have a working C# implementation somewhere, so the bounty remains if any C# crypto experts want to take a crack at it.
sr. member
Activity: 369
Merit: 250
Doof's submission is not complete, I haven't heard from him so thought I'd open it back up.
hero member
Activity: 686
Merit: 504
always the student, never the master.
i think doof deserve the bounty.
sr. member
Activity: 369
Merit: 250
Bounty still available for any takers.
sr. member
Activity: 369
Merit: 250
byte array or string is not a big deal.. not hard to convert to base64 string..
hero member
Activity: 765
Merit: 503
It builds, but looking at the java code, there's a lot that's different.

For example SignMessage on the java return is string, this is byte[]
hero member
Activity: 765
Merit: 503
All good

Method on Line 393 needs adding too.
public ECDSASignature sign(Sha256Hash input, KeyParameter aesKey)

sr. member
Activity: 369
Merit: 250
The commented out part I could have stuffed up... safest to delete it and re-translate the BitcoinJ version.
hero member
Activity: 765
Merit: 503
Ok, ill take a look.

Who did the original conversion?  The commented out code creates a BigInt type on "sig".

Java creates an ECDSASignature  class.   Not sure which way to go.

ECDSASignature sig = sign(hash, aesKey);
 
        // Now we have to work backwards to figure out the recId needed to recover the signature.
 
        int recId = -1;
 
        for (int i = 0; i < 4; i++) {
 
            ECKey k = ECKey.recoverFromSignature(i, sig, hash, isCompressed());
 
            if (k != null && Arrays.equals(k.pub, pub)) {
 
                recId = i;
 
                break;
 
            }
 
        }
sr. member
Activity: 369
Merit: 250
Done.  Slothbag, can you pm me your email?  I cant commit to github until tonight.  Ill email you the .cs files.

Also, ill look at bitcoinj and see if he has any unit tests.  there's a few (logical) assumptions to be made, but I cant verify the implementation performs exactly the same without unit tests.

Here is a very simple C++ message sign verify program https://github.com/Bobalot/bitcoin-signature-tools

I was just planning to generate 100 random addresses and get the C++ and the C# programs to run through them all and compare the results.  Not super thorough but probably enough for my purposes
hero member
Activity: 765
Merit: 503
Done.  Slothbag, can you pm me your email?  I cant commit to github until tonight.  Ill email you the .cs files.

Also, ill look at bitcoinj and see if he has any unit tests.  there's a few (logical) assumptions to be made, but I cant verify the implementation performs exactly the same without unit tests.
sr. member
Activity: 369
Merit: 250

From memory the one or two Util functions I needed I just moved into the class that needed them.  Not fussed if you want to keep them in a separate Util file or not.
hero member
Activity: 765
Merit: 503
hero member
Activity: 765
Merit: 503
It just does a double hash.. ComputeHash(ComputeHash(data)) I believe

Ahhh... cool.  Was thinking from type Double, lol
hero member
Activity: 765
Merit: 503
Java implementation he is adding 2 bit ints r & s. The c# out of the box class doesn't have these, so ill have to wrap it.

public static class ECDSASignature {
 
        public BigInteger r, s;
 

 
        public ECDSASignature(BigInteger r, BigInteger s) {
 
            this.r = r;
 
            this.s = s;
 
        }
sr. member
Activity: 369
Merit: 250
It just does a double hash.. ComputeHash(ComputeHash(data)) I believe
hero member
Activity: 765
Merit: 503
No probs, I should mention I dont want any extra dll's to be required.

All the required code should be able to be translated from the BitcoinJ library (BitcoinJ also uses Bouncy Castle).  But if you find a different class, as long as its not too bloated, that's ok too.

Yeah, that was my assumption.  Just translating...
hero member
Activity: 765
Merit: 503
I haven't even looked at this code in months, but I did implement full tx signing and verification in C# here, https://github.com/mb300sd/Bitcoin-Tool/tree/master/Bitcoin%20Tool

Something might be helpful.

Yeah, I tried the dataSign method you had, but the message signing required some extra work, I think because Bitcoin-QT use some compressed signature which chops out the public key or something.

Well, if doof doesn't get it tonight, I might have a go at it tomorrow, just have to find my original source somewhere and install VS on this new laptop

Just tying to find out what this method does:  then done
Sha256Hash.createDouble(messageBytes);
sr. member
Activity: 369
Merit: 250
Well, if doof doesn't get it tonight, I might have a go at it tomorrow, just have to find my original source somewhere and install VS on this new laptop

The GitHub project I created (linked above) has a crypto folder, which is pretty much 99% your code just cut down for this exercise.  Hopefully the submitted changes I can push back into your library.
legendary
Activity: 1260
Merit: 1000
Drunk Posts
I haven't even looked at this code in months, but I did implement full tx signing and verification in C# here, https://github.com/mb300sd/Bitcoin-Tool/tree/master/Bitcoin%20Tool

Something might be helpful.

Yeah, I tried the dataSign method you had, but the message signing required some extra work, I think because Bitcoin-QT use some compressed signature which chops out the public key or something.

Well, if doof doesn't get it tonight, I might have a go at it tomorrow, just have to find my original source somewhere and install VS on this new laptop
sr. member
Activity: 369
Merit: 250
I haven't even looked at this code in months, but I did implement full tx signing and verification in C# here, https://github.com/mb300sd/Bitcoin-Tool/tree/master/Bitcoin%20Tool

Something might be helpful.

Yeah, I tried the dataSign method you had, but the message signing required some extra work, I think because Bitcoin-QT use some compressed signature which chops out the public key or something.
legendary
Activity: 1260
Merit: 1000
Drunk Posts
I haven't even looked at this code in months, but I did implement full tx signing and verification in C# here, https://github.com/mb300sd/Bitcoin-Tool/tree/master/Bitcoin%20Tool

Something might be helpful.
sr. member
Activity: 369
Merit: 250
No probs, I should mention I dont want any extra dll's to be required.

All the required code should be able to be translated from the BitcoinJ library (BitcoinJ also uses Bouncy Castle).  But if you find a different class, as long as its not too bloated, that's ok too.
hero member
Activity: 765
Merit: 503
Just about done.  Theres a few Classes that don't seem to exist in bouncy castle.  Just hunting them down now.
sr. member
Activity: 369
Merit: 250
Cant github from work, so I just copied and paste.  Is the bounty still out?  Should finish it off in an hour.

Yeah mate, still available.  Send us a link or whatever when your done and i'll have a look.
hero member
Activity: 765
Merit: 503
i'm also ready to help out if still needed (my SO profile: http://stackoverflow.com/users/90742/herzmeister)

Well no one has submitted a pull request yet.. first one to submit a working solution will get the coin.  Not ideal I know... but it's not that big of a job either.

Cant github from work, so I just copied and paste.  Is the bounty still out?  Should finish it off in an hour.
legendary
Activity: 1764
Merit: 1007
I thought I'm nice and let the other guy first, and I'm at work right now anyway.
sr. member
Activity: 369
Merit: 250
i'm also ready to help out if still needed (my SO profile: http://stackoverflow.com/users/90742/herzmeister)

Well no one has submitted a pull request yet.. first one to submit a working solution will get the coin.  Not ideal I know... but it's not that big of a job either.
legendary
Activity: 924
Merit: 1004
Firstbits: 1pirata
I think people would be more willing to help if you sent the bounty in escrow on Rugatu, assuming is your question of course.

http://www.rugatu.com/questions/21141/are-there-any-gurus-at-c
legendary
Activity: 1764
Merit: 1007
i'm also ready to help out if still needed (my SO profile: http://stackoverflow.com/users/90742/herzmeister)
sr. member
Activity: 369
Merit: 250
Yeah, should be mostly straight forward, though there are a few curly ones in there like mismatch ECKey vs ECKeyPair classes..

I had a good crack at it myself but didn't wont to spend too long on it.. I figured the crypto experts would be able to get it working pretty quick.

Submit a pull request when your done, i'll run it through a test script with 100 addresses and different messages to confirm it works before releasing the bounty.

Thanks for looking into it for me. 
hero member
Activity: 765
Merit: 503
Most of it is easy fixes.

Change the static methods to not static.  No need for them.

And a issues are just case problems.  BigInteger.multiply should be BigInteger.Multiply, BigInteger.Long etc

If you go to your objectbrowser, you should see all the methods.

Gotta run to my meetup now. If the bounties not collected by tomorrow morn, ill finish it up.
hero member
Activity: 765
Merit: 503
Actually, looking at it now.
hero member
Activity: 765
Merit: 503
Happy to look at it tomorrow, after my Brisbane meetup tonight.
sr. member
Activity: 369
Merit: 250
Hi All,

Any C# guru's want a quick job?  I need signmessage and verifymessage implemented, BitcoinJ code is in place, needs translating into C#.

Check out this C# project on GitHub  https://github.com/slothbag/BitcoinCryptoTest

File ECKeyPair.cs lines 90-200 have been commented out, they are a copy from BitcoinJ and obviously don't compile in C#.

The first to make this very simple program sign and verify messages compatible with Bitcoin-QT there is 1 BTC for ya.


The existing C# code is from mb300sb and his excellent C# library here https://bitcointalksearch.org/topic/c-bitcoin-tool-variety-of-uses-148163

Update: I am cancelling the bounty for this due to lack of interest.
Jump to: