oleganza / CoreBitcoin

Awesome Bitcoin toolkit for ObjC and Swift
Do What The F*ck You Want To Public License
719 stars 255 forks source link

How to generate public key from mnemonic in testnet? #102

Closed xx11dragon closed 6 years ago

xx11dragon commented 6 years ago

I trying mnemonic to public key, it working in mainnet.

NSArray * array = @[@"know", @"final", @"wide", @"brush", @"educate", @"bleak", @"exact", @"exhibit", @"coil", @"galaxy", @"milk", @"rhythm"];

BTCMnemonic *mnemonic = [[BTCMnemonic alloc] initWithWords:array password:nil 
wordListType:BTCMnemonicWordListTypeEnglish];
BTCKeychain *mainKeychain = [[BTCKeychain alloc] initWithSeed:mnemonic.seed network:
[BTCNetwork mainnet]];
BTCKeychain *purpose = [mainKeychain derivedKeychainAtIndex:44 hardened:YES];
BTCKeychain *coin = [purpose derivedKeychainAtIndex:0 hardened:YES];
BTCKeychain *account = [coin derivedKeychainAtIndex:0 hardened:YES];

BTCKeychain *keychainFirst = [account derivedKeychainAtIndex:0 hardened:NO];
BTCKeychain *keychainSecond = [keychainFirst derivedKeychainAtIndex:0 hardened:NO];

NSLog(@"public key - %@", keychainSecond.key.compressedPublicKeyAddress.string);

and, i want change testnet: Change code:

BTCKeychain *mainKeychain = [[BTCKeychain alloc] initWithSeed:mnemonic.seed network:
[BTCNetwork testnet]];
NSLog(@"testnet public key - %@", keychainSecond.key.addressTestnet.string);

I 've got the wrong private.

Could you please explain me solution of that problem?

Do you have any document or example?

Thanks

xx11dragon commented 6 years ago

use [mainKeychain derivedKeychainWithPath:@"m/44'/1'/0'/0/0"];in testnet.