Java Code Examples for org.bitcoinj.crypto.DeterministicKey#serializePubB58()

The following examples show how to use org.bitcoinj.crypto.DeterministicKey#serializePubB58() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SeedUtil.java    From snowblossom with Apache License 2.0 6 votes vote down vote up
public static ByteString getSeedId(NetworkParams params, String seed_str, String pass, int account)
{
  ByteString seed = decodeSeed(seed_str,pass);
  DeterministicKey dk = HDKeyDerivation.createMasterPrivateKey(seed.toByteArray());
  DeterministicHierarchy dh = new DeterministicHierarchy(dk);


  DeterministicKey dk_acct = dh.get( ImmutableList.of(
    	new ChildNumber(44,true),
    	new ChildNumber(params.getBIP44CoinNumber(),true),
    	new ChildNumber(account,true)
	),
    true, true);

  String xpub = dk_acct.serializePubB58( org.bitcoinj.params.MainNetParams.get() );
  ByteString seed_id = ByteString.copyFrom(dk_acct.getIdentifier());

  return seed_id;
}
 
Example 2
Source File: SeedUtil.java    From snowblossom with Apache License 2.0 6 votes vote down vote up
public static String getSeedXpub(NetworkParams params, String seed_str, String pass, int account)
{
  ByteString seed = decodeSeed(seed_str,pass);
  DeterministicKey dk = HDKeyDerivation.createMasterPrivateKey(seed.toByteArray());
  DeterministicHierarchy dh = new DeterministicHierarchy(dk);


  DeterministicKey dk_acct = dh.get( ImmutableList.of(
    	new ChildNumber(44,true),
    	new ChildNumber(params.getBIP44CoinNumber(),true),
    	new ChildNumber(account,true)
	),
    true, true);

  String xpub = dk_acct.serializePubB58( org.bitcoinj.params.MainNetParams.get() );
  return xpub;
}
 
Example 3
Source File: HDMnemonicKeystore.java    From token-core-android with Apache License 2.0 5 votes vote down vote up
public HDMnemonicKeystore(Metadata metadata, String password, List<String> mnemonics, String path, String id) {
  MnemonicUtil.validateMnemonics(mnemonics);
  DeterministicSeed seed = new DeterministicSeed(mnemonics, null, "", 0L);
  DeterministicKeyChain keyChain = DeterministicKeyChain.builder().seed(seed).build();
  this.mnemonicPath = path;

  DeterministicKey parent = keyChain.getKeyByPath(BIP44Util.generatePath(path), true);
  NetworkParameters networkParameters = metadata.isMainNet() ? MainNetParams.get() : TestNet3Params.get();
  this.xpub = parent.serializePubB58(networkParameters);
  String xprv = parent.serializePrivB58(networkParameters);
  DeterministicKey mainAddressKey = keyChain.getKeyByPath(BIP44Util.generatePath(path + "/0/0"), true);
  if (Metadata.P2WPKH.equals(metadata.getSegWit())) {
    this.address = new SegWitBitcoinAddressCreator(networkParameters).fromPrivateKey(mainAddressKey.getPrivateKeyAsHex());
  } else {
    this.address = mainAddressKey.toAddress(networkParameters).toBase58();
  }
  if (metadata.getTimestamp() == 0) {
    metadata.setTimestamp(DateUtil.getUTCTime());
  }
  metadata.setWalletType(Metadata.HD);

  this.crypto = Crypto.createPBKDF2CryptoWithKDFCached(password, xprv.getBytes(Charset.forName("UTF-8")));
  this.metadata = metadata;
  this.encMnemonic = crypto.deriveEncPair(password, Joiner.on(" ").join(mnemonics).getBytes());
  this.crypto.clearCachedDerivedKey();

  this.version = VERSION;
  this.info = new Info();
  this.id = Strings.isNullOrEmpty(id) ? UUID.randomUUID().toString() : id;
}