• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java HDKeyDerivation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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()));
    }
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:18,代码来源:BIP32Test.java


示例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);
}
 
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:17,代码来源:WalletUtil.java


示例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));
    }
}
 
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:25,代码来源:HDChain.java


示例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());
}
 
开发者ID:ksedgwic,项目名称:BTCReceive,代码行数:32,代码来源:HDAddress.java


示例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];
}
 
开发者ID:Yubico,项目名称:yubico-bitcoin-java,代码行数:8,代码来源:YkneoBitcoinSoft.java


示例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;
}
 
开发者ID:Yubico,项目名称:yubico-bitcoin-java,代码行数:12,代码来源:YkneoBitcoinSoft.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CacheDirective类代码示例发布时间:2022-05-22
下一篇:
Java AbstractRemoveStepHandler类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap