当前位置: 首页>>代码示例>>Java>>正文


Java ECKey类代码示例

本文整理汇总了Java中com.google.bitcoin.core.ECKey的典型用法代码示例。如果您正苦于以下问题:Java ECKey类的具体用法?Java ECKey怎么用?Java ECKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ECKey类属于com.google.bitcoin.core包,在下文中一共展示了ECKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildRawTx

import com.google.bitcoin.core.ECKey; //导入依赖的package包/类
private static String buildRawTx() {
	ScriptBuilder builder = new ScriptBuilder();
	builder.op(OP_DEPTH).op(OP_1).op(OP_NUMEQUAL).op(OP_IF)
			.data("name of nakakamoto".getBytes()).op(OP_DROP)
			.op(OP_RIPEMD160).op(OP_RIPEMD160)
			.data(doublehash160("satoshi".getBytes())).op(OP_EQUAL)
			.op(OP_ELSE).op(OP_DUP).op(OP_HASH160)
			.data(doublehash160("Haha".getBytes())).op(OP_EQUALVERIFY)
			.op(OP_CHECKSIG).op(OP_ENDIF);

	Script outputScript = builder.build();
	Transaction tx1 = new Transaction(MainNetParams.get());
	tx1.addInput(new TransactionInput(MainNetParams.get(), tx1,
			new byte[] {}));
	ECKey key = new ECKey();
	tx1.addOutput(Bitcoins.toSatoshiEndBully(), key);
	Transaction tx2 = new Transaction(MainNetParams.get());

	tx2.addInput(tx1.getOutput(0));
	tx2.addOutput(Bitcoins.toSatoshiEndBully(), outputScript);
	tx2.addOutput(Bitcoins.toSatoshiEndBully(), key);
	System.out.println(tx2);
	String rawTx = BaseEncoding.base16().encode(
			tx2.unsafeBitcoinSerialize());
	return rawTx;
}
 
开发者ID:y12studio,项目名称:bkbc-tools,代码行数:27,代码来源:HintScriptBuilder.java

示例2: decodeFromBitcoin

import com.google.bitcoin.core.ECKey; //导入依赖的package包/类
/**
 * Returns a decoded signature.
 * @throws RuntimeException if the signature is invalid or unparseable in some way.
 */
public static TransactionSignature decodeFromBitcoin(byte[] bytes, boolean requireCanonical) throws VerificationException {
    // Bitcoin encoding is DER signature + sighash byte.
    if (requireCanonical && !isEncodingCanonical(bytes))
        throw new VerificationException("Signature encoding is not canonical.");
    ECKey.ECDSASignature sig;
    try {
        sig = ECKey.ECDSASignature.decodeFromDER(bytes);
    } catch (IllegalArgumentException e) {
        throw new VerificationException("Could not decode DER", e);
    }
    TransactionSignature tsig = new TransactionSignature(sig.r, sig.s);
    // In Bitcoin, any value of the final byte is valid, but not necessarily canonical. See javadocs for
    // isEncodingCanonical to learn more about this.
    tsig.sighashFlags = bytes[bytes.length - 1];
    return tsig;
}
 
开发者ID:HashEngineering,项目名称:myriadcoinj,代码行数:21,代码来源:TransactionSignature.java

示例3: signInput

import com.google.bitcoin.core.ECKey; //导入依赖的package包/类
private static byte[] signInput(NetworkParameters params, Transaction tx, int tx_input_index, String base58PrivKey, BitcoinScript script, SigHash sigHash) {
   	Log.d("SharedCoin", "SharedCoin signInput tx.getInputs().size " + tx.getInputs().size());	
   	Log.d("SharedCoin", "SharedCoin signInput tx_input_index " + tx_input_index);	
   	Log.d("SharedCoin", "SharedCoin signInput base58PrivKey " + base58PrivKey);	
       	
	try {
		ECKey key = new ECKey(Base58.decode(base58PrivKey), null);
    	Log.d("SharedCoin", "SharedCoin signInput key.toAddress " + key.toAddress(params).toString());	
		
		TransactionSignature transactionSignature = tx.calculateSignature(tx_input_index, key, null, script.getProgram(), SigHash.ALL, false);
		
		byte[] signedScript = Script.createInputScript(transactionSignature.encodeToBitcoin(), key.getPubKey());
		//ArrayUtils.reverse(signedScript);

		String signedScriptHex = new String(Hex.encode(signedScript));
    	Log.d("SharedCoin", "SharedCoin signInput signedScriptHex " + signedScriptHex);		
    	Log.d("SharedCoin", "SharedCoin signInput script.program hex " + new String(Hex.encode(script.getProgram())));		

		return signedScript;
	} catch (Exception e) {
    	Log.d("SharedCoin", "SharedCoin signInput e " + e.getLocalizedMessage());		
		e.printStackTrace();
	}
	
	return null;
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:27,代码来源:SharedCoin.java

示例4: keyChainContainsPrivateKey

import com.google.bitcoin.core.ECKey; //导入依赖的package包/类
/**
 * Determine whether the key is already in the wallet.
 * @throws KeyCrypterException
 */
private boolean keyChainContainsPrivateKey(Collection<byte[]> unencryptedPrivateKeys, ECKey keyToAdd, CharSequence walletPassword) throws KeyCrypterException {
    if (unencryptedPrivateKeys == null || keyToAdd == null) {
        return false;
    } else {
        byte[] unencryptedKeyToAdd = new byte[0];
        if (keyToAdd.isEncrypted()) {
            unencryptedKeyToAdd = keyToAdd.getKeyCrypter().decrypt(keyToAdd.getEncryptedPrivateKey(), keyToAdd.getKeyCrypter().deriveKey(walletPassword));
        }
        for (byte[] loopEncryptedPrivateKey : unencryptedPrivateKeys) { 
            if (Arrays.equals(unencryptedKeyToAdd, loopEncryptedPrivateKey)) {
                return true;
            }
        }
        return false;
    }
}
 
开发者ID:coinspark,项目名称:sparkbit,代码行数:21,代码来源:ImportPrivateKeysSubmitAction.java

示例5: buildRawTx

import com.google.bitcoin.core.ECKey; //导入依赖的package包/类
private static String buildRawTx() {
	ProtoBlue puf = ProtoBlue.newBuilder().setBkbcValue(200855)
			.setProtoType(Type.TEST).setExchangeType(ExType.BTC_TWD)
			.setVersion(VerType.TEST1).build();
	System.out.println(puf);

	ScriptBuilder builder = new ScriptBuilder();
	builder.op(OP_RETURN).data(puf.toByteArray());

	Script outputScript = builder.build();
	Transaction tx1 = new Transaction(MainNetParams.get());
	tx1.addInput(new TransactionInput(MainNetParams.get(), tx1,
			new byte[] {}));
	ECKey key = new ECKey();
	tx1.addOutput(Bitcoins.toSatoshiEndBully(), key);
	Transaction tx2 = new Transaction(MainNetParams.get());

	tx2.addInput(tx1.getOutput(0));
	tx2.addOutput(Bitcoins.toSatoshiEndBully(), key);
	tx2.addOutput(Bitcoins.toSatoshiEndBully(), outputScript);
	System.out.println(tx2);
	String rawTx = BaseEncoding.base16().encode(
			tx2.unsafeBitcoinSerialize());
	return rawTx;
}
 
开发者ID:y12studio,项目名称:bkbc-tools,代码行数:26,代码来源:ScriptOpReturnBuilder.java

示例6: HDReceiver

import com.google.bitcoin.core.ECKey; //导入依赖的package包/类
public HDReceiver(Context ctxt,
                  NetworkParameters params,
                  File dir,
                  String prefix,
                  DeterministicKey accountRootKey) {

    mParams = params;
    mDirectory = dir;
    mFilePrefix = prefix;

    // WORKAROUND - there is a bug that watch-only addresses
    // don't seem to properly scan historically; they use
    // quick catchup.  Create a real key (that we ignore) as a
    // workaround.
    //
    mWorkaroundKey = new ECKey();
    mWorkaroundKey.setCreationTimeSeconds(HDAddress.EPOCH);

    mAccountKey = accountRootKey;
    mAccount = new HDAccount(params, mAccountKey, "Account 0");
    mLogger.info("created HDReceiver");
}
 
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:23,代码来源:HDReceiver.java

示例7: determineRequestStr

import com.google.bitcoin.core.ECKey; //导入依赖的package包/类
private String determineRequestStr(final boolean includeBluetoothMac)
{
	final boolean includeLabel = includeLabelView.isChecked();

	final ECKey key = (ECKey) addressView.getSelectedItem();
	final Address address = key.toAddress(Constants.NETWORK_PARAMETERS);
	final String label = includeLabel ? AddressBookProvider.resolveLabel(activity, address.toString()) : null;
	final BigInteger amount = amountCalculatorLink.getAmount();

	final StringBuilder uri = new StringBuilder(BitcoinURI.convertToBitcoinURI(address, amount, label, null));
	if (includeBluetoothMac && bluetoothMac != null)
	{
		uri.append(amount == null && label == null ? '?' : '&');
		uri.append(Bluetooth.MAC_URI_PARAM).append('=').append(bluetoothMac);
	}
	return uri.toString();
}
 
开发者ID:9cat,项目名称:templecoin-android-wallet,代码行数:18,代码来源:RequestCoinsFragment.java

示例8: writeKeys

import com.google.bitcoin.core.ECKey; //导入依赖的package包/类
public static void writeKeys(@Nonnull final Writer out, @Nonnull final List<ECKey> keys) throws IOException
{
	final DateFormat format = Iso8601Format.newDateTimeFormatT();

	out.write("# KEEP YOUR PRIVATE KEYS SAFE! Anyone who can read this can spend your "+ CoinDefinition.coinName+"s.\n");

	for (final ECKey key : keys)
	{
		out.write(key.getPrivateKeyEncoded(Constants.NETWORK_PARAMETERS).toString());
		if (key.getCreationTimeSeconds() != 0)
		{
			out.write(' ');
			out.write(format.format(new Date(key.getCreationTimeSeconds() * DateUtils.SECOND_IN_MILLIS)));
		}
		out.write('\n');
	}
}
 
开发者ID:9cat,项目名称:templecoin-android-wallet,代码行数:18,代码来源:WalletUtils.java

示例9: deriveChildKey

import com.google.bitcoin.core.ECKey; //导入依赖的package包/类
/**
 * @throws HDDerivationException if private derivation is attempted for a public-only parent key, or
 * if the resulting derived key is invalid (eg. private key == 0).
 */
public static DeterministicKey deriveChildKey(DeterministicKey parent, ChildNumber childNumber)
        throws HDDerivationException {

    RawKeyBytes rawKey = deriveChildKeyBytes(parent, childNumber);
    return new DeterministicKey(
            HDUtils.append(parent.getChildNumberPath(), childNumber),
            rawKey.chainCode,
            parent.hasPrivate() ? null : ECKey.CURVE.getCurve().decodePoint(rawKey.keyBytes),
            parent.hasPrivate() ? new BigInteger(1, rawKey.keyBytes) : null,
            parent);
}
 
开发者ID:HashEngineering,项目名称:quarkcoinj,代码行数:16,代码来源:HDKeyDerivation.java

示例10: basics

import com.google.bitcoin.core.ECKey; //导入依赖的package包/类
@Test
public void basics() throws Exception {
    NetworkParameters params = UnitTestParams.get();
    File f = File.createTempFile("spvblockstore", null);
    f.delete();
    f.deleteOnExit();
    SPVBlockStore store = new SPVBlockStore(params, f);

    Address to = new ECKey().toAddress(params);
    // Check the first block in a new store is the genesis block.
    StoredBlock genesis = store.getChainHead();
    assertEquals(params.getGenesisBlock(), genesis.getHeader());
    assertEquals(0, genesis.getHeight());


    // Build a new block.
    StoredBlock b1 = genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader(), store);
    store.put(b1);
    store.setChainHead(b1);
    store.close();

    // Check we can get it back out again if we rebuild the store object.
    store = new SPVBlockStore(params, f);
    StoredBlock b2 = store.get(b1.getHeader().getHash());
    assertEquals(b1, b2);
    // Check the chain head was stored correctly also.
    StoredBlock chainHead = store.getChainHead();
    assertEquals(b1, chainHead);
}
 
开发者ID:HashEngineering,项目名称:myriadcoinj,代码行数:30,代码来源:SPVBlockStoreTest.java

示例11: addReceivingAddress

import com.google.bitcoin.core.ECKey; //导入依赖的package包/类
/**
 * Add a receiving address in the form of an WalletAddressBookData,
 * replacing the label of any existing address.
 * 
 * @param receivingAddress
 * @param checkAlreadyPresent
 */
public void addReceivingAddress(WalletAddressBookData receivingAddress, boolean checkAlreadyPresent) {
    if (receivingAddress == null || receivingAddress.getAddress() == null) {
        return;
    }

    boolean justUpdateLabel = false;

    if (checkAlreadyPresent) {
        // Check the address is not already in the set.
        for (WalletAddressBookData addressBookData : receivingAddresses) {
            if (addressBookData.getAddress().equals(receivingAddress.getAddress())) {
                // Just update label.
                addressBookData.setLabel(receivingAddress.getLabel());
                justUpdateLabel = true;
                break;
            }
        }
    }

    boolean addressMatchesKey = false;
    if (wallet != null) {
        for (ECKey key : wallet.getKeys()) {
            if (receivingAddress.getAddress().equals(
                    key.toAddress(SparkBit.getBitcoinController().getModel().getNetworkParameters()).toString())) {
                addressMatchesKey = true;
                break;
            }
        }
    }

    if (!justUpdateLabel && (wallet == null || addressMatchesKey)) {
        receivingAddresses.add(receivingAddress);
    }
}
 
开发者ID:coinspark,项目名称:sparkbit,代码行数:42,代码来源:WalletInfoData.java

示例12: getPubPoint

import com.google.bitcoin.core.ECKey; //导入依赖的package包/类
ECPoint getPubPoint() {
    if (publicAsPoint == null) {
        checkNotNull(privateAsFieldElement);
        publicAsPoint = ECKey.CURVE.getG().multiply(privateAsFieldElement).normalize();
    }
    return publicAsPoint;
}
 
开发者ID:HashEngineering,项目名称:quarkcoinj,代码行数:8,代码来源:DeterministicKey.java

示例13: addKey

import com.google.bitcoin.core.ECKey; //导入依赖的package包/类
@Override
public synchronized boolean addKey(ECKey key, String address, String label, String device_name, String device_version) throws Exception {
	boolean success = super.addKey(key, address, label, device_name, device_version);

	EventListeners.invokeWalletDidChange();

	return success;
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:9,代码来源:MyRemoteWallet.java

示例14: filter

import com.google.bitcoin.core.ECKey; //导入依赖的package包/类
private List<MyTransactionOutPoint> filter(List<MyTransactionOutPoint> unspent, List<ECKey> tempKeys, boolean askForPrivateKeys, final SendProgress progress) throws Exception {		
	List<MyTransactionOutPoint> filtered = new ArrayList<MyTransactionOutPoint>();

	Set<String> alreadyAskedFor = new HashSet<String>();

	for (MyTransactionOutPoint output : unspent) {
		BitcoinScript script = new BitcoinScript(output.getScriptBytes());

		String addr = script.getAddress().toString();

		Map<String, Object> keyMap = findKey(addr);

		if (keyMap.get("priv") == null) {
			if (askForPrivateKeys && alreadyAskedFor.add(addr)) {

				ECKey key = progress.onPrivateKeyMissing(addr);

				if (key != null) {
					filtered.add(output);

					tempKeys.add(key);
				}
			}
		} else {
			filtered.add(output);
		}
	}

	return filtered;
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:31,代码来源:MyRemoteWallet.java

示例15: generateECKey

import com.google.bitcoin.core.ECKey; //导入依赖的package包/类
public ECKey generateECKey() {
	SecureRandom random = new SecureRandom();

	if (extra_seed != null) {
		random.setSeed(extra_seed);
	}

	return new ECKey(random);
}
 
开发者ID:10xEngineer,项目名称:My-Wallet-Android,代码行数:10,代码来源:MyWallet.java


注:本文中的com.google.bitcoin.core.ECKey类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。