web3j icon indicating copy to clipboard operation
web3j copied to clipboard

Update the Web3J documentation to contain signatures

Open rach-id opened this issue 2 years ago • 4 comments

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:

  • How to use the Sign class to generate signatures for random messages.
  • How the SignatureData can be used
  • Example code snippets

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:

  • Simply concatenating their values
  • EIP-155 way, etc

rach-id avatar Mar 18 '22 16:03 rach-id

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

mohamedelshami avatar Mar 24 '22 13:03 mohamedelshami

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 avatar Mar 24 '22 13:03 rach-id

@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.

rach-id avatar Mar 25 '22 09:03 rach-id

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

mohamedelshami avatar Mar 27 '22 15:03 mohamedelshami