i'm new on blockchain development and i'm trying to make a login like metamask in vuejs. Can someone teach me how to make 13 mnemonics word, where the last mnemonic is the password value get from an input using bip39?
async createWallet(){
const mnemonic = await generateMnemonic();
// const entropy = await entropyToMnemonic();
// this.passphraseCreated = entropy
if(this.selectLang == 'english'){
this.mnemonic = await setDefaultWordlist('english')
} else if (this.selectLang == 'chinese'){
this.mnemonic = await setDefaultWordlist('chinese_traditional')
}
const seed = await mnemonicToSeed(this.mnemonic, this.createPassword || "");
const root = hdkey.fromMasterSeed(seed);
const masterPrivateKey = root.privateKey.toString('hex');
const addrNode = root.derive("m/44'/60'/0'/0/0");
const pubKey = privateToPublic(addrNode._privateKey);
const addr = publicToAddress(pubKey).toString('hex');
const address = toChecksumAddress(addr);
console.log(mnemonic)
async login() {
const seed = await mnemonicToSeed(this.mnWrited, this.passLogin || "")
if(validateMnemonic(this.mnWrited || this.passLogin))
{
const root = hdkey.fromMasterSeed(seed)
const addrNode = root.derive("m/44'/60'/0'/0/0")
const pubKey = privateToPublic(addrNode._privateKey)
const addr = publicToAddress(pubKey).toString('hex')
const address = toChecksumAddress(addr)
this.address = address
console.log(address)
fetch('https://api.etherscan.io/api?module=account&action=balance&address=' + address + '&tag=latest&apikey=R5AABKRFH5HMXBA9IBQ5G44HS84B8YJWFI')
.then(response => response.json())
.then(response => {
if(response.status == '0'){
// console.log(response.message)
// this.logged = true;
}
else {
// console.log(response)
this.logged = true;
}
})
}
else
{
console.log("Wrong Words")
this.showResponse = true;
}
// if(this.mnWrited.length < 12 && this.mnWrited.length > 12){
// console.log('Digite as 12 palavras.')
// }
},
mnemonicToSeed
from bip39 accept an optional password as second parameter. Your code seems to already use it. What is your problem?