use of org.tron.common.crypto.ECKey in project java-tron by tronprotocol.
the class WalletTest method testGetEcKey.
@Test
public void testGetEcKey() {
ECKey ecKey = new ECKey(Utils.getRandom());
ECKey ecKey2 = new ECKey(Utils.getRandom());
Wallet wallet = new Wallet(ecKey);
logger.info("ecKey address = {}", ByteArray.toHexString(ecKey.getAddress()));
logger.info("wallet address = {}", ByteArray.toHexString(wallet.getAddress()));
assertEquals("Wallet ECKey should match provided ECKey", wallet.getEcKey(), ecKey);
}
use of org.tron.common.crypto.ECKey in project java-tron by tronprotocol.
the class Node method instanceOf.
public static Node instanceOf(String addressOrEnode) {
try {
URI uri = new URI(addressOrEnode);
if (uri.getScheme().equals("enode")) {
return new Node(addressOrEnode);
}
} catch (URISyntaxException e) {
// continue
}
final ECKey generatedNodeKey = ECKey.fromPrivate(sha3(addressOrEnode.getBytes()));
final String generatedNodeId = Hex.toHexString(generatedNodeKey.getNodeId());
final Node node = new Node("enode://" + generatedNodeId + "@" + addressOrEnode);
node.isFakeNodeId = true;
return node;
}
use of org.tron.common.crypto.ECKey in project java-tron by tronprotocol.
the class Manager method getHomeNode.
public Node getHomeNode() {
final Args args = Args.getInstance();
Set<Node> nodes = this.peersStore.get("home".getBytes());
if (nodes.size() > 0) {
return nodes.stream().findFirst().get();
} else {
Node node = new Node(new ECKey().getNodeId(), args.getNodeExternalIp(), args.getNodeListenPort());
nodes.add(node);
this.peersStore.put("home".getBytes(), nodes);
return node;
}
}
use of org.tron.common.crypto.ECKey in project java-tron by tronprotocol.
the class BlockCapsule method sign.
public void sign(byte[] privateKey) {
// TODO private_key == null
ECKey ecKey = ECKey.fromPrivate(privateKey);
ECDSASignature signature = ecKey.sign(getRawHash().getBytes());
ByteString sig = ByteString.copyFrom(signature.toBase64().getBytes());
BlockHeader blockHeader = this.block.getBlockHeader().toBuilder().setWitnessSignature(sig).build();
this.block = this.block.toBuilder().setBlockHeader(blockHeader).build();
}
use of org.tron.common.crypto.ECKey in project java-tron by tronprotocol.
the class TransactionCapsule method sign.
public void sign(byte[] privateKey) {
ECKey ecKey = ECKey.fromPrivate(privateKey);
ECDSASignature signature = ecKey.sign(getRawHash().getBytes());
ByteString sig = ByteString.copyFrom(signature.toBase64().getBytes());
this.transaction = this.transaction.toBuilder().addSignature(sig).build();
}
Aggregations