alexbosworth / ln-service

Node.js interface to LND
MIT License
319 stars 60 forks source link

createWallet yields UnexpectedUnlockWalletError #102

Closed jacohend closed 5 years ago

jacohend commented 5 years ago

I'm attempting to use createWallet on an uninitialized lnd instance to initialize a wallet from an existing seed/password. I'm receiving

Could not unlock the lnd wallet: 503,UnexpectedUnlockWalletError,[object Object]

I think not being able to see the error Object is a bug, and it's not clear why I'd be getting an "unlock" error when I'm not trying to unlock the wallet.

This is my code:

    let lndWalletPass="xxxxx"
    let lndWalletSeed="xxxxx"
    try {
        let create
        if (typeof lndWalletPass !== 'undefined' && typeof lndWalletSeed !== 'undefined') {
            create = await lnService.createWallet({ lnd, seed: lndWalletSeed, password: lndWalletPass })
            console.log(create)
        } else {
            lndWalletPass = generator.generate({
                length: 20,
                numbers: true
            })
            const { seed } = await lnService.createSeed({ lnd })
            create = await lnService.createWallet({ lnd, seed: seed, password: lndWalletPass })
            console.log(chalk.green(`LND Wallet Password: ${lndWalletPass}`))
            console.log(chalk.green(`LND Wallet Seed: ${seed}`))
        }
        console.log(create)
        //let unlock = await lnService.unlockWallet({ lnd, password: lndWalletPass })
        //console.log(unlock)
    } catch (err) {
        console.log(chalk.red(`Could not unlock the lnd wallet: ${err}`))
        return
    }

Any assistance would be appreciated.

alexbosworth commented 5 years ago

how are you instantiating the lnd object?

jacohend commented 5 years ago

@alexbosworth Thanks. Here's how I'm instantiating:

let tlsCert = toBase64(`${homedir}/.lnd/tls.cert`)
let { lnd } = lnService.unauthenticatedLndGrpc({
        cert: tlsCert,
        socket: '127.0.0.1:10009'
})

Logging indicates the tls cert is being correctly decoded to b64 string. LND is running in docker-compose with 10009 exposed in host mode.

alexbosworth commented 5 years ago

How are you generating the seed? There is a generate seed method you should be using

You can try just logging the err by itself, it might help to see what is going on

alexbosworth commented 5 years ago

If you want to see a full flow of creating a wallet, you can check this test file: https://github.com/alexbosworth/ln-service/blob/master/test/macros/spawn_lnd.js

jacohend commented 5 years ago

I was using the seed method to create the cipher_seed_mnemonic I passed to initWallet. I couldn't figure out the issue, so I went with using my own grpc client and it seems to be working fine.