/** * Creates an ECKey that simply trusts the caller to ensure that point is really the result of multiplying the * generator point by the private key. This is used to speed things up when you know you have the right values * already. The compression state of pub will be preserved. */ public static ECKey fromPrivateAndPrecalculatedPublic(BigInteger priv, ECPoint pub) { return new ECKey(priv, pub); }
/** * Creates an ECKey that simply trusts the caller to ensure that point is really the result of multiplying the * generator point by the private key. This is used to speed things up when you know you have the right values * already. The compression state of pub will be preserved. */ public static ECKey fromPrivateAndPrecalculatedPublic(BigInteger priv, ECPoint pub) { return new ECKey(priv, pub); }
/** * Creates an ECKey that simply trusts the caller to ensure that point is really the result of multiplying the * generator point by the private key. This is used to speed things up when you know you have the right values * already. The compression state of the point will be preserved. */ public static ECKey fromPrivateAndPrecalculatedPublic(byte[] priv, byte[] pub) { checkNotNull(priv); checkNotNull(pub); return new ECKey(new BigInteger(1, priv), CURVE.getCurve().decodePoint(pub)); }
/** * Creates an ECKey that cannot be used for signing, only verifying signatures, from the given encoded point. * The compression state of pub will be preserved. */ public static ECKey fromPublicOnly(byte[] pub) { return new ECKey(null, CURVE.getCurve().decodePoint(pub)); }
/** * Creates an ECKey that cannot be used for signing, only verifying signatures, from the given encoded point. * The compression state of pub will be preserved. */ public static ECKey fromPublicOnly(byte[] pub) { return new ECKey(null, CURVE.getCurve().decodePoint(pub)); }
/** * 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(BigInteger privKey, boolean compressed) { ECPoint point = publicPointFromPrivate(privKey); return new ECKey(privKey, getPointWithCompression(point, compressed)); }
/** * Returns a copy of this key, but with the public point represented in uncompressed form. Normally you would * never need this: it's for specialised scenarios or when backwards compatibility in encoded form is necessary. */ public ECKey decompress() { if (!pub.isCompressed()) return this; else return new ECKey(priv, decompressPoint(pub.get())); }
/** * Returns a copy of this key, but with the public point represented in uncompressed form. Normally you would * never need this: it's for specialised scenarios or when backwards compatibility in encoded form is necessary. */ public ECKey decompress() { if (!pub.isCompressed()) return this; else return new ECKey(priv, decompressPoint(pub.get())); }
public Channel () { keyServer = new ECKey(); channelStatus = new ChannelStatus(); anchorTxHash = Sha256Hash.wrap(Tools.getRandomByte(32)); masterPrivateKeyServer = Tools.getRandomByte(20); }
@Override protected void onSetupCompleted() { if (wallet().getImportedKeys().size() < 1) wallet().importKey(new ECKey()); wallet().allowSpendingUnconfirmedTransactions(); view.displayWalletPath(vWalletFile.getAbsolutePath()); setupWalletListeners(wallet()); Log.d("myLogs", "My address = " + wallet().freshReceiveAddress()); } };
@Test public void cloning() throws Exception { DumpedPrivateKey a = new DumpedPrivateKey(MAINNET, new ECKey().getPrivKeyBytes(), true); // TODO: Consider overriding clone() in DumpedPrivateKey to narrow the type DumpedPrivateKey b = (DumpedPrivateKey) a.clone(); assertEquals(a, b); assertNotSame(a, b); }
@Test public void testSomething() { String msg = "hello world"; Sha256Hash hash = Sha256Hash.of(msg.getBytes()); ECKey signingKey = new ECKey(); ECKey verificationKey = ECKey.fromPublicOnly(signingKey.getPubKeyPoint()); ECKey.ECDSASignature sig = signingKey.sign(hash); boolean isVerified = verificationKey.verify(hash, sig); assertTrue("msg " + msg + " can not be signed with " + Arrays.toString(sig.encodeToDER()), isVerified); }
@Test public void sendRequestP2PKTest() { ECKey key = new ECKey(); SendRequest req = SendRequest.to(PARAMS, key, SATOSHI.multiply(12)); assertArrayEquals(key.getPubKey(), req.tx.getOutputs().get(0).getScriptPubKey().getPubKey()); }
/** Create a fake transaction, without change. */ public static Transaction createFakeTxWithoutChange(final NetworkParameters params, final TransactionOutput output) { Transaction prevTx = FakeTxBuilder.createFakeTx(params, Coin.COIN, new ECKey().toAddress(params)); Transaction tx = new Transaction(params); tx.addOutput(output); tx.addInput(prevTx.getOutput(0)); return tx; }
@Test public void watchingScripts() throws Exception { // Verify that pending transactions to watched addresses are relevant Address watchedAddress = new ECKey().toAddress(PARAMS); wallet.addWatchedAddress(watchedAddress); Coin value = valueOf(5, 0); Transaction t1 = createFakeTx(PARAMS, value, watchedAddress); assertTrue(t1.getWalletOutputs(wallet).size() >= 1); assertTrue(wallet.isPendingTransactionRelevant(t1)); }
@Test public void roundTripDumpedPrivKey() throws Exception { ECKey key = new ECKey(); assertTrue(key.isCompressed()); NetworkParameters params = UnitTestParams.get(); String base58 = key.getPrivateKeyEncoded(params).toString(); ECKey key2 = DumpedPrivateKey.fromBase58(params, base58).getKey(); assertTrue(key2.isCompressed()); assertTrue(Arrays.equals(key.getPrivKeyBytes(), key2.getPrivKeyBytes())); assertTrue(Arrays.equals(key.getPubKey(), key2.getPubKey())); }
@Test public void removeKey() { ECKey key = new ECKey(); chain.importKeys(key); assertEquals(1, chain.numKeys()); assertTrue(chain.removeKey(key)); assertEquals(0, chain.numKeys()); assertFalse(chain.removeKey(key)); }
@Test public void testKeys() throws Exception { for (int i = 0 ; i < 20 ; i++) { myKey = new ECKey(); myAddress = myKey.toAddress(PARAMS); myWallet = new Wallet(PARAMS); myWallet.importKey(myKey); Wallet wallet1 = roundTrip(myWallet); assertArrayEquals(myKey.getPubKey(), wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPubKey()); assertArrayEquals(myKey.getPrivKeyBytes(), wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPrivKeyBytes()); } }