本文整理汇总了Java中org.bitcoinj.core.ECKey.fromPublicOnly方法的典型用法代码示例。如果您正苦于以下问题:Java ECKey.fromPublicOnly方法的具体用法?Java ECKey.fromPublicOnly怎么用?Java ECKey.fromPublicOnly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bitcoinj.core.ECKey
的用法示例。
在下文中一共展示了ECKey.fromPublicOnly方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Address
import org.bitcoinj.core.ECKey; //导入方法依赖的package包/类
/**
* Constructor an HD address.
*
* @param NetworkParameters params
* @param DeterministicKey cKey deterministic key for this address
* @param int child index of this address in its chain
*
*/
public Address(NetworkParameters params, DeterministicKey cKey, int child) {
this.params = params;
childNum = child;
DeterministicKey dk = HDKeyDerivation.deriveChildKey(cKey, new ChildNumber(childNum, false));
// compressed WIF private key format
if(dk.hasPrivKey()) {
// byte[] prepended0Byte = ArrayUtils.addAll(new byte[1], dk.getPrivKeyBytes());
byte[] getPrivKeyBytes = dk.getPrivKeyBytes();
byte[] prepended0Byte = new byte[1 + getPrivKeyBytes.length];
prepended0Byte[0] = 0;
System.arraycopy(getPrivKeyBytes, 0, prepended0Byte, 1, getPrivKeyBytes.length);
ecKey = ECKey.fromPrivate(new BigInteger(prepended0Byte), true);
}
else {
ecKey = ECKey.fromPublicOnly(dk.getPubKey());
}
long now = Utils.now().getTime() / 1000; // use Unix time (in seconds)
ecKey.setCreationTimeSeconds(now);
pubKey = ecKey.getPubKey();
pubKeyHash = ecKey.getPubKeyHash();
strPath = dk.getPathAsString();
}
示例2: deserializeFromProtobuf
import org.bitcoinj.core.ECKey; //导入方法依赖的package包/类
private void deserializeFromProtobuf(List<Protos.Key> keys) throws UnreadableWalletException {
lock.lock();
try {
checkState(hashToKeys.isEmpty(), "Tried to deserialize into a non-empty chain");
for (Protos.Key key : keys) {
if (key.getType() != Protos.Key.Type.ORIGINAL && key.getType() != Protos.Key.Type.ENCRYPTED_SCRYPT_AES)
continue;
boolean encrypted = key.getType() == Protos.Key.Type.ENCRYPTED_SCRYPT_AES;
byte[] priv = key.hasSecretBytes() ? key.getSecretBytes().toByteArray() : null;
if (!key.hasPublicKey())
throw new UnreadableWalletException("Public key missing");
byte[] pub = key.getPublicKey().toByteArray();
ECKey ecKey;
if (encrypted) {
checkState(keyCrypter != null, "This wallet is encrypted but encrypt() was not called prior to deserialization");
if (!key.hasEncryptedData())
throw new UnreadableWalletException("Encrypted private key data missing");
Protos.EncryptedData proto = key.getEncryptedData();
EncryptedData e = new EncryptedData(proto.getInitialisationVector().toByteArray(),
proto.getEncryptedPrivateKey().toByteArray());
ecKey = ECKey.fromEncrypted(e, keyCrypter, pub);
} else {
if (priv != null)
ecKey = ECKey.fromPrivateAndPrecalculatedPublic(priv, pub);
else
ecKey = ECKey.fromPublicOnly(pub);
}
ecKey.setCreationTimeSeconds(key.getCreationTimestamp() / 1000);
importKeyLocked(ecKey);
}
} finally {
lock.unlock();
}
}
示例3: isSignatureCorrect
import org.bitcoinj.core.ECKey; //导入方法依赖的package包/类
private boolean isSignatureCorrect(ECDSASignature signature, byte[] challengeString) {
Sha256Hash hash = Sha256Hash.wrap(Sha256Hash.hash(challengeString));
ECKey verificationKey = ECKey.fromPublicOnly(partnerProof.getScriptPair().getPubKey());
return verificationKey.verify(hash, signature);
}