I'm using web3J
version 3.0.0-alpha4
and hit following problem. When I sign the same raw message (it's simply string like "TEST" for now) I get different signatures using web3js
i web3j
. The signature from web3js
is valid (and web3j is not), I test it using solidity ecrecover
function. It's worth to mention that hashes as you can see in the snippets are the same.
Java snippet:
String privateKey1 = "7196933fe363871920c59be78aa5c478bf6e6271532db5d0ce3b090518f91f03";
Credentials credentials = Credentials.create(privateKey1);
String testString = "\u0019Ethereum Signed Message:\n"+"TEST".length()+"TEST";
Sign.SignatureData signatureData = Sign.signMessage(testString.getBytes(), credentials.getEcKeyPair());
System.out.println("R: "+Numeric.toHexString(signatureData.getR()));
System.out.println("S: "+Numeric.toHexString(signatureData.getS()));
System.out.println("V: "+signatureData.getV());
Java result:
R: 0x9aae2a66c2c4b3d12f36ce26b59024b6deadcb8ac51f4bd14188feaec15b6c2f
S: 0x53037c38b48243e2bb852d7f857ccc2c24c1bb1c1842bb30f0bea555c995a626
V: 28
JS snippet:
hash = web3.sha3('TEST');
sig = web3.eth.sign(web3.eth.accounts[0], hash);
r = "0x"+sig.substr(2,64);
s = "0x"+sig.substr(66,64)
v = parseInt(sig.substr(130,2))+27;
JS result (testRPC 4.1.3 console):
truffle(development)> r
'0x95c8ab63220d912e878d5178f042c7199cade577e39adc00745cf5fdbef0adb0'
truffle(development)> s
'0x61b0bac1eee0cec838e9e7a934df3b6431e0b786ecff772d4ea3b39fc50f9a32'
truffle(development)> v
28
From the Ethereum documentation I started add "\u0019Ethereum Signed Message:\n"+"TEST".length()
to the message, but it still didn't resolve the difference.