public String getSignature() { return getResult(); } }
@Test public void testEthSign() { buildResponse( "{\n" + " \"id\":1,\n" + " \"jsonrpc\": \"2.0\",\n" + " \"result\": " + "\"0xbd685c98ec39490f50d15c67ba2a8e9b5b1d6d7601fca80b295e7d717446bd8b712" + "7ea4871e996cdc8cae7690408b4e800f60ddac49d2ad34180e68f1da0aaf001\"\n" + "}" ); EthSign ethSign = deserialiseResponse(EthSign.class); assertThat(ethSign.getSignature(), is("0xbd685c98ec39490f50d15c67ba2a8e9b5b1d6d7601fca80b295e7d717446bd8b7127ea4871e9" + "96cdc8cae7690408b4e800f60ddac49d2ad34180e68f1da0aaf001")); }
@Test public void testSignTransaction() throws Exception { boolean accountUnlocked = unlockAccount(); assertTrue(accountUnlocked); RawTransaction rawTransaction = createTransaction(); byte[] encoded = TransactionEncoder.encode(rawTransaction); byte[] hashed = Hash.sha3(encoded); EthSign ethSign = web3j.ethSign(ALICE.getAddress(), Numeric.toHexString(hashed)) .sendAsync().get(); String signature = ethSign.getSignature(); assertNotNull(signature); assertFalse(signature.isEmpty()); }
@InvokeOnHeader(Web3jConstants.ETH_SIGN) void ethSign(Message message) throws IOException { String address = message.getHeader(Web3jConstants.ADDRESS, configuration::getAddress, String.class); String sha3HashOfDataToSign = message.getHeader(Web3jConstants.SHA3_HASH_OF_DATA_TO_SIGN, configuration::getSha3HashOfDataToSign, String.class); Request<?, EthSign> request = web3j.ethSign(address, sha3HashOfDataToSign); setRequestId(message, request); EthSign response = request.send(); boolean hasError = checkForError(message, response); if (!hasError) { message.setBody(response.getSignature()); } }