use of org.hyperledger.besu.crypto.SECPPrivateKey in project besu by hyperledger.
the class PublicKeySubCommandTest method callingPublicKeyExportAddressSubCommandWithPrivateKeyFileMustWriteKeyToStandardOutput.
@Test
public void callingPublicKeyExportAddressSubCommandWithPrivateKeyFileMustWriteKeyToStandardOutput() throws IOException {
final SECPPrivateKey privateKey = SECPPrivateKey.create(Bytes32.fromHexString("0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63"), ALGORITHM);
final KeyPair keyPair = KeyPair.create(privateKey, curve, ALGORITHM);
final Path privateKeyFile = Files.createTempFile("private", "address");
Files.writeString(privateKeyFile, privateKey.toString());
parseCommand(PUBLIC_KEY_SUBCOMMAND_NAME, PUBLIC_KEY_EXPORT_ADDRESS_SUBCOMMAND_NAME, "--node-private-key-file", privateKeyFile.toString());
final String expectedOutputStart = Util.publicKeyToAddress(keyPair.getPublicKey()).toString();
assertThat(commandOutput.toString(UTF_8)).startsWith(expectedOutputStart);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
use of org.hyperledger.besu.crypto.SECPPrivateKey in project besu by hyperledger.
the class PublicKeySubCommandTest method callingPublicKeyExportAddressSubCommandWithoutEcCurveNameDoesNotConfiguresSignatureAlgorithmFactory.
@Test
public void callingPublicKeyExportAddressSubCommandWithoutEcCurveNameDoesNotConfiguresSignatureAlgorithmFactory() throws Exception {
assertThat(SignatureAlgorithmFactory.isInstanceSet()).isFalse();
final SECPPrivateKey privateKey = SECPPrivateKey.create(Bytes32.fromHexString("0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63"), ALGORITHM);
final Path privateKeyFile = Files.createTempFile("private", "address");
Files.writeString(privateKeyFile, privateKey.toString());
parseCommand(PUBLIC_KEY_SUBCOMMAND_NAME, PUBLIC_KEY_EXPORT_ADDRESS_SUBCOMMAND_NAME, "--node-private-key-file", privateKeyFile.toString());
assertThat(SignatureAlgorithmFactory.isInstanceSet()).isFalse();
}
use of org.hyperledger.besu.crypto.SECPPrivateKey in project besu by hyperledger.
the class OperatorSubCommandTest method checkPublicKey.
private void checkPublicKey(final File dir, final SignatureAlgorithm signatureAlgorithm) throws IOException {
String publicKeyHex = readPubFile(dir);
String privateKeyHex = readPrivFile(dir);
SECPPrivateKey privateKey = signatureAlgorithm.createPrivateKey(Bytes32.fromHexString(privateKeyHex));
SECPPublicKey expectedPublicKey = signatureAlgorithm.createPublicKey(privateKey);
assertThat(publicKeyHex).isEqualTo(expectedPublicKey.getEncodedBytes().toHexString());
}
use of org.hyperledger.besu.crypto.SECPPrivateKey in project besu by hyperledger.
the class TestSigningPrivateMarkerTransactionFactory method setSigningKeyEnbaled.
public void setSigningKeyEnbaled(final String privateMarkerTransactionSigningKey) {
final SignatureAlgorithm algorithm = SignatureAlgorithmFactory.getInstance();
final SECPPrivateKey privateKey = algorithm.createPrivateKey(Bytes32.fromHexString(privateMarkerTransactionSigningKey));
aliceFixedSigningKey = algorithm.createKeyPair(privateKey);
sender = extract(Hash.hash(aliceFixedSigningKey.getPublicKey().getEncodedBytes()));
}
use of org.hyperledger.besu.crypto.SECPPrivateKey in project besu by hyperledger.
the class SignUtil method signTransaction.
public static byte[] signTransaction(final RawTransaction transaction, final Account sender, final SignatureAlgorithm signatureAlgorithm, final Optional<BigInteger> chainId) {
byte[] encodedTransaction = TransactionEncoder.encode(transaction);
Credentials credentials = sender.web3jCredentialsOrThrow();
SECPPrivateKey privateKey = signatureAlgorithm.createPrivateKey(credentials.getEcKeyPair().getPrivateKey());
byte[] transactionHash = org.web3j.crypto.Hash.sha3(encodedTransaction);
SECPSignature secpSignature = signatureAlgorithm.sign(Bytes32.wrap(transactionHash), signatureAlgorithm.createKeyPair(privateKey));
Sign.SignatureData signature = new Sign.SignatureData(calculateV(secpSignature, chainId), secpSignature.getR().toByteArray(), secpSignature.getS().toByteArray());
List<RlpType> values = getTxRlpValues(transaction, signature, secpSignature);
RlpList rlpList = new RlpList(values);
byte[] encoded = RlpEncoder.encode(rlpList);
if (transaction.getType().equals(TransactionType.LEGACY)) {
return encoded;
}
return ByteBuffer.allocate(encoded.length + 1).put(transaction.getType().getRlpType()).put(encoded).array();
}
Aggregations