0

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.')
        // }
    },
4
  • The function mnemonicToSeed from bip39 accept an optional password as second parameter. Your code seems to already use it. What is your problem?
    – Ismael
    Aug 16, 2019 at 3:07
  • When i try to login, he doesen't recognize the password as valid. I Updated my question with the login code. Aug 16, 2019 at 21:15
  • Sorry, but without a small reproducible example is impossible to say what is wrong.
    – Ismael
    Aug 17, 2019 at 16:52
  • I edited post and put an async login () function Aug 19, 2019 at 0:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.