当前位置: 首页 > 工具软件 > BitcoinJ > 使用案例 >

确定性钱包的多账户层次结构(bitcoinj使用BIP44)

单于奕
2023-12-01

虚拟账户可以根据助记词生成钱包,最近我使用bitcoinj生成钱包,最开始使用的随机生成钱包,类似如下代码

<dependency>
       <groupId>org.bitcoinj</groupId>
       <artifactId>bitcoinj-core</artifactId>
       <version>0.14.7</version>
</dependency>
ECKey key = new ECKey();
logger.info("We created a new key:\n" + key);
// TEST 网络
NetworkParameters params  = TestNet3Params.get();
Address addressFromKey = key.toAddress(params);
logger.info("Public Address generated: " + addressFromKey);
String privateKey = key.getPrivateKeyEncoded(params).toString();
logger.info("Private key is: " + privateKey);
logger.info("Private Hex key is: " + key.getPrivateKeyAsHex());
Wallet wallet = new Wallet(TestNet3Params.get());
File walletFile = new File(result.get("addressFromKey")+".test.wallet");
wallet.importKey(key);
wallet.saveToFile(walletFile);

这样生成钱包没有规律性,使用时必须记住私钥,如果私钥丢失,账户中的钱将永远找不回来,为了方便大家使用,使用助记词的方式生成钱包安全性和通用性都更高

下面代码是通过BIP44规则生成账户(我使用的是bitcoinj这个框架)

String wordsList = "one misery space industry hen mistake typical prison plunge yellow disagree arm";
DeterministicSeed deterministicSeed = new DeterministicSeed(wordsList, null, "", 0L);
DeterministicKeyChain deterministicKeyChain = DeterministicKeyChain.builder().seed(deterministicSeed).build();
BigInteger privKey = deterministicKeyChain.getKeyByPath(HDUtils.parsePath("44H / 1H / 0H / 0 / 2"), true).getPrivKey();
ECKey ecKey = ECKey.fromPrivate(privKey);
Address address = ecKey.toAddress(params);
System.out.println(address.toBase58());
#引入的包
import org.bitcoinj.core.Address;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.crypto.HDUtils;
import org.bitcoinj.params.TestNet3Params;
import org.bitcoinj.wallet.DeterministicKeyChain;
import org.bitcoinj.wallet.DeterministicSeed;
import org.bitcoinj.wallet.UnreadableWalletException;

生成规则如下

m / purpose' / coin_type' / account' / change / address_index

例如

coinaccountchainaddresspath
Bitcoinfirstexternalfirstm / 44' / 0' / 0' / 0 / 0
Bitcoinfirstexternalsecondm / 44' / 0' / 0' / 0 / 1
Bitcoinfirstchangefirstm / 44' / 0' / 0' / 1 / 0
Bitcoinfirstchangesecondm / 44' / 0' / 0' / 1 / 1
Bitcoinsecondexternalfirstm / 44' / 0' / 1' / 0 / 0
Bitcoinsecondexternalsecondm / 44' / 0' / 1' / 0 / 1
Bitcoinsecondchangefirstm / 44' / 0' / 1' / 1 / 0
Bitcoinsecondchangesecondm / 44' / 0' / 1' / 1 / 1
Bitcoin Testnetfirstexternalfirstm / 44' / 1' / 0' / 0 / 0
Bitcoin Testnetfirstexternalsecondm / 44' / 1' / 0' / 0 / 1
Bitcoin Testnetfirstchangefirstm / 44' / 1' / 0' / 1 / 0
Bitcoin Testnetfirstchangesecondm / 44' / 1' / 0' / 1 / 1
Bitcoin Testnetsecondexternalfirstm / 44' / 1' / 1' / 0 / 0
Bitcoin Testnetsecondexternalsecondm / 44' / 1' / 1' / 0 / 1
Bitcoin Testnetsecondchangefirstm / 44' / 1' / 1' / 1 / 0
Bitcoin Testnetsecondchangesecondm / 44' / 1' / 1' / 1 / 1

 

不同币类型

indexhexasymbolcoin
00x80000000BTCBitcoin
10x80000001 Testnet (all coins)
20x80000002LTCLitecoin
30x80000003DOGEDogecoin
40x80000004RDDReddcoin
50x80000005DSHDash (ex Darkcoin)
60x80000006PPCPeercoin
70x80000007NMCNamecoin
80x80000008FTCFeathercoin
90x80000009XCPCounterparty
100x8000000aBLKBlackcoin
110x8000000bNSRNuShares
120x8000000cNBTNuBits
130x8000000dMZCMazacoin
140x8000000eVIAViacoin
150x8000000fXCHClearingHouse
160x80000010RBYRubycoin
170x80000011GRSGroestlcoin
180x80000012DGCDigitalcoin
190x80000013CCNCannacoin
200x80000014DGBDigiByte
210x80000015 Open Assets
220x80000016MONAMonacoin
230x80000017CLAMClams
240x80000018XPMPrimecoin
250x80000019NEOSNeoscoin
260x8000001aJBSJumbucks
270x8000001bZRCziftrCOIN
280x8000001cVTCVertcoin
290x8000001dNXTNXT
300x8000001eBURSTBurst
310x8000001fMUEMonetaryUnit
320x80000020ZOOMZoom
330x80000021VASHVirtual Cash Also known as VPNcoin
340x80000022CDNCanada eCoin
350x80000023SDCShadowCash
360x80000024PKBParkByte
370x80000025PNDPandacoin
380x80000026STARTStartCOIN
390x80000027MOINMOIN
400x80000028EXPExpanse
410x80000029EMC2Einsteinium
420x8000002aDCRDecred
430x8000002bXEMNEM
440x8000002cPARTParticl
450x8000002dARGArgentum
460x8000002e Libertas
470x8000002f Posw coin
480x80000030SHRShreeji
490x80000031GCRGlobal Currency Reserve (GCRcoin)
500x80000032NVCNovacoin
510x80000033ACAsiacoin
520x80000034BTCDBitcoindark
530x80000035DOPEDopecoin
540x80000036TPCTemplecoin
550x80000037AIBAIB
560x80000038EDRCEDRCoin
570x80000039SYSSyscoin
580x8000003aSLRSolarcoin
590x8000003bSMLYSmileycoin
600x8000003cETHEther
610x8000003dETCEther Classic
620x8000003ePSBPesobit
630x8000003fLDCNLandcoin
640x80000040 Open Chain
650x80000041XBCBitcoinplus
660x80000042IOPInternet of People
670x80000043NXSNexus
680x80000044INSNInsaneCoin
690x80000045OKOKCash
700x80000046BRITBritCoin
710x80000047CMPCompcoin
720x80000048CRWCrown
730x80000049BELABelaCoin
740x8000004a  
750x8000004bFJCFujiCoin
760x8000004cMIXMIX
770x8000004dXVGVerge
780x8000004eEFLElectronic Gulden
790x8000004fCLUBClubCoin
800x80000050RICHXRichCoin
810x80000051POTPotcoin
820x80000052QRKQuarkcoin
830x80000053TRCTerracoin
840x80000054GRCGridcoin
850x80000055AURAuroracoin
860x80000056IXCIXCoin
870x80000057NLGGulden
880x80000058BITBBitBean
890x80000059BTABata
900x8000005aXMYMyriadcoin
910x8000005bBSDBitSend
920x8000005cUNOUnobtanium
930x8000005dMTRMasterTrader
940x8000005eGBGoldBlocks
950x8000005fSHMSaham
960x80000060CRXChronos
970x80000061BIQUbiquoin
980x80000062EVOEvotion
990x80000063STOSaveTheOcean
1000x80000064BIGUPBigUp
1010x80000065GAMEGameCredits
1020x80000066DLCDollarcoins
1030x80000067ZYDZayedcoin
1040x80000068DBICDubaicoin
1050x80000069STRATStratis
1060x8000006aSHShilling
1070x8000006bMARSMarsCoin
1080x8000006cUBQUbiq
1090x8000006dPTCPesetacoin
1100x8000006eNRONeurocoin
1110x8000006fARKARK
1120x80000070USCUltimateSecureCashMain
1130x80000071THCHempcoin
1140x80000072LINXLinx
1150x80000073ECNEcoin
1160x80000074DNRDenarius
1170x80000075PINKPinkcoin
1180x80000076PIGGYPiggyCoin
1190x80000077PIVXPivx
1200x80000078FLASHFlashcoin
1210x80000079ZENZencash
1220x8000007aPUTPutincoin
1230x8000007bZNYBitZeny
1240x8000007cUNIFYUnify
1250x8000007dXSTStealthCoin
1260x8000007eBRKBreakout Coin
1270x8000007fVCVcash
1280x80000080XMRMonero
1290x80000081VOXVoxels
1300x80000082NAVNavCoin
1310x80000083FCTFactom Factoids
1320x80000084ECFactom Entry Credits
1330x80000085ZECZcash
1340x80000086LSKLisk
1350x80000087STEEMSteem
1360x80000088XZCZCoin
1370x80000089SBTCRSK
1380x8000008a Giftblock
1390x8000008bRPTRealPointCoin
1400x8000008cLBCLBRY Credits
1410x8000008dKMDKomodo
1420x8000008eBSQbisq Token
1430x8000008fRICRiecoin
1440x80000090XRPRipple
1450x80000091BCHBitcoin Cash
1460x80000092NEBLNeblio
1470x80000093ZCLZClassic
1480x80000094XLMStellar Lumens
1490x80000095NLC2NoLimitCoin2
1500x80000096WHLWhaleCoin
1510x80000097ERCEuropeCoin
1520x80000098DMDDiamond
1530x80000099BTMBytom
1540x8000009aBIOBiocoin
1550x8000009bXWCWhitecoin
1560x8000009cBTGBitcoin Gold
1570x8000009dBTC2XBitcoin 2x
1580x8000009eSSNSuperSkynet
1590x8000009fTOATOACoin
1600x800000a0BTXBitcore
1610x800000a1ACCAdcoin
1620x800000a2BCOBridgecoin
1630x800000a3ELLAEllaism
1640x800000a4PIRLPirl
1650x800000a5XRBRaiBlocks
1660x800000a6VIVOVivo
1670x800000a7FRSTFirstcoin
1680x800000a8HNCHelleniccoin
1690x800000a9BUZZBUZZ
1700x800000aaMBRSEmber
1710x800000abHSRHcash
1720x800000acHTMLHTMLCOIN
1730x800000adODNObsidian
1740x800000aeONXOnixCoin
1750x800000afRVNRavencoin
1760x800000b0GBXGoByte
1770x800000b1BTCZBitcoinZ
1780x800000b2POAPoa
1790x800000b3NYCNewYorkCoin
1800x800000b4MXTMarteXcoin
1810x800000b5WCWincoin
1820x800000b6MNXMinexcoin
1830x800000b7BTCPBitcoin Private
1840x800000b8MUSICMusicoin
1850x800000b9BCABitcoin Atom
1860x800000baCRAVECrave
1870x800000bbSTAKSTRAKS
1880x800000bcWBTCWorld Bitcoin
1890x800000bdLCHLiteCash
1900x800000beEXCLExclusiveCoin
1910x800000bf Lynx
1920x800000c0LCCLitecoinCash
1930x800000c1XFEFeirm
1940x800000c2EOSEOS
1950x800000c3TRXTron
1960x800000c4KOBOKobocoin
1970x800000c5HUSHHUSH
1980x800000c6BANANOBananos
1990x800000c7ETFETF
2000x800000c8OMNIOmni
2010x800000c9BIFIBitcoinFile
2020x800000caUFOUniform Fiscal Object
2030x800000cbCNMCCryptonodes
2040x800000ccNRGEnergi
2050x800000cdRINRingo
2060x800000ceATPPlatON
2070x800000cfEVTeveriToken
2080x800000d0ATNATN
2090x800000d1BISBismuth
2100x800000d2NEETNEETCOIN
2110x800000d3BOPOBopoChain
2150x800000d7BOXYBoxyCoin
2160x800000d8FLOFlo
2220x800000deBITGBitcoin Green
2230x800000dfASKAskCoin
2240x800000e0SMARTSmartcash
2250x800000e1XUEZXUEZ
2260x800000e2HLMHelium
233  0x800000e9VAR  Varda
2420x800000f2NIMNimiq
2470x800000f7UCUlord
2530x800000fdNPWNewPowerCoin
2550x800000ff SmartHoldem
2560x80000100NANOBitcoin Nano
2570x80000101BTCCBitcoin Core
2580x80000102 Zen Protocol
2590x80000103ZESTZest
2700x8000010eONEONE
2710x8000010fSBCSBC
2990x8000012bNUKONekonium
3000x8000012cGNXGenaro Network
3120x80000138ARAAura
3210x80000141RAPRapture
3280x80000148BLOCKBlocknet
3330x8000014dMEMMemCoin
4250x800001a9AIONAion
4440x800001bcPHRPhore
5100x800001feKOTOKoto
5120x80000200XRDRadiant
5280x80000210YAPYapstone
5550x8000022bBCSBitcoin Smart
6250x80000271EASTEastcoin
6660x8000029aACTAchain
6680x8000029cSSCSelfSell
7770x80000309BTWBitcoin World
8000x80000320BEETBeetle Coin
8010x80000321DSTDSTRA
8080x80000328QVTQvolta
8180x80000332VETVeChain Token
8200x80000334CLOCallisto
8860x80000376ADFAD Token
8880x80000378NEONEO
8900x8000037aXSELSeln
9980x800003e6LBTCLightning Bitcoin
9990x800003e7BCDBitcoin Diamond
10000x800003e8BTNBitcoin New
10020x800003eaBKTBanKitt
10240x80000400ONTOntology
11110x80000457BBCBig Bitcoin
11220x80000462CMTCyberMiles Token
11280x80000468ETSCEthereum Social
11450x80000479CDYBitcoin Candy
13370x80000539DFCDefcoin
13970x80000575HYCHycon
15240x800005f4 Taler
16200x80000654ATHAtheios
16880x80000698BCXBitcoinX
17290x800006c1XTZTezos
18150x80000717ADACardano
18560x80000743TESTeslacoin
19010x8000076dCLCClassica
19190x8000077fVIPSVIPSTARCOIN
19770x800007b9XMXXuma
19870x800007c3EGEMEtherGem
19890x800007c5HODLHOdlcoin
19970x800007cdPOLIS  Polis
20180x800007e2EOSCEOSClassic
23010x800008fdQTUMQTUM
23020x800008feETPMetaverse
23030x800008ffGXCGXChain
23040x80000900SSCSelfSell
23050x80000901ELAElastos
35520x80000de0DEODestocoin
27180x80000a9eNASNebulas
33770x80000d31ROIROIcoin
42180x8000107aIOTAIOTA
42420x80001092AXEAxe
52480x00001480FICFIC
57570x8000167d Stacks
60600x800017acGOGoChain GO
66660x80001a0aBPABitcoin Pizza
66880x80001a20SAFESAFE
69690x80001b39ROGERTheHolyrogerCoin
77770x80001e61BTVBitvote
83390x80002093BTQ  BitcoinQuark
88880x800022b8SBTCSuper Bitcoin
89990x80002327BTPBitcoin Pay
98880x800026a0BTFBitcoin Faith
99990x8000270fGODBitcoin God
102910x80002833BTRBitcoin Rhodium
225040x800057e8PWRPWRcoin
311020x8000797eESNEtherSocial Network
313370x80007a69 ThePower.io
338780x80008456BTCSBitcoin Stake
373100x800091be RSK Testnet
655360x80010000KETHKrypton World
999990x8001869fWICCWaykichain
2006250x80030fb1AKAAkroma
4242420x800‭67932‬X42x42
13131140x8014095aETHOEther-1
17121440x801a2010LAXLAPO
52493530x80501949BCO  BitcoinOre
52493540x8050194aBHD  BitcoinHD
57183500x8057414eWAN  Wanchain
57415640x80579bfcWAVES  Waves
919270090x857ab1e1kUSD  kUSD

如上

 

欢迎大家加群:835870546

大家可以一起交流学习!

 类似资料: