hyperledger-web3j / web3j

Lightweight Java and Android library for integration with Ethereum clients
https://www.web3labs.com/web3j-sdk
Other
5.11k stars 1.69k forks source link

Update the Web3J documentation to contain signatures #1664

Open rach-id opened 2 years ago

rach-id commented 2 years ago

Problem statement

Currently, the documentation is not showing how to sign random messages using Web3j and how to use those signatures. And, as a result of that, we have multiple issues in GitHub, and also other platform like Stack exchange where people ask for help concerning this. Also, some people might have different results depending on the methods used. Example issues: https://github.com/web3j/web3j/issues/208, https://github.com/web3j/web3j/issues/1662 etc

Proposed solution

It would be awesome to add to the docs this functionality via opening a new PR here.

The PR could contain:

This work can be inspired from the way web3JS is handling signatures and their documentation.

Stretch goal

Add to<standard>String() method to SignatureData that returns the hex encoding of the signature (aside from the raw r, s and v values) following different standards:

mohamedelshami commented 2 years ago

Thanks, Rachid, this is a good proposal. By random message, do you mean arbitrary-sized message?

rach-id commented 2 years ago

Thanks. Something like:

        Credentials credentials = Credentials.create("0x1234");
        byte[] msg = "hello".getBytes();
        Sign.SignatureData signature = Sign.signMessage(msg, credentials.getEcKeyPair());

Where we show people how to create credentials, how to use them to sign arbitrary-sized messages, how to handle the resulting signature, etc. I noticed a need for this in multiple issues. It would be good to have a link containing all this information and share it with people.

rach-id commented 2 years ago

@mohamedelshami What do you think if we open a tracking issue for these documentation issues. So that if someone picks up documentation, then, they will already have a list of stuff that needs to be added. Let me know if you think it is a good idea, and I will create something and start populating it with docs proposals.

mohamedelshami commented 2 years ago

@SweeXordious it's definitely a good idea. Pretty sure there's a good a number of open issues related to lack of documentation.