@Override public void setPrivateKey(BigInteger key) { if (null != key) { this.key = ECKey.fromPrivate(key); } }
/** * Creates an ECKey given the private key only. The public key is calculated from it (this is slow). The resulting * public key is compressed. */ public static ECKey fromPrivate(BigInteger privKey) { return fromPrivate(privKey, true); }
/** * Creates an ECKey given the private key only. The public key is calculated from it (this is slow). The resulting * public key is compressed. */ public static ECKey fromPrivate(byte[] privKeyBytes) { return fromPrivate(new BigInteger(1, privKeyBytes)); }
/** * Creates an ECKey given the private key only. The public key is calculated from it (this is slow), either * compressed or not. */ public static ECKey fromPrivate(byte[] privKeyBytes, boolean compressed) { return fromPrivate(new BigInteger(1, privKeyBytes), compressed); }
/** * Creates an ECKey given the private key only. The public key is calculated from it (this is slow), either * compressed or not. */ public static ECKey fromPrivate(byte[] privKeyBytes, boolean compressed) { return fromPrivate(new BigInteger(1, privKeyBytes), compressed); }
/** * Creates an ECKey given the private key only. The public key is calculated from it (this is slow), either * compressed or not. */ public static ECKey fromPrivate(byte[] privKeyBytes, boolean compressed) { return fromPrivate(new BigInteger(1, privKeyBytes), compressed); }
/** * Creates an ECKey given the private key only. The public key is calculated from it (this is slow). The resulting * public key is compressed. */ public static ECKey fromPrivate(byte[] privKeyBytes) { return fromPrivate(new BigInteger(1, privKeyBytes)); }
/** * Returns an ECKey created from this encoded private key. */ public ECKey getKey() { final ECKey key = ECKey.fromPrivate(bytes); return compressed ? key : key.decompress(); }
/** * Returns an ECKey created from this encoded private key. */ public ECKey getKey() { final ECKey key = ECKey.fromPrivate(bytes); return compressed ? key : key.decompress(); }
private ECKey decodeHexPK(String hex, boolean compressed) { byte[] privBytes = Hex.decode(hex); // Prepend a zero byte to make the biginteger unsigned byte[] appendZeroByte = ArrayUtils.addAll(new byte[1], privBytes); return ECKey.fromPrivate(new BigInteger(appendZeroByte), compressed); }
/** * Returns an ECKey created from this encoded private key. */ public ECKey getKey() { return ECKey.fromPrivate(Arrays.copyOf(bytes, 32), isPubKeyCompressed()); }
private TypedKey getFromWifKey() { ImmutableList.Builder<CoinType> builder = ImmutableList.builder(); for (CoinType type : CoinID.getSupportedCoins()) { if (version == type.getDumpedPrivateKeyHeader()) { builder.add(type); } } final ECKey key = compressed ? ECKey.fromPrivate(content) : ECKey.fromPrivate(content).decompress(); return new TypedKey(builder.build(), key); }
private TypedKey getFromMiniKey() { final ECKey key = ECKey.fromPrivate(content).decompress(); return new TypedKey(CoinID.getSupportedCoins(), key); } }
@Before public void setUp() throws Exception { final ECKey key = ECKey.fromPrivate(TEST_KEY_PRIV); params = new UnitTestParams() { @Override public byte[] getAlertSigningKey() { return key.getPubKey(); } }; }
@Test public void fromKeys() { ECKey key = ECKey.fromPrivate(Utils.HEX.decode("00905b93f990267f4104f316261fc10f9f983551f9ef160854f40102eb71cffdcc")); Wallet wallet = Wallet.fromKeys(PARAMS, Arrays.asList(key)); assertEquals(1, wallet.getImportedKeys().size()); assertEquals(key, wallet.getImportedKeys().get(0)); wallet.upgradeToDeterministic(null); String seed = wallet.getKeyChainSeed().toHexString(); assertEquals("5ca8cd6c01aa004d3c5396c628b78a4a89462f412f460a845b594ac42eceaa264b0e14dcd4fe73d4ed08ce06f4c28facfa85042d26d784ab2798a870bb7af556", seed); }
@Test public void testGetPrivateKeyAsHex() throws Exception { ECKey key = ECKey.fromPrivate(BigInteger.TEN).decompress(); // An example private key. assertEquals("000000000000000000000000000000000000000000000000000000000000000a", key.getPrivateKeyAsHex()); }
@Test public void testGetPublicKeyAsHex() throws Exception { ECKey key = ECKey.fromPrivate(BigInteger.TEN).decompress(); // An example private key. assertEquals("04a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7893aba425419bc27a3b6c7e693a24c696f794c2ed877a1593cbee53b037368d7", key.getPublicKeyAsHex()); }
@Test public void testSignatures() throws Exception { // Test that we can construct an ECKey from a private key (deriving the public from the private), then signing // a message with it. BigInteger privkey = new BigInteger(1, HEX.decode("180cb41c7c600be951b5d3d0a7334acc7506173875834f7a6c4c786a28fcbb19")); ECKey key = ECKey.fromPrivate(privkey); byte[] output = key.sign(Sha256Hash.ZERO_HASH).encodeToDER(); assertTrue(key.verify(Sha256Hash.ZERO_HASH.getBytes(), output)); // Test interop with a signature from elsewhere. byte[] sig = HEX.decode( "3046022100dffbc26774fc841bbe1c1362fd643609c6e42dcb274763476d87af2c0597e89e022100c59e3c13b96b316cae9fa0ab0260612c7a133a6fe2b3445b6bf80b3123bf274d"); assertTrue(key.verify(Sha256Hash.ZERO_HASH.getBytes(), sig)); }
@Test(expected = java.lang.IllegalStateException.class) public void sendCoinsNoBroadcasterTest() throws InsufficientMoneyException { ECKey key = ECKey.fromPrivate(BigInteger.TEN); SendRequest req = SendRequest.to(OTHER_ADDRESS.getParameters(), key, SATOSHI.multiply(12)); wallet.sendCoins(req); }
@Test public void sendCoinsWithBroadcasterTest() throws InsufficientMoneyException { ECKey key = ECKey.fromPrivate(BigInteger.TEN); receiveATransactionAmount(wallet, myAddress, Coin.COIN); MockTransactionBroadcaster broadcaster = new MockTransactionBroadcaster(wallet); wallet.setTransactionBroadcaster(broadcaster); SendRequest req = SendRequest.to(OTHER_ADDRESS.getParameters(), key, Coin.CENT); wallet.sendCoins(req); }