[ad_1]
Today, most crypto wallets use a 24-word recovery phrase. Using 264-bit phrases can reliably protect your private key from hacker attacks. But in this story, for the sake of simplicity, I will show you how to implement a 12-word seed phrase.
Basically, a seed phrase is a set of predefined words (in Bitcoin improvement proposal 0039 vocabulary, or BIP39 vocabulary, Referred to) Allows you to restore your Private key, So you can control the expenditure funds. This is a very simple and user-friendly function. I strongly recommend that you use seed phrases-no matter what happens to your computer or phone, you will always have a backup. Let’s see how it can be seen through the eyes of the developer.
Most modern wallets (the so-called HD wallet) support BIP32 (Aka BIP32-Ed25519 In Cardano) and BIP39, So they pre-installed a dictionary containing 2048 words to recover the private key (master private key), or more accurately, the range is 1 to 204⁸²⁴…204⁸²⁴ possible combinations.In this story, I used a 12-character Mnemonic, The number of possible combinations is 204⁸¹² or ²¹³², as shown in the table.
|--------------------|--------------------|--------------------|
| Seed Phrase | Bits | Checksum |
|--------------------|--------------------|--------------------|
| 9-word | 99 (96+3) | 3-bit |
|--------------------|--------------------|--------------------|
| 12-word | 132 (128+4) | 4-bit |
|--------------------|--------------------|--------------------|
| 15-word | 165 (160+5) | 5-bit |
|--------------------|--------------------|--------------------|
| 18-word | 198 (192+6) | 6-bit |
|--------------------|--------------------|--------------------|
| 21-word | 231 (224+7) | 7-bit |
|--------------------|--------------------|--------------------|
| 24-word | 264 (256+8) | 8-bit |
|--------------------|--------------------|--------------------|
In recent years, 9 characters and 12 characters Second factor phrase Recovery has become more and more popular.
First, we need a natural binary number from 0 to ²¹²⁸–1.In order to get it, I should use a Random number generator (RNG), but I am too lazy to download, so I have to toss a coin 128 times. Laziness is not the engine of progress. 🙂
call! It’s really hard. Let’s check what I got.This is my 128-bit binary number, very low entropy, That is Why.
00101110100101011010001011010111100011011011010100110101110010110000000101001110001110011001101011010101001110111101111010001011
By the way, I have prepared a 12-word table for my binary file:
As you can see, each word contains 11 cells (ie bits), so 2¹¹ = 2048 variations (from 0 to 2047 inclusive). I use Xcode Playground to calculate it:
Now, for convenience, I will use an underscore to separate the 11-bit groups from each other_`Sign.
00101110100_10101101000_10110101111_00011011011_01010011010_11100101100_00000101001_11000111001_10011010110_10101001110_11110111101_0001011
Then I will put them in the table:
As a result, the last word is missing 4 bits. Why don’t I use 132 digits-what are you asking? Don’t worry!The last 4 digits of the entire 12-character phrase are used as Checksum.
First, let’s convert all 11 digits to decimals (except the last one).However, we must remember that the words in the BIP39 dictionary start with a decimal index 0001, But the smallest binary value of any 12 words is 00000000000. So I must add 1 To each binary value.
The conversion in Xcode Playground is natural. You don’t even need any online converters.
Now copy and paste the decimals into the red cells.
After that, we can easily English word list Through the corresponding index. Please note that this dictionary has an outdated version.Make sure you are using the actual vocabulary version.
I only need to perform the last step-calculate the index of the twelfth word.For this, I will run my entire 128-bit number SHA-256 Hash function.From the 256-bit value generated, I will borrow Top 4, I will insert it at the end of the mnemonic.This is an Checksum.
My last sentence is now known.
That’s the word Blade.
Word order Seed phrase Very important!
|-----|--------------------|
| # | Word |
|-----|--------------------|
| 1 | company |
|-----|--------------------|
| 2 | public |
|-----|--------------------|
| 3 | remove |
|-----|--------------------|
| 4 | bread |
|-----|--------------------|
| 5 | fashion |
|-----|--------------------|
| 6 | tortoise |
|-----|--------------------|
| 7 | ahead |
|-----|--------------------|
| 8 | shrimp |
|-----|--------------------|
| 9 | onion |
|-----|--------------------|
| 10 | prefer |
|-----|--------------------|
| 11 | waste |
|-----|--------------------|
| 12 | blade |
|-----|--------------------|
- If the word order in the mnemonic has changed, or you have made at least one spelling error, The private key will not be recovered — Therefore, you will not be able to use your wallet.
- Keep your mnemonic phrase in a safe and inaccessible place and do not show it to anyone. Do not store your seed phrase on your phone, computer or the Internet. Who can access your seed phrase can access the funds in your wallet.
The reconstruction of the source binary number is simple.Let’s declare a dictionary in Swift (where LHS is key, RHS is Values):
let wordList: [String: String] = [ "company": "00101110100",
"public": "10101101000",
"remove": "10110101111",
"bread": "00011011011",
"fashion": "01010011010",
"tortoise": "11100101100",
"ahead": "00000101001",
"shrimp": "11000111001",
"onion": "10011010110",
"prefer": "10101001110",
"waste": "11110111101",
"blade": "00010111000"
]
It’s time to check if it works. The nature of the dictionary in Swift is such that if you enter a dictionary with a non-existent key, it will return zero therefore.In other words, the dictionary in Swift is Elective Under the hood.
wordList["tortoise"] // "11100101100"wordList["tortose"] // nil, because there's a typo...
The easiest way to reconstruct a binary number is to use the addition of strings.Please note that if you enter the wrong word instead of the corresponding dictionary key (whether it is a wrong word or misspelling), you will receive the default value 00000000000, Which will lead to incorrect reconstruction of the original binary number.
var reco: String = wordList["company", default: "00000000000"] +
wordList["public", default: "00000000000"] +
wordList["remove", default: "00000000000"] +
wordList["bread", default: "00000000000"] +
wordList["fashion", default: "00000000000"] +
wordList["tortoise", default: "00000000000"] +
wordList["ahead", default: "00000000000"] +
wordList["shrimp", default: "00000000000"] +
wordList["onion", default: "00000000000"] +
wordList["prefer", default: "00000000000"] +
wordList["waste", default: "00000000000"] +
wordList["blade", default: "00000000000"]print(reco)reco.count // 132
This is a 132-digit value:
001011101001010110100010110101111000110110110101001101011100101100000001010011100011100110011010110101010011101111011110100010111000
I need to truncate the last four characters to get a 128-bit source.
var truncated = String(reco.dropLast(4))print(truncated)truncated.count // 128
Look!That’s ours Original number, Isn’t it?
00101110100101011010001011010111100011011011010100110101110010110000000101001110001110011001101011010101001110111101111010001011
Of course, you can use wordlist to create a binary number, and vice versa. But because of the lowest possible entropy, this is a bad idea. People often tend to simplify—for example, a seed phrase can contain a list of verbs extracted from the BIP39 dictionary in ascending index order. In this case, your private key is a simple game for hackers.
abandon (0001), absent (0006), absorb (0007), abuse (0010),
accuse (0014), achieve (0015), acquire (0018), act (0020),
adapt (0025), add (0026), addict (0027), GUESS LAST WORD ?
For those who are paranoid about the safety of seed phrases, there is a metal box to protect your 24-word mnemonic in the event of fire and flood.
addr1q9w70n62nu8p7f9ukfn66gzumm9d9uxwppkx7gk7vd7gy0ehfavj97gkncwm8t8l8l8x9e4adzmw2djh4y5gd9rmtewqr99zr3
That’s it so far.
If this story is helpful to you, please press shoot Button and catch it.In Medium you can applaud 50 times Every story.
If you have any questions, you can contact me in the following ways Cardano Stack Exchange.
Happy bet!
[ad_2]
Source link