Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to generate a BIP32 xpub from a mnemonic for segwit accounts? #1535

Closed
yuradmt opened this issue Jan 19, 2020 · 2 comments
Closed

How to generate a BIP32 xpub from a mnemonic for segwit accounts? #1535

yuradmt opened this issue Jan 19, 2020 · 2 comments

Comments

@yuradmt
Copy link

yuradmt commented Jan 19, 2020

I use the following code to generate a bip32 xpub:

function getXpub(mne: string, format: string) {
  const seed = bip39.mnemonicToSeedSync(mne) 
  const root = bip32.fromSeed(seed)
  const purpose = format === 'p2pkh' ? '44' : format === 'p2sh-segwit' ? '49' : '84'
  const path = `m/${purpose}'/1'/0'`
  const node = root.derivePath(path)
  return node.neutered().toBase58()
}

It generates a correct xpub for legacy p2pkh addresses, but not for segwit addresses. How can I fix it to work with segwit properly?

@yuradmt
Copy link
Author

yuradmt commented Jan 19, 2020

Found the answer here #927

@yuradmt yuradmt closed this as completed Jan 19, 2020
@youfoundron
Copy link

@yuradmt mind sharing the snippet that worked?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants