Package org.ethereum.crypto

Examples of org.ethereum.crypto.ECKey$ECDSASignature


  public Account() {
  }

    public void init(){
        this.ecKey = new ECKey(Utils.getRandom());
        address = this.ecKey.getAddress();
    }
View Full Code Here


        String expected = "f87302f870808b00d3c21bcecceda10000009479b08ad8787060333663d19704909ee7b1903e588609184e72a000824255801ca00f410a70e42b2c9854a8421d32c87c370a2b9fff0a27f9f031bb4443681d73b5a018a7dc4c4f9dee9f3dc35cb96ca15859aa27e219a8e4a8547be6bd3206979858";

        BigInteger value = new BigInteger("1000000000000000000000000");

        byte[] privKey = HashUtil.sha3("cat".getBytes());
        ECKey ecKey = ECKey.fromPrivate(privKey);

        byte[] gasPrice=  Hex.decode("09184e72a000");
        byte[] gas =      Hex.decode("4255");

        Transaction tx = new Transaction(null, value.toByteArray(),
                ecKey.getAddress(),  gasPrice, gas, null);

        tx.sign(privKey);
        tx.getEncoded();

        Set<Transaction> txs = new HashSet<>(Arrays.asList(tx));
View Full Code Here

    Assert.assertEquals(1866897155, ECKey.fromPrivate(privateKey).hashCode());
  }

  @Test
  public void testECKey() {
    ECKey key = new ECKey();
    assertTrue(key.isPubKeyCanonical());
    assertNotNull(key.getPubKey());
    assertNotNull(key.getPrivKeyBytes());
    log.debug(Hex.toHexString(key.getPrivKeyBytes()) + " :Generated privkey");
    log.debug(Hex.toHexString(key.getPubKey()) + " :Generated pubkey");
  }
View Full Code Here

    log.debug(Hex.toHexString(key.getPubKey()) + " :Generated pubkey");
  }

  @Test
  public void testFromPrivateKey() {
    ECKey key = ECKey.fromPrivate(privateKey).decompress();
    assertTrue(key.isPubKeyCanonical());
    assertTrue(key.hasPrivKey());
    assertArrayEquals(pubKey, key.getPubKey());
  }
View Full Code Here

    assertArrayEquals(pubKey, key.getPubKey());
  }

  @Test(expected=IllegalArgumentException.class)
  public void testPrivatePublicKeyBytesNoArg() {
    new ECKey(null, null);
    fail("Expecting an IllegalArgumentException for using only null-parameters");
  }
View Full Code Here

    fail("Expecting an IllegalArgumentException for using only null-parameters");
  }

  @Test
  public void testIsPubKeyOnly() {
    ECKey key = ECKey.fromPublicOnly(pubKey);
    assertTrue(key.isPubKeyCanonical());
    assertTrue(key.isPubKeyOnly());
    assertArrayEquals(key.getPubKey(), pubKey);
  }
View Full Code Here

    assertArrayEquals(compressedPubKey, pubFromPriv);
  }

  @Test
  public void testGetAddress() {
    ECKey key = ECKey.fromPublicOnly(pubKey);
    assertArrayEquals(Hex.decode(address), key.getAddress());
  }
View Full Code Here

    assertArrayEquals(Hex.decode(address), key.getAddress());
  }

  @Test
  public void testToString() {
        ECKey key = ECKey.fromPrivate(BigInteger.TEN); // An example private key.
        assertEquals("pub:04a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7893aba425419bc27a3b6c7e693a24c696f794c2ed877a1593cbee53b037368d7", key.toString());
  }
View Full Code Here

  }

  @Test
  public void testEthereumSign() throws IOException {
    // TODO: Understand why key must be decompressed for this to work
    ECKey key = ECKey.fromPrivate(privateKey).decompress();
        System.out.println("Secret\t: " + Hex.toHexString(key.getPrivKeyBytes()));
        System.out.println("Pubkey\t: " + Hex.toHexString(key.getPubKey()));
        System.out.println("Data\t: " + exampleMessage);
        byte[] messageHash = HashUtil.sha3(exampleMessage.getBytes());
        ECDSASignature signature = key.sign(messageHash);
        String output = signature.toBase64();
        System.out.println("Signtr\t: " + output + " (Base64, length: " + output.length() + ")");
        assertEquals(sigBase64, output);
  }
View Full Code Here

        assertEquals(sigBase64, output);
  }
 
    @Test
    public void testVerifySignature1() {
      ECKey key = ECKey.fromPublicOnly(pubKey);
        BigInteger r = new BigInteger("28157690258821599598544026901946453245423343069728565040002908283498585537001");
        BigInteger s = new BigInteger("30212485197630673222315826773656074299979444367665131281281249560925428307087");
        ECDSASignature sig = ECDSASignature.fromComponents(r.toByteArray(), s.toByteArray(), (byte) 28);
        key.verify(HashUtil.sha3(exampleMessage.getBytes()), sig);
    }
View Full Code Here

TOP

Related Classes of org.ethereum.crypto.ECKey$ECDSASignature

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.