btcwallet icon indicating copy to clipboard operation
btcwallet copied to clipboard

restoring from seed

Open JFixby opened this issue 4 years ago • 5 comments

I`m using btcsuite/btcwallet v0.11.0 and trying to restore from the hex seed.

Unfortunately after the restoring some funds and accounts are missing and the wallet does not recognize its addresses (unspent outputs) in blockchain.

Is there a way to restore from the hex seed on some other alternative wallet to retrieve the funds? I tried Electrum but it didn`t recognize the hex seed generated by the btcsuite/btcwallet.

Can I convert maybe the hex seed into some format recognized by other alternative wallets?

JFixby avatar Feb 10 '21 18:02 JFixby

There hasn't been a tagged release in a while but many things were fixed anyway. You can try out the master branch. Maybe your problem was fixed by https://github.com/btcsuite/btcwallet/pull/682.

You can paste the hex seed here for example: https://guggero.github.io/cryptography-toolkit/#!/hd-wallet (or use the provided offline version!) where it says "Seed hex". Then you'll get the xprv... out which Electrum might understand.

guggero avatar Feb 10 '21 19:02 guggero

Ok I produced xprv from the seed using btcwallet code:

import (
	"encoding/hex"
	"fmt"
	"github.com/btcsuite/btcd/chaincfg"
	"github.com/btcsuite/btcutil/hdkeychain"
	"github.com/jfixby/pin/lang"

	"github.com/decred/dcrwallet/pgpwordlist"
	"github.com/jfixby/pin"

	"testing"
)

func TestSeed(t *testing.T) {

	hexs := "asdf...." //btcwallet generated seed
	data, err := hex.DecodeString(hexs)
	lang.CheckErr(err)

	// Derive the master extended key from the seed.
	rootKey, err := hdkeychain.NewMaster(data, &chaincfg.MainNetParams)
	lang.CheckErr(err)

	rootPubKey, err := rootKey.Neuter()
	lang.CheckErr(err)

	fmt.Println("Master private key: ", rootKey)
	fmt.Println("Master public key: ", rootPubKey)
}

It prints out xprv...

However bitcoin-cli importprivkey does not recognize the format. Is it possible to convert it to something compatible?

Also I checked btcctl --wallet dumpwallet says method is not implemented. Is it expected behaviour?

JFixby avatar Feb 12 '21 17:02 JFixby

I believe bitcoin-cli importprivkey expects a private key in Wallet Import Format (WIF). See https://en.bitcoin.it/wiki/Wallet_import_format for more info.

wpaulino avatar Feb 15 '21 23:02 wpaulino

Seems like I'm in a forced hodl here. The less I'm trying to fix the problem the more money I make on my locked btc. xD

JFixby avatar Mar 09 '21 19:03 JFixby

@JFixby have you seen https://pkg.go.dev/github.com/btcsuite/[email protected]/wallet#Wallet.DumpWIFPrivateKey?

wpaulino avatar Mar 10 '21 22:03 wpaulino