Search in sources :

Example 6 with ECKey

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);
}
Also used : Wallet(org.tron.core.Wallet) ECKey(org.tron.common.crypto.ECKey) Test(org.junit.Test)

Example 7 with 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;
}
Also used : ECKey(org.tron.common.crypto.ECKey) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 8 with ECKey

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;
    }
}
Also used : Args(org.tron.core.config.args.Args) Node(org.tron.common.overlay.discover.Node) ECKey(org.tron.common.crypto.ECKey)

Example 9 with ECKey

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();
}
Also used : ByteString(com.google.protobuf.ByteString) ECDSASignature(org.tron.common.crypto.ECKey.ECDSASignature) ECKey(org.tron.common.crypto.ECKey) BlockHeader(org.tron.protos.Protocol.BlockHeader)

Example 10 with ECKey

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();
}
Also used : ByteString(com.google.protobuf.ByteString) ECDSASignature(org.tron.common.crypto.ECKey.ECDSASignature) ECKey(org.tron.common.crypto.ECKey)

Aggregations

ECKey (org.tron.common.crypto.ECKey)10 Test (org.junit.Test)4 ByteString (com.google.protobuf.ByteString)3 ECDSASignature (org.tron.common.crypto.ECKey.ECDSASignature)2 Wallet (org.tron.core.Wallet)2 WitnessCapsule (org.tron.core.capsule.WitnessCapsule)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 Writer (java.io.Writer)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Properties (java.util.Properties)1 Node (org.tron.common.overlay.discover.Node)1 BlockCapsule (org.tron.core.capsule.BlockCapsule)1 Args (org.tron.core.config.args.Args)1