HD Wallet

TIP

All Vite official wallets are HD wallets. For specific derivation rules, please visit: VEP-3

For the HD protocol, please visit: HD Protocol, HD Wallet, BIP3

Key generation steps

To generate the private key, Vite wallet will

  1. Follow BIP39 protocol to generate 24-word mnemonic phrase and the entropy;
  2. Generate seed from mnemonic. In this step Two-Factor Seed Phrases is not supported;
  3. Derive master key from hashed seed through HMAC(Hash-based Message Authentication Code)-SHA512 algorithm with key ed25519 blake2b seed;
  4. Follow BIP44 protocol to derive private key and address of Vite from master key. The coin_type 666666 has been registered as Vite at SLIP-0044.

The role of the wallet password

When creating an account in the wallet, user needs to enter a password, which is not Two-Factor Seed Phrases, but one of the parameters we encrypt BIP39 entropy. The specific encryption is different in iOS wallet, web wallet and go-vite built-in wallet

  1. Go-vite built-in wallet: The user password is derived to a 256-bit encryption key of AES-GCM algorithm using the scrypt algorithm with standard parameters. The BIP39 entropy is encrypted with the key and stored in an EntropyStore file in user's file system. User can backup this file, so that even if his mnemonic phrase is lost it can always be recovered by decrypting the file.
  2. Web wallet: The password is derived to 256-bit encryption key using the scrypt algorithm with lightweight parameters. The wallet employs AES-GCM algorithm to encrypt entropy into cipher text and stores in localStorage.
  3. iOS Wallet: The salted hash value of user password is used as AES-GCM encryption key to encrypt the entropy. The encrypted data is saved in App Sandbox. After the user enters the password to log in wallet, the data is decrypted and derived into private key.

Account recovery from mnemonic phrase

A single mnemonic, under the rule of vep-3: m/44'/666666'/x', theoretically can derive 2^32-1 addresses. So how does the wallet restore the account from the mnemonic phrase if the user forgets his private key, or even his Vite address as well?

In web wallet, iOS wallet and Android wallet(yet to be released), a default maximum of 10 addresses are generated from one mnemonic phrase. When restoring account, the wallet will traverse the 0-9 address to check whether they are used. For example, if a transaction is found on the 8th address, the wallet will immediately restore all the addresses of 0-8. Therefore, do remember your mnemonic, because from which your lost accounts/private keys can always be found back.

Large-scale address derivation

You can directly integrate go-vite wallet module in your project. After creating the mnemonic and having it unlocked, you will have entropystore.Manager object with two methods: DeriveForFullPath and DeriveForIndexPath.

  1. DeriveForFullPath: As method name suggests, the complete prefix m/44'/666666'/x' is passed in to derive address and private key. This method can also be used at a very large scale such as the required addresses exceed 2^32. To meet this purpose, passing in m/44'/666666'/x'/y'/z'/...(x, y and z are uint32 values indicating different sub levels, each of which has 2^32-1 sub addresses associated).

  2. DeriveForIndexPath: After passing in a uint32 value x, this method will compose a prefix string of m/44'/666666'/x' and call DeriveForFullPath, then return related private key and account address. Up to 2^32-1 addresses can be generated by this method.