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

Support for BIP49 (segwit) address? #24

Open
ecdsa521 opened this issue Dec 12, 2017 · 3 comments
Open

Support for BIP49 (segwit) address? #24

ecdsa521 opened this issue Dec 12, 2017 · 3 comments

Comments

@ecdsa521
Copy link

Hello

Is it possible to generate segwit style addresses as defined in BIP49? It should be compatible with BIP44 and only require change to derivation path, but I am not able to generate proper segwit addresses. It also seems impossible to generate addresses using custom derivation path without private key part?

k=BTC::Keychain.new :xpub => "xpub6CUGRUonZSQ4TWtTMmzXdrXDtypWKiKrhko4egpiMZbpiaQL2jkwSB1icqYh2cfDfVxdx4df189oLKnC5fSwqPfgyP3hooxujYzAu3fDVmz"
k.derived_key("m/49'/0'/0'/1'").address

The result is BTC::BTCError: Not possible to derive a hardened keychain without a private key (index: 49).

If I do initialize it with xprv instead, for example

k=BTC::Keychain.new :xprv => "xprv9s21ZrQH143K4KqQx9Zrf1eN8EaPQVFxM2Ast8mdHn7GKiDWzNEyNdduJhWXToy8MpkGcKjxeFWd8oBSvsz4PCYamxR7TX49pSpp3bmHVAY"
k.derived_key("m/49'/0'/0'/1'").address
# => #<BTC::PublicKeyAddress:1AgPR8sjddSPY4ZQsZet5JxjEJTLrSMqVK>

It does generate address, but not segwit style.

Can you please tell me if I am doing something wrong? Ideally I want to generate segwit style addresses with only xpub.

@iamajvillalobos
Copy link

I think you're using it incorrectly. I tried to use it like this and it works perfectly. You don't need to supply the full path but only the index.

wallet = BTC::Keychain.new(xpub: "xpub6EEtgK5WdTq4FK4BwU38C8g2FKAANdMoxCoKXwkjFSm3p2qCqbGQPehPBKi5PdeGM3JqZR4y5mFsAexSCCS8vogQpv9CV6vFPeznEUTjvMX")
wallet.derived_key(0).address.to_s  # 151BbmtNVLduGhumeq1vuxFvp5PejuQdtC

Which is the same when I use tool like https://coinomi.com/recovery-phrase-tool.html
screenshot-2018-3-28 bip39 - mnemonic code

@ecdsa521
Copy link
Author

@iamarmanjon this is old style address, not Segwit.

Segwit addresses are either old style, embedded in P2SH, starting with "3", or new style (bech32) starting with "bc1"

@sha-0
Copy link

sha-0 commented Jul 19, 2018

Any plans to add SegWit (BIP49/BIP84) support? @oleganza

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

3 participants