單鏈錢包通常被稱為主鏈錢包。這種錢包一般是針對(duì)渠道型公鏈開發(fā)的。比方IM Token版和MetaMask(許多朋友叫它小狐貍錢包)都是以太坊單鏈錢包,所以只支撐使用相同規(guī)范的ETH和ERC-20令牌。
多鏈錢包
多鏈錢包簡(jiǎn)單來(lái)說(shuō)便是能夠支撐多個(gè)主鏈渠道令牌的錢包。常見的多鏈錢包有Bitter、imToken2.0、Cobo錢包等。
?/**
?* entropy為上面通過(guò)SecureRandom生成的隨機(jī)數(shù)組
?**/
?public List toMnemonic(byte[] entropy) throws MnemonicException.MnemonicLengthException {
????//為了減少字?jǐn)?shù)刪來(lái)檢查參數(shù)的代碼
?????
????//計(jì)算entropyhash作為后面的checksum
????byte[] hash = Sha256Hash.hash(entropy);詳情開發(fā)I59案例2OO7需求3O69
????//將hash轉(zhuǎn)換成二進(jìn)制,true為1,false為0。詳情請(qǐng)看bytesToBits函數(shù)的解析
????boolean[] hashBits = bytesToBits(hash);
?????
????//將隨機(jī)數(shù)組轉(zhuǎn)換成二進(jìn)制
????boolean[] entropyBits = bytesToBits(entropy);
?????
????//checksum長(zhǎng)度
????int checksumLengthBits = entropyBits.length / 32;
?
????// 將entropyBits和checksum加起來(lái),相當(dāng)于BIP39中的ENT+CS
????boolean[] concatBits = new boolean[entropyBits.length + checksumLengthBits];
????System.arraycopy(entropyBits, 0, concatBits, 0, entropyBits.length);
????System.arraycopy(hashBits, 0, concatBits, entropyBits.length, checksumLengthBits);
?
????/**
????*this.wordList是助記詞列表。開發(fā)源碼版:yy625019
?????*?
????**/
????ArrayList words = new ArrayList<>();
?????
????//助記詞個(gè)數(shù)
????int nwords = concatBits.length / 11;
????for (int i = 0; i < nwords; ++i) {
??????int index = 0;
??????for (int j = 0; j < 11; ++j) {
????????//java中int是由32位二進(jìn)制組成,index左移1位,如果concatBits對(duì)應(yīng)的位為true則將index對(duì)應(yīng)的位設(shè)置位1
????????index <<= 1;
????????if (concatBits[(i * 11) + j])
??????????index |= 0x1;
??????}開發(fā)邏輯:mrsfu123
??????//根據(jù)索引從助記詞列表中獲取單詞并添加到words
??????words.add(this.wordList.get(index));
????}
????//得到的助記詞??
????return words;????
??}
標(biāo)簽: