foxnut / go-hdwallet

A multi-cryptocurrency HD wallet implementated by Golang.
MIT License
105 stars 56 forks source link

Incorrect address by mnemonic phrase (BTC) #9

Open turbo-nyasha opened 2 years ago

turbo-nyasha commented 2 years ago

Hi, i'm try to generate address pool by mnemonic phrase (which i check with TrustWallet) and i got wrong address:

import (
    "fmt"
    "github.com/foxnut/go-hdwallet"
)

func main() {
    mnemonic := "build twice play danger limit faculty weird coil target immune zero reform"
    k, _ := hdwallet.NewKey(hdwallet.Mnemonic(mnemonic))
    w, _ := k.GetWallet(hdwallet.CoinType(hdwallet.BTC))
    addr1, _ := w.GetKey().AddressP2WPKH()
    //expected bc1q99pp52svzq4fqkl6p4c7zjywmafqydgw0g7a2y
    fmt.Println(addr1)
    //actual bc1qqsjukgskejs6n80dkdkvk5pnlfsfj0fux9a99r
}

Installing with -u option is not working, this is deps:

        github.com/btcsuite/btcd v0.20.1-beta // indirect
    github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
    github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d // indirect
    github.com/cpacia/bchutil v0.0.0-20181003130114-b126f6a35b6c // indirect
    github.com/ethereum/go-ethereum v1.9.13 // indirect
    github.com/foxnut/go-hdwallet v0.0.0-20200602072018-8db9c730e77c // indirect
    github.com/tyler-smith/go-bip39 v1.0.2 // indirect
    golang.org/x/crypto v0.0.0-20200427165652-729f1e841bcc // indirect
    golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect
AndreyMashukov commented 1 month ago

Hi, i'm try to generate address pool by mnemonic phrase (which i check with TrustWallet) and i got wrong address:

import (
  "fmt"
  "github.com/foxnut/go-hdwallet"
)

func main() {
  mnemonic := "build twice play danger limit faculty weird coil target immune zero reform"
  k, _ := hdwallet.NewKey(hdwallet.Mnemonic(mnemonic))
  w, _ := k.GetWallet(hdwallet.CoinType(hdwallet.BTC))
  addr1, _ := w.GetKey().AddressP2WPKH()
  //expected bc1q99pp52svzq4fqkl6p4c7zjywmafqydgw0g7a2y
  fmt.Println(addr1)
  //actual bc1qqsjukgskejs6n80dkdkvk5pnlfsfj0fux9a99r
}

Installing with -u option is not working, this is deps:

        github.com/btcsuite/btcd v0.20.1-beta // indirect
  github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
  github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d // indirect
  github.com/cpacia/bchutil v0.0.0-20181003130114-b126f6a35b6c // indirect
  github.com/ethereum/go-ethereum v1.9.13 // indirect
  github.com/foxnut/go-hdwallet v0.0.0-20200602072018-8db9c730e77c // indirect
  github.com/tyler-smith/go-bip39 v1.0.2 // indirect
  golang.org/x/crypto v0.0.0-20200427165652-729f1e841bcc // indirect
  golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect
"m/0'/0/0",        // Bip32
"m/44'/0'/0'/0/0", // Bip44
"m/49'/0'/0'/0/0", // Bip49
"m/84'/0'/0'/0/0", // Bip84 (Trust Wallet) <- use this one 

@turbo-nyasha

you should use correct Derivation Path