use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class TransactionData method getSignedTransaction.
public Transaction getSignedTransaction(final NonceProvider nonceProvider) {
final KeyPair keyPair = SIGNATURE_ALGORITHM.get().createKeyPair(privateKey);
final Address fromAddress = Address.extract(keyPair.getPublicKey());
final long nonce = nonceProvider.get(fromAddress);
return Transaction.builder().gasLimit(gasLimit).gasPrice(gasPrice).nonce(nonce).payload(data).value(value).to(to.orElse(null)).guessType().signAndBuild(keyPair);
}
use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class GenerateBlockchainConfig method generateNodeKeypair.
/**
* Generate a keypair for a node.
*
* @param node The number of the node.
*/
private void generateNodeKeypair(final int node) {
try {
LOG.info("Generating keypair for node {}.", node);
final KeyPair keyPair = SIGNATURE_ALGORITHM.get().generateKeyPair();
writeKeypair(keyPair.getPublicKey(), keyPair.getPrivateKey());
} catch (final IOException e) {
LOG.error("An error occurred while trying to generate node keypair.", e);
}
}
use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class FixedKeySigningPrivateMarkerTransactionFactoryTest method createsFullyPopulatedPrivateMarkerTransactionUsingProvidedNonce.
@Test
public void createsFullyPopulatedPrivateMarkerTransactionUsingProvidedNonce() {
final PrivateTransaction privTransaction = mock(PrivateTransaction.class);
final Wei gasPrice = Wei.of(100);
final long gasLimit = 500;
final long providedNonce = 100;
final String enclaveKey = "pmtLookupKey";
final KeyPair signingKeys = SignatureAlgorithmFactory.getInstance().generateKeyPair();
final Address precompiledAddress = Address.fromHexString("1");
final FixedKeySigningPrivateMarkerTransactionFactory factory = new FixedKeySigningPrivateMarkerTransactionFactory(signingKeys);
final Transaction unsignedPrivateMarkerTransaction = new Transaction.Builder().type(TransactionType.FRONTIER).nonce(providedNonce).gasPrice(gasPrice).gasLimit(gasLimit).to(precompiledAddress).value(Wei.ZERO).payload(Bytes.fromBase64String(enclaveKey)).build();
final Transaction transaction = Transaction.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, ""));
assertThat(transaction.getNonce()).isEqualTo(providedNonce);
assertThat(transaction.getGasLimit()).isEqualTo(gasLimit);
assertThat(transaction.getGasPrice().get()).isEqualTo(gasPrice);
assertThat(transaction.getValue()).isEqualTo(Wei.ZERO);
assertThat(transaction.getSender()).isEqualTo(Util.publicKeyToAddress(signingKeys.getPublicKey()));
assertThat(transaction.getTo()).isEqualTo(Optional.of(precompiledAddress));
assertThat(transaction.getPayload()).isEqualTo(Bytes.fromBase64String(enclaveKey));
final Transaction nextTransaction = Transaction.readFrom(factory.create(unsignedPrivateMarkerTransaction, privTransaction, ""));
assertThat(nextTransaction.getSender()).isEqualTo(transaction.getSender());
}
use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class MainnetTransactionValidatorTest method transactionWithNullSenderCanBeValidIfGasPriceAndValueIsZero.
@Test
public void transactionWithNullSenderCanBeValidIfGasPriceAndValueIsZero() {
final MainnetTransactionValidator validator = new MainnetTransactionValidator(gasCalculator, false, Optional.of(BigInteger.ONE), defaultGoQuorumCompatibilityMode);
final TransactionTestFixture builder = new TransactionTestFixture();
final KeyPair senderKeyPair = SIGNATURE_ALGORITHM.get().generateKeyPair();
final Address arbitrarySender = Address.fromHexString("1");
builder.gasPrice(Wei.ZERO).nonce(0).sender(arbitrarySender).value(Wei.ZERO);
assertThat(validator.validateForSender(builder.createTransaction(senderKeyPair), null, false)).isEqualTo(ValidationResult.valid());
}
use of org.hyperledger.besu.crypto.KeyPair in project besu by hyperledger.
the class CliqueExtraDataValidationRuleTest method signerNotInExpectedValidatorsFailsValidation.
@Test
public void signerNotInExpectedValidatorsFailsValidation() {
final KeyPair otherSigner = SignatureAlgorithmFactory.getInstance().generateKeyPair();
final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture();
final BlockHeader parent = headerBuilder.number(1).buildHeader();
headerBuilder.number(2);
final BlockHeader badlySignedChild = TestHelpers.createCliqueSignedBlockHeader(headerBuilder, otherSigner, Lists.newArrayList());
final CliqueExtraDataValidationRule rule = new CliqueExtraDataValidationRule(new EpochManager(10));
assertThat(rule.validate(badlySignedChild, parent, cliqueProtocolContext)).isFalse();
}
Aggregations