oleganza/CoreBitcoin

Watch only wallet with BTCKeychain?

Closed this issue · 3 comments

I want to only store the extended public key in the wallet for future address generation. Is it possible using this library to generate unlimited child addresses from the extended public key string only?

I know how to do it with the whole KeyChain but not just the extended public key.

Thanks in advanced!

Yes, you can instantiate BTCKeychain with an xpub:

// Initializes with a base58-encoded extended public or private key.
// Inherits the network from the formatted key.
- (id) initWithExtendedKey:(NSString*)extendedKey;

Thanks very much! For anyone using swift heres the code i used:

var data = BigUInt(userRandomness).serialize()

let mnemonic = BTCMnemonic.init(
                entropy: data,
                password: "",
                wordListType: BTCMnemonicWordListType.english
               )

let keychain = mnemonic?.keychain
let xpub = keychain?.extendedPublicKey
let childKeychain = BTCKeychain.init(extendedKey: xpub)
let newAddress = childKeychain?.key.address.string

keychain.extendedPublicKey already returns a string, so no need to call .description (which is only for debugging and does not guarantee the format). I have edited your snippet with this fix.

Same for address.description — it should be address.string.