本文整理汇总了Java中com.google.bitcoin.crypto.HDKeyDerivation类的典型用法代码示例。如果您正苦于以下问题:Java HDKeyDerivation类的具体用法?Java HDKeyDerivation怎么用?Java HDKeyDerivation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HDKeyDerivation类属于com.google.bitcoin.crypto包,在下文中一共展示了HDKeyDerivation类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testVector
import com.google.bitcoin.crypto.HDKeyDerivation; //导入依赖的package包/类
private void testVector(int testCase) throws AddressFormatException {
log.info("======= Test vector {}", testCase);
HDWTestVector tv = tvs[testCase];
DeterministicKey masterPrivateKey = HDKeyDerivation.createMasterPrivateKey(Hex.decode(tv.seed));
Assert.assertEquals(testEncode(tv.priv), testEncode(masterPrivateKey.serializePrivB58()));
Assert.assertEquals(testEncode(tv.pub), testEncode(masterPrivateKey.serializePubB58()));
DeterministicHierarchy dh = new DeterministicHierarchy(masterPrivateKey);
for (int i = 0; i < tv.derived.size(); i++) {
HDWTestVector.DerivedTestCase tc = tv.derived.get(i);
log.info("{}", tc.name);
Assert.assertEquals(tc.name, String.format("Test%d %s", testCase + 1, tc.getPathDescription()));
int depth = tc.path.length - 1;
DeterministicKey ehkey = dh.deriveChild(Arrays.asList(tc.path).subList(0, depth), false, true, tc.path[depth]);
Assert.assertEquals(testEncode(tc.priv), testEncode(ehkey.serializePrivB58()));
Assert.assertEquals(testEncode(tc.pub), testEncode(ehkey.serializePubB58()));
}
}
示例2: createMasterPubKeyFromPubB58
import com.google.bitcoin.crypto.HDKeyDerivation; //导入依赖的package包/类
public static DeterministicKey createMasterPubKeyFromPubB58(String xpubstr)
throws AddressFormatException
{
byte[] data = Base58.decodeChecked(xpubstr);
ByteBuffer ser = ByteBuffer.wrap(data);
if (ser.getInt() != 0x0488B21E)
throw new AddressFormatException("bad xpub version");
ser.get(); // depth
ser.getInt(); // parent fingerprint
ser.getInt(); // child number
byte[] chainCode = new byte[32];
ser.get(chainCode);
byte[] pubBytes = new byte[33];
ser.get(pubBytes);
return HDKeyDerivation.createMasterPubKeyFromBytes(pubBytes, chainCode);
}
示例3: HDChain
import com.google.bitcoin.crypto.HDKeyDerivation; //导入依赖的package包/类
public HDChain(NetworkParameters params,
DeterministicKey accountKey,
JSONObject chainNode)
throws RuntimeException, JSONException {
mParams = params;
mChainName = chainNode.getString("name");
mIsReceive = chainNode.getBoolean("isReceive");
int chainnum = mIsReceive ? 0 : 1;
mChainKey = HDKeyDerivation.deriveChildKey(accountKey, chainnum);
mLogger.info("deserialized HDChain " + mChainName + ": " +
mChainKey.getPath());
mAddrs = new ArrayList<HDAddress>();
JSONArray addrobjs = chainNode.getJSONArray("addrs");
for (int ii = 0; ii < addrobjs.length(); ++ii) {
JSONObject addrNode = addrobjs.getJSONObject(ii);
mAddrs.add(new HDAddress(mParams, mChainKey, addrNode));
}
}
示例4: HDAddress
import com.google.bitcoin.crypto.HDKeyDerivation; //导入依赖的package包/类
public HDAddress(NetworkParameters params,
DeterministicKey chainKey,
int addrnum) {
mParams = params;
mAddrNum = addrnum;
DeterministicKey addrKey =
HDKeyDerivation.deriveChildKey(chainKey, addrnum);
mPath = addrKey.getPath();
// Derive ECKey.
byte[] prvBytes = addrKey.getPrivKeyBytes();
mPubBytes = addrKey.getPubKeyBytes(); // Expensive, save.
mECKey = new ECKey(prvBytes, mPubBytes);
// Set creation time to now.
mECKey.setCreationTimeSeconds(EPOCH);
// Derive path, public key, public hash and address.
mPubKey = mECKey.getPubKey();
mPubKeyHash = mECKey.getPubKeyHash();
mAddress = mECKey.toAddress(mParams);
// Initialize transaction count and balance.
mNumTrans = 0;
mBalance = 0;
mAvailable = 0;
mLogger.info("created address " + mPath + ": " + mAddress.toString());
}
示例5: generateMasterKeyPair
import com.google.bitcoin.crypto.HDKeyDerivation; //导入依赖的package包/类
@Override
public byte[] generateMasterKeyPair(boolean allowExport, boolean returnPrivateKey, boolean testnetKey) throws PinModeLockedException, IOException {
ensurePin(PinMode.ADMIN);
master = new DeterministicHierarchy(HDKeyDerivation.createMasterPrivateKey(random.generateSeed(32)));
this.allowExport = allowExport;
return returnPrivateKey ? master.getRootKey().serializePrivate() : new byte[0];
}
示例6: importExtendedKeyPair
import com.google.bitcoin.crypto.HDKeyDerivation; //导入依赖的package包/类
@Override
public void importExtendedKeyPair(byte[] extendedPrivateKey, boolean allowExport) throws PinModeLockedException, IOException {
ensurePin(PinMode.ADMIN);
byte[] privkey = new byte[33];
byte[] chaincode = new byte[32];
System.arraycopy(extendedPrivateKey, 13, chaincode, 0, 32);
System.arraycopy(extendedPrivateKey, 45, privkey, 0, 33);
master = new DeterministicHierarchy(HDKeyDerivation.createMasterPrivKeyFromBytes(privkey, chaincode));
this.allowExport = allowExport;
}