Bip44确定性算法的android实现

简介

这是一个Bip44确定性算法的Android实现库,可以生成12个助记词,seed种子和根据path路径生成路径的私钥.

对Bip44确定算法不了解的可以看我之前的一篇文章:
区块链开发之确定性算法bip32,bip39,bip44

项目地址:https://github.com/wypeng2012/Bip44ForAndroid

欢迎star

support Android sdk >= 14

PS:- coin_type link

https://github.com/satoshilabs/slips/blob/master/slip-0044.md

- 如何使用

代码如下:


                    //get 12 words
                    List<String> words = Bip44Utils.generateMnemonicWords(MainActivity.this);
                    Log.e("TAG", "words: " + words.toString());

                    // get bip39 seed
                    byte[] seed = Bip44Utils.getSeed(words);
                    Log.e("TAG", "seed: " + new BigInteger(1,seed).toString(16));

                    //get PrivateKey by path
                    BigInteger pri1 = Bip44Utils.getPathPrivateKey(words,"m/44'/194'/0'/0/0");
                    Log.e("TAG", "pri1: " + pri1.toString(16));

                    BigInteger pri2 = Bip44Utils.getPathPrivateKey(words,seed,"m/44'/194'/0'/0/0");
                    Log.e("TAG", "pri2: " + pri2.toString(16));

                    byte[] pri3 = Bip44Utils.getPathPrivateKeyBytes(words, "m/44'/194'/0'/0/0");
                    Log.e("TAG", "pri3: " + new BigInteger(1,pri3).toString(16));

                    byte[] pri4 = Bip44Utils.getPathPrivateKeyBytes(words, seed,"m/44'/194'/0'/0/0");
                    Log.e("TAG", "pri4: " + new BigInteger(1,pri4).toString(16));

                    byte[] pri5 = Bip44Utils.getDefaultPathPrivateKeyBytes(words, 194);
                    Log.e("TAG", "pri5: " + new BigInteger(1,pri5).toString(16));

                    //if you use bitcoinj library,you can generate bitcoin privatekey and public key and address like this:

                    BigInteger pribtc = Bip44Utils.getPathPrivateKey(words,"m/44'/0'/0'/0/0");

                    ECKey ecKey = ECKey.fromPrivate(pribtc);

	                String publicKey = ecKey.getPublicKeyAsHex();
	                String privateKey = ecKey.getPrivateKeyEncoded(networkParameters).toString();
	                String address = ecKey.toAddress(networkParameters).toString();


                    //if you use web3j library,you can generate bitcoin privatekey and public key and address like this:
                    
				  BigInteger prieth = Bip44Utils.getPathPrivateKey(words,"m/44'/60'/0'/0/0");

                   ECKeyPair ecKeyPair = ECKeyPair.create(prieth);

	               String publicKey = Numeric.toHexStringWithPrefix(ecKeyPair.getPublicKey());
	               String privateKey = Numeric.toHexStringWithPrefix(ecKeyPair.getPrivateKey());
	               String address = "0x" + Keys.getAddress(ecKeyPair);
                    


打印结果:


words: [course, question, calm, west, basket, kitten, salmon, absorb, tool, ankle, mixed, endorse]

seed: c03f5488370482658066b96a803fcceac46b68181024a545d814344cbf7d9da9b478a20d0b95ebef268b7c24afd4540c59a4567146d45d2db891ca2576d409c7

pri1: 6ef7a396546d4fcf26865e54033ad48db858d19b5a08782014a652f4b5469037

pri2: 6ef7a396546d4fcf26865e54033ad48db858d19b5a08782014a652f4b5469037

pri3: 6ef7a396546d4fcf26865e54033ad48db858d19b5a08782014a652f4b5469037

pri4: 6ef7a396546d4fcf26865e54033ad48db858d19b5a08782014a652f4b5469037

pri5: 6ef7a396546d4fcf26865e54033ad48db858d19b5a08782014a652f4b5469037


- 如何远程依赖

  1. Maven
<dependency>
  <groupId>party.loveit</groupId>
  <artifactId>bip44forandroidlibrary</artifactId>
  <version>1.0.7</version>
  <type>pom</type>
</dependency>
  1. Gradle
compile 'party.loveit:bip44forandroidlibrary:1.0.7'

or

implementation 'party.loveit:bip44forandroidlibrary:1.0.7'

  1. Ivy
<dependency org='party.loveit' name='bip44forandroidlibrary' rev='1.0.7'>
  <artifact name='bip44forandroidlibrary' ext='pom' ></artifact>
</dependency>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值