Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Web3J Sign VS Web3JS - different results #486

Closed
relaxbao opened this issue Apr 8, 2018 · 3 comments
Closed

Web3J Sign VS Web3JS - different results #486

relaxbao opened this issue Apr 8, 2018 · 3 comments
Assignees
Labels
stale no activity for 21 days

Comments

@relaxbao
Copy link

relaxbao commented Apr 8, 2018

hello, I'm using Web3J version 3.3.1。when I sign the same message(eg:"TEST"), I wondered why i get diffierent signatures using web3js and web3j. the verify function in the contract are different. .

java snippet

        String message = "TEST";
        String prefix =  "\u0019Ethereum Signed Message:\n" + message.length();
        byte[] data = Hash.sha3((prefix + message).getBytes());
        System.out.println("data: " + Numeric.toHexString(data));
        Sign.SignatureData signature = Sign.signMessage(data, credentials.getEcKeyPair());

verify function in the contract

   function verify( bytes32 hash, uint8 v, bytes32 r, bytes32 s) constant returns(address retAddr) {
      bytes32 prefixedHash = sha3(hash);
      return ecrecover(prefixedHash, v, r, s);
    }

JavaScript snippet

var msgHash =web3.sha3('TEST')
var signature = eth.sign(eth.accounts[1],msgHash)

verify function in the contract

function verify( bytes32 hash, uint8 v, bytes32 r, bytes32 s) constant returns(address retAddr) {
      bytes memory prefix = "\x19Ethereum Signed Message:\n32";
      bytes32 prefixedHash = sha3(prefix, hash);
      return ecrecover(prefixedHash, v, r, s);
    }

I saw the issues #208 #476 , and the following test:
https://github.com/web3j/web3j/blob/51f88364b8899ff8d89fd7bb3671d7b3624afe4d/crypto/src/test/java/org/web3j/crypto/ECRecoverTest.java.
how can I use the same verify function in contract no matter web3j or web3js? Thank you!

@ChocolateSlayer
Copy link

See my answer there #208 if still relevant.
That's how I can use the same verify function in contract for signatures created by web3j and web3js

@AlexandrouR
Copy link
Contributor

is this still an issue ?

@AlexandrouR AlexandrouR self-assigned this Jul 18, 2019
@AlexandrouR AlexandrouR added the awaiting-user-input Require more info or input from user label Jul 18, 2019
@AlexandrouR AlexandrouR added stale no activity for 21 days and removed awaiting-user-input Require more info or input from user labels Aug 8, 2019
@AlexandrouR
Copy link
Contributor

Issue closed due to inactivity.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
stale no activity for 21 days
Projects
None yet
Development

No branches or pull requests

3 participants