Java Code Examples for org.web3j.crypto.Sign#signMessage()
The following examples show how to use
org.web3j.crypto.Sign#signMessage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UniversalLinkTest.java From alpha-wallet-android with MIT License | 5 votes |
private byte[] getSignature(byte[] message) throws SalesOrderMalformed { Sign.SignatureData sigData = Sign.signMessage(message, testKey); byte[] sig = new byte[65]; try { System.arraycopy(sigData.getR(), 0, sig, 0, 32); System.arraycopy(sigData.getS(), 0, sig, 32, 32); System.arraycopy(sigData.getV(), 0, sig, 64, 1); } catch (IndexOutOfBoundsException e) { throw new SalesOrderMalformed("Signature shorter than expected 256"); } return sig; }
Example 2
Source File: UniversalLinkTest.java From alpha-wallet-android with MIT License | 5 votes |
private String ecRecoverAddress() throws Exception { String testSigMsg = "obtain public key"; Sign.SignatureData testSig = Sign.signMessage(testSigMsg.getBytes(), testKey); BigInteger recoveredKey = Sign.signedMessageToKey(testSigMsg.getBytes(), testSig); return Keys.getAddress(recoveredKey); }
Example 3
Source File: UniversalLinkTypeTest.java From alpha-wallet-android with MIT License | 5 votes |
private byte[] getSignature(byte[] message) throws SalesOrderMalformed { Sign.SignatureData sigData = Sign.signMessage(message, testKey); byte[] sig = new byte[65]; try { System.arraycopy(sigData.getR(), 0, sig, 0, 32); System.arraycopy(sigData.getS(), 0, sig, 32, 32); System.arraycopy(sigData.getV(), 0, sig, 64, 1); } catch (IndexOutOfBoundsException e) { throw new SalesOrderMalformed("Signature shorter than expected 256"); } return sig; }
Example 4
Source File: UniversalLinkTypeTest.java From alpha-wallet-android with MIT License | 5 votes |
private String ecRecoverAddress() throws Exception { String testSigMsg = "obtain public key"; Sign.SignatureData testSig = Sign.signMessage(testSigMsg.getBytes(), testKey); BigInteger recoveredKey = Sign.signedMessageToKey(testSigMsg.getBytes(), testSig); return Keys.getAddress(recoveredKey); }
Example 5
Source File: PrivateTransactionEncoder.java From web3j with Apache License 2.0 | 5 votes |
public static byte[] signMessage( final RawPrivateTransaction rawTransaction, final Credentials credentials) { final byte[] encodedTransaction = encode(rawTransaction); final Sign.SignatureData signatureData = Sign.signMessage(encodedTransaction, credentials.getEcKeyPair()); return encode(rawTransaction, signatureData); }
Example 6
Source File: PrivateTransactionEncoder.java From web3j with Apache License 2.0 | 5 votes |
public static byte[] signMessage( final RawPrivateTransaction rawTransaction, final long chainId, final Credentials credentials) { final byte[] encodedTransaction = encode(rawTransaction, chainId); final Sign.SignatureData signatureData = Sign.signMessage(encodedTransaction, credentials.getEcKeyPair()); final Sign.SignatureData eip155SignatureData = TransactionEncoder.createEip155SignatureData(signatureData, chainId); return encode(rawTransaction, eip155SignatureData); }
Example 7
Source File: EdconLinkGenerator.java From alpha-wallet-android with MIT License | 4 votes |
private byte[] signMagicLink(byte[] signData) { ECKeyPair ecKeyPair = ECKeyPair.create(privateKey); Sign.SignatureData signatureData = Sign.signMessage(signData, ecKeyPair); return bytesFromSignature(signatureData); }
Example 8
Source File: SpawnableLinkGenerator.java From alpha-wallet-android with MIT License | 4 votes |
private byte[] signMagicLink(byte[] signData) { ECKeyPair ecKeyPair = ECKeyPair.create(privateKey); Sign.SignatureData signatureData = Sign.signMessage(signData, ecKeyPair); return bytesFromSignature(signatureData); }
Example 9
Source File: BesuPrivacyQuickstartIntegrationTest.java From web3j with Apache License 2.0 | 4 votes |
@Test public void simplePrivateTransactions() throws Exception { // Build new privacy group using the create API final Base64String privacyGroupId = nodeBob.privCreatePrivacyGroup( Arrays.asList( ENCLAVE_KEY_ALICE, ENCLAVE_KEY_BOB, ENCLAVE_KEY_CHARLIE), "AliceBobCharlie", "AliceBobCharlie group") .send() .getPrivacyGroupId(); final BigInteger nonce = nodeCharlie .privGetTransactionCount(ALICE.getAddress(), privacyGroupId) .send() .getTransactionCount(); final RawPrivateTransaction rawPrivateTransaction = RawPrivateTransaction.createContractTransaction( nonce, ZERO_GAS_PROVIDER.getGasPrice(), ZERO_GAS_PROVIDER.getGasLimit(), HUMAN_STANDARD_TOKEN_BINARY, ENCLAVE_KEY_ALICE, privacyGroupId, RESTRICTED); final String signedTransactionData = Numeric.toHexString( PrivateTransactionEncoder.signMessage(rawPrivateTransaction, 2018, ALICE)); final String transactionHash = nodeAlice.eeaSendRawTransaction(signedTransactionData).send().getTransactionHash(); final PollingPrivateTransactionReceiptProcessor receiptProcessor = new PollingPrivateTransactionReceiptProcessor(nodeAlice, 1 * 1000, 120); final PrivateTransactionReceipt receipt = receiptProcessor.waitForTransactionReceipt(transactionHash); assertEquals(receipt.getFrom(), (ALICE.getAddress())); assertEquals(receipt.getLogs().size(), (0)); assertNull(receipt.getTo()); assertNotNull(receipt.getContractAddress()); assertNotNull(receipt.getStatus()); assertNull(receipt.getRevertReason()); final PrivateTransactionWithPrivacyGroup privateTransaction = (PrivateTransactionWithPrivacyGroup) nodeAlice .privGetPrivateTransaction(transactionHash) .send() .getPrivateTransaction() .get(); assertEquals(privateTransaction.getFrom(), (ALICE.getAddress())); assertEquals(privateTransaction.getGas(), (ZERO_GAS_PROVIDER.getGasLimit())); assertEquals(privateTransaction.getGasPrice(), (ZERO_GAS_PROVIDER.getGasPrice())); assertEquals(privateTransaction.getNonce(), (nonce)); final byte[] encodedTransaction = PrivateTransactionEncoder.encode(rawPrivateTransaction, 2018); final Sign.SignatureData signatureData = Sign.signMessage(encodedTransaction, ALICE.getEcKeyPair()); final Sign.SignatureData eip155SignatureData = TransactionEncoder.createEip155SignatureData(signatureData, 2018); assertEquals( Numeric.toBytesPadded(BigInteger.valueOf(privateTransaction.getV()), 2), (eip155SignatureData.getV())); assertEquals( Numeric.hexStringToByteArray(privateTransaction.getR()), (eip155SignatureData.getR())); assertEquals( Numeric.hexStringToByteArray(privateTransaction.getS()), (eip155SignatureData.getS())); assertEquals(privateTransaction.getPrivateFrom(), (ENCLAVE_KEY_ALICE)); assertEquals(privateTransaction.getPrivacyGroupId(), (privacyGroupId)); assertEquals(privateTransaction.getRestriction(), (RESTRICTED)); assertNull(privateTransaction.getTo()); }