web3j icon indicating copy to clipboard operation
web3j copied to clipboard

Signatures StructuredDataEncoder differ in web3J and web3js

Open lizimu2018 opened this issue 3 years ago • 1 comments

Signatures StructuredDataEncoder data differ in web3J and web3js(with Metamask)

I want to call remove liquidity with java

Issue_context

web3j version:4.8.6 jdk version:1.8

This is my java code `

    ECKeyPair ecKeyPair = ECKeyPair.create(new BigInteger(account.getPrivateKey(), 16));
    StructuredDataEncoder structuredDataEncoder = new StructuredDataEncoder(json);
    Sign.SignatureData signatureData = Sign.signPrefixedMessage(structuredDataEncoder.hashStructuredData(), ecKeyPair);
    List<Type> inputParameters = new ArrayList<>();
    inputParameters.add(new Uint8(Numeric.toBigInt(signatureData.getV())));
    inputParameters.add(new Bytes32(signatureData.getR()));
    inputParameters.add(new Bytes32(signatureData.getS()));
    String data =  FunctionEncoder.encodeConstructor(inputParameters);
    System.out.println(data); 

`

This is json content { "types":{ "EIP712Domain":[ { "name":"name", "type":"string" }, { "name":"version", "type":"string" }, { "name":"chainId", "type":"uint256" }, { "name":"verifyingContract", "type":"address" } ], "Permit":[ { "name":"owner", "type":"address" }, { "name":"spender", "type":"address" }, { "name":"value", "type":"uint256" }, { "name":"nonce", "type":"uint256" }, { "name":"deadline", "type":"uint256" } ] }, "domain":{ "name":"Cherry LPs", "version":"1", "chainId":66, "verifyingContract":"0x919cEE4766eD56CA3FA5028B16BF22D43a7A5d43" }, "primaryType":"Permit", "message":{ "owner":"0xd41ef6af97cb0f54eab5c1ebfe62478f40a78259", "spender":"0x865bfde337C8aFBffF144Ff4C29f9404EBb22b15", "value":"1000000000000000000", "nonce":"0x02", "deadline":1629271118 } }

lizimu2018 avatar Aug 18 '21 07:08 lizimu2018

I think you should use signMessage(structuredDataEncoder.hashStructuredData(), ecKeyPair, false) instead of signPrefixedMessage(structuredDataEncoder.hashStructuredData(), ecKeyPair)

alexdupre avatar Oct 27 '21 07:10 alexdupre