Java Code Examples for org.bitcoinj.crypto.ChildNumber

The following examples show how to use org.bitcoinj.crypto.ChildNumber. These examples are extracted from open source projects. 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 Project: token-core-android   Source File: V3MnemonicKeystore.java    License: Apache License 2.0 6 votes vote down vote up
private V3MnemonicKeystore(Metadata metadata, String password, List<String> mnemonicCodes, String path, String id) {
  MnemonicUtil.validateMnemonics(mnemonicCodes);
  DeterministicSeed seed = new DeterministicSeed(mnemonicCodes, null, "", 0L);
  DeterministicKeyChain keyChain = DeterministicKeyChain.builder().seed(seed).build();

  this.mnemonicPath = path;
  List<ChildNumber> zeroPath = BIP44Util.generatePath(path);

  byte[] prvKeyBytes = keyChain.getKeyByPath(zeroPath, true).getPrivKeyBytes();
  this.crypto = Crypto.createPBKDF2CryptoWithKDFCached(password, prvKeyBytes);
  this.encMnemonic = crypto.deriveEncPair(password, Joiner.on(" ").join(mnemonicCodes).getBytes());
  this.crypto.clearCachedDerivedKey();

  this.address = AddressCreatorManager.getInstance(metadata.getChainType(), metadata.isMainNet(), metadata.getSegWit()).fromPrivateKey(prvKeyBytes);
  metadata.setTimestamp(DateUtil.getUTCTime());
  metadata.setWalletType(Metadata.V3);
  this.metadata = metadata;
  this.version = VERSION;
  this.id = Strings.isNullOrEmpty(id) ? UUID.randomUUID().toString() : id;
}
 
Example 2
public void createWallet2(String passphrase, Runnable callback) {

        wallet = new Wallet(params);
        DeterministicSeed seed = wallet.getKeyChainSeed();
        mnemonicKey = Joiner.on(" ").join(seed.getMnemonicCode());
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));

        walletFriendlyAddress = wallet.currentReceiveAddress().toString();

        ChildNumber childNumber = new ChildNumber(ChildNumber.HARDENED_BIT);
        DeterministicKey de = wallet.getKeyByPath(ImmutableList.of(childNumber));
        xprvKey = de.serializePrivB58(params);

        wifKey = wallet.currentReceiveKey().getPrivateKeyAsWiF(params);

        callback.run();
    }
 
Example 3
Source Project: snowblossom   Source File: SeedUtil.java    License: 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 4
Source Project: snowblossom   Source File: SeedUtil.java    License: 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 5
Source Project: snowblossom   Source File: SeedTest.java    License: Apache License 2.0 6 votes vote down vote up
private void testVector(String seed, String data, String pw, String xprv)
  throws Exception
{
  ByteString expected = HexUtil.hexStringToBytes(data);

  ByteString found = SeedUtil.decodeSeed(seed, pw);

  Assert.assertEquals( HexUtil.getHexString(expected), HexUtil.getHexString(found));

  DeterministicKey dk = HDKeyDerivation.createMasterPrivateKey(found.toByteArray());
  DeterministicHierarchy dh = new DeterministicHierarchy(dk);

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

  Assert.assertEquals(
    xprv,
    dk_acct.serializePrivB58(org.bitcoinj.params.MainNetParams.get()));
}
 
Example 6
Source Project: thundernetwork   Source File: Tools.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Call to get the MasterKey for a new Channel.
 * TODO: Change to request master node key..
 *
 * @param number Query the Database to get the latest unused number
 * @return DeterministicKey for the new Channel
 */
public static DeterministicKey getMasterKey (int number) {

    DeterministicKey hd = DeterministicKey.deserializeB58(SideConstants.KEY_B58, Constants.getNetwork());
    //		DeterministicKey hd =  DeterministicKey.deserializeB58(null,KEY_B58);
    //        DeterministicKey hd = HDKeyDerivation.createMasterPrivateKey(KEY.getBytes());
    DeterministicHierarchy hi = new DeterministicHierarchy(hd);

    List<ChildNumber> childList = new ArrayList<ChildNumber>();
    ChildNumber childNumber = new ChildNumber(number, true);
    childList.add(childNumber);

    DeterministicKey key = hi.get(childList, true, true);
    return key;

}
 
Example 7
@Override
public DeterministicKeyChain makeWatchingKeyChain(Protos.Key key, Protos.Key firstSubKey, DeterministicKey accountKey,
                                                  boolean isFollowingKey, boolean isMarried) throws UnreadableWalletException {
    ImmutableList<ChildNumber> accountPath = useBitcoinDeterministicKeyChain ? BtcDeterministicKeyChain.BIP44_BTC_ACCOUNT_PATH : BisqDeterministicKeyChain.BIP44_BSQ_ACCOUNT_PATH;
    if (!accountKey.getPath().equals(accountPath))
        throw new UnreadableWalletException("Expecting account key but found key with path: " +
                HDUtils.formatPath(accountKey.getPath()));
    return useBitcoinDeterministicKeyChain ? new BtcDeterministicKeyChain(accountKey, isFollowingKey) : new BisqDeterministicKeyChain(accountKey, isFollowingKey);
}
 
Example 8
Source Project: token-core-android   Source File: BitcoinTransaction.java    License: Apache License 2.0 5 votes vote down vote up
private void collectPrvKeysAndAddress(String segWit, String password, Wallet wallet) {
  this.network = wallet.getMetadata().isMainNet() ? MainNetParams.get() : TestNet3Params.get();
  if (wallet.getMetadata().getSource().equals(Metadata.FROM_WIF)) {
    changeAddress = Address.fromBase58(network, wallet.getAddress());
    BigInteger prvKey = DumpedPrivateKey.fromBase58(network, wallet.exportPrivateKey(password)).getKey().getPrivKey();
    prvKeys = Collections.singletonList(prvKey);
  } else {
    prvKeys = new ArrayList<>(getOutputs().size());
    String xprv = new String(wallet.decryptMainKey(password), Charset.forName("UTF-8"));
    DeterministicKey xprvKey = DeterministicKey.deserializeB58(xprv, network);
    DeterministicKey changeKey = HDKeyDerivation.deriveChildKey(xprvKey, ChildNumber.ONE);
    DeterministicKey indexKey = HDKeyDerivation.deriveChildKey(changeKey, new ChildNumber(getChangeIdx(), false));
    if (Metadata.P2WPKH.equals(segWit)) {
      changeAddress = new SegWitBitcoinAddressCreator(network).fromPrivateKey(indexKey);
    } else {
      changeAddress = indexKey.toAddress(network);
    }

    for (UTXO output : getOutputs()) {
      String derivedPath = output.getDerivedPath().trim();
      String[] pathIdxs = derivedPath.replace('/', ' ').split(" ");
      int accountIdx = Integer.parseInt(pathIdxs[0]);
      int changeIdx = Integer.parseInt(pathIdxs[1]);

      DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(xprvKey, new ChildNumber(accountIdx, false));
      DeterministicKey externalChangeKey = HDKeyDerivation.deriveChildKey(accountKey, new ChildNumber(changeIdx, false));
      prvKeys.add(externalChangeKey.getPrivKey());
    }
  }
}
 
Example 9
Source Project: token-core-android   Source File: BIP44Util.java    License: Apache License 2.0 5 votes vote down vote up
public static ImmutableList<ChildNumber> generatePath(String path) {
  List<ChildNumber> list = new ArrayList<>();
  for (String p : path.split("/")) {
    if ("m".equalsIgnoreCase(p) || "".equals(p.trim())) {
      continue;
    } else if (p.charAt(p.length() - 1) == '\'') {
      list.add(new ChildNumber(Integer.parseInt(p.substring(0, p.length() - 1)), true));
    } else {
      list.add(new ChildNumber(Integer.parseInt(p), false));
    }
  }

  ImmutableList.Builder<ChildNumber> builder = ImmutableList.builder();
  return builder.addAll(list).build();
}
 
Example 10
Source Project: token-core-android   Source File: HDMnemonicKeystore.java    License: Apache License 2.0 5 votes vote down vote up
public String newReceiveAddress(int nextIdx) {
  NetworkParameters networkParameters = this.metadata.isMainNet() ? MainNetParams.get() : TestNet3Params.get();
  DeterministicKey key = DeterministicKey.deserializeB58(this.xpub, networkParameters);
  DeterministicKey changeKey = HDKeyDerivation.deriveChildKey(key, ChildNumber.ZERO);
  DeterministicKey indexKey = HDKeyDerivation.deriveChildKey(changeKey, new ChildNumber(nextIdx));
  if (Metadata.P2WPKH.equals(metadata.getSegWit())) {
    return new SegWitBitcoinAddressCreator(networkParameters).fromPrivateKey(indexKey).toBase58();
  } else {
    return indexKey.toAddress(networkParameters).toBase58();
  }
}
 
Example 11
public void restoreFromBlock(String mnemonicCode, WalletCreationCallback callback) {
    mnemonicCode = mnemonicCode.trim();
    if (mnemonicCode.equals("")) {
        callback.onWalletCreated(null);
        return;
    }

    DeterministicSeed seed = new DeterministicSeed(Splitter.on(' ').splitToList(mnemonicCode), null, "", 0);

    wallet = Wallet.fromSeed(params, seed);
    mnemonicKey = Joiner.on(" ").join(seed.getMnemonicCode());
    //sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));
    walletFriendlyAddress = wallet.currentReceiveAddress().toString();

    ChildNumber childNumber = new ChildNumber(ChildNumber.HARDENED_BIT);
    DeterministicKey de = wallet.getKeyByPath(ImmutableList.of(childNumber));
    xprvKey = de.serializePrivB58(params);

    wifKey = wallet.currentReceiveKey().getPrivateKeyAsWiF(params);

    RequestorBtc.getUTXOListDgbNew(wallet.currentReceiveAddress().toString(), new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItemDgb> utxos = (List<UTXOItemDgb>)response;
            setUTXO(utxos);
            callback.onWalletCreated(wallet);
        }

        @Override
        public void onFailure(String msg) {
            callback.onWalletCreated(wallet);
        }
    });
}
 
Example 12
public void restoreFromBlock2(String mnemonicCode, Runnable callback) {
    if (mnemonicCode.charAt(mnemonicCode.length() - 1) == ' ') {
        mnemonicCode = mnemonicCode.substring(0, mnemonicCode.length() - 1);
    }

    DeterministicSeed seed = new DeterministicSeed(Splitter.on(' ').splitToList(mnemonicCode), null, "", 0);

    wallet = Wallet.fromSeed(params, seed);
    mnemonicKey = Joiner.on(" ").join(seed.getMnemonicCode());
    sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));
    walletFriendlyAddress = wallet.currentReceiveAddress().toString();

    ChildNumber childNumber = new ChildNumber(ChildNumber.HARDENED_BIT);
    DeterministicKey de = wallet.getKeyByPath(ImmutableList.of(childNumber));
    xprvKey = de.serializePrivB58(params);

    wifKey = wallet.currentReceiveKey().getPrivateKeyAsWiF(params);

    callback.run();

    RequestorBtc.getUTXOListDgbNew(wallet.currentReceiveAddress().toString(), new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItemDgb> utxos = (List<UTXOItemDgb>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example 13
public void restoreFromBlock(String mnemonicCode, WalletCreationCallback callback) {
    mnemonicCode = mnemonicCode.trim();
    if (mnemonicCode.equals("")) {
        callback.onWalletCreated(null);
        return;
    }

    DeterministicSeed seed = new DeterministicSeed(Splitter.on(' ').splitToList(mnemonicCode), null, "", 0);

    wallet = Wallet.fromSeed(params, seed);
    mnemonicKey = Joiner.on(" ").join(seed.getMnemonicCode());
    //sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));
    walletFriendlyAddress = wallet.currentReceiveAddress().toString();

    ChildNumber childNumber = new ChildNumber(ChildNumber.HARDENED_BIT);
    DeterministicKey de = wallet.getKeyByPath(ImmutableList.of(childNumber));
    xprvKey = de.serializePrivB58(params);

    wifKey = wallet.currentReceiveKey().getPrivateKeyAsWiF(params);

    callback.onWalletCreated(wallet);

    RequestorBtc.getUTXOListSbtcNew(wallet.currentReceiveAddress().toString(), new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example 14
public void restoreFromBlock2(String mnemonicCode, Runnable callback) {
    if (mnemonicCode.charAt(mnemonicCode.length() - 1) == ' ') {
        mnemonicCode = mnemonicCode.substring(0, mnemonicCode.length() - 1);
    }

    DeterministicSeed seed = new DeterministicSeed(Splitter.on(' ').splitToList(mnemonicCode), null, "", 0);

    wallet = Wallet.fromSeed(params, seed);
    mnemonicKey = Joiner.on(" ").join(seed.getMnemonicCode());
    sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));
    walletFriendlyAddress = wallet.currentReceiveAddress().toString();

    ChildNumber childNumber = new ChildNumber(ChildNumber.HARDENED_BIT);
    DeterministicKey de = wallet.getKeyByPath(ImmutableList.of(childNumber));
    xprvKey = de.serializePrivB58(params);

    wifKey = wallet.currentReceiveKey().getPrivateKeyAsWiF(params);

    callback.run();

    RequestorBtc.getUTXOListSbtcNew(wallet.currentReceiveAddress().toString(), new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example 15
public void restoreFromBlock(String mnemonicCode, WalletCreationCallback callback) {
    mnemonicCode = mnemonicCode.trim();
    if (mnemonicCode.equals("")) {
        callback.onWalletCreated(null);
        return;
    }

    DeterministicSeed seed = new DeterministicSeed(Splitter.on(' ').splitToList(mnemonicCode), null, "", 0);

    wallet = Wallet.fromSeed(params, seed);
    mnemonicKey = Joiner.on(" ").join(seed.getMnemonicCode());
    //sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));
    walletFriendlyAddress = wallet.currentReceiveAddress().toString();

    ChildNumber childNumber = new ChildNumber(ChildNumber.HARDENED_BIT);
    DeterministicKey de = wallet.getKeyByPath(ImmutableList.of(childNumber));
    xprvKey = de.serializePrivB58(params);

    wifKey = wallet.currentReceiveKey().getPrivateKeyAsWiF(params);

    callback.onWalletCreated(wallet);

    RequestorBtc.getUTXOListLtcNew(wallet.currentReceiveAddress().toString(), new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example 16
public void restoreFromBlock2(String mnemonicCode, Runnable callback) {
    if (mnemonicCode.charAt(mnemonicCode.length() - 1) == ' ') {
        mnemonicCode = mnemonicCode.substring(0, mnemonicCode.length() - 1);
    }

    DeterministicSeed seed = new DeterministicSeed(Splitter.on(' ').splitToList(mnemonicCode), null, "", 0);

    wallet = Wallet.fromSeed(params, seed);
    mnemonicKey = Joiner.on(" ").join(seed.getMnemonicCode());
    sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));
    walletFriendlyAddress = wallet.currentReceiveAddress().toString();

    ChildNumber childNumber = new ChildNumber(ChildNumber.HARDENED_BIT);
    DeterministicKey de = wallet.getKeyByPath(ImmutableList.of(childNumber));
    xprvKey = de.serializePrivB58(params);

    wifKey = wallet.currentReceiveKey().getPrivateKeyAsWiF(params);

    callback.run();

    RequestorBtc.getUTXOListLtcNew(wallet.currentReceiveAddress().toString(), new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example 17
private List<ChildNumber> getPathParent() {
    List<ChildNumber> pathParent = new ArrayList<>();
    pathParent.add(new ChildNumber(88, true));
    pathParent.add(new ChildNumber(0, true));
    pathParent.add(new ChildNumber(0, true));
    return pathParent;
}
 
Example 18
public void restoreFromBlock(String mnemonicCode, WalletCreationCallback callback) {
    mnemonicCode = mnemonicCode.trim();
    if (mnemonicCode.equals("")) {
        callback.onWalletCreated(null);
        return;
    }

    DeterministicSeed seed = new DeterministicSeed(Splitter.on(' ').splitToList(mnemonicCode), null, "", 0);

    wallet = Wallet.fromSeed(params, seed);
    mnemonicKey = Joiner.on(" ").join(seed.getMnemonicCode());
    //sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));

    walletFriendlyAddress = wallet.currentReceiveAddress().toString();

    ChildNumber childNumber = new ChildNumber(ChildNumber.HARDENED_BIT);
    DeterministicKey de = wallet.getKeyByPath(ImmutableList.of(childNumber));
    xprvKey = de.serializePrivB58(params);

    wifKey = wallet.currentReceiveKey().getPrivateKeyAsWiF(params);

    callback.onWalletCreated(wallet);


    RequestorBtc.getUTXOList(wallet.currentReceiveAddress().toString(), new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            UTXOListResponse utxoResponse = (UTXOListResponse) response;
            setUTXO(utxoResponse.getUTXOList());
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example 19
public void restoreFromBlock2(String mnemonicCode, Runnable callback) {
    if (mnemonicCode.charAt(mnemonicCode.length() - 1) == ' ') {
        mnemonicCode = mnemonicCode.substring(0, mnemonicCode.length() - 1);
    }

    DeterministicSeed seed = new DeterministicSeed(Splitter.on(' ').splitToList(mnemonicCode), null, "", 0);

    wallet = Wallet.fromSeed(params, seed);
    mnemonicKey = Joiner.on(" ").join(seed.getMnemonicCode());
    sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));

    walletFriendlyAddress = wallet.currentReceiveAddress().toString();

    ChildNumber childNumber = new ChildNumber(ChildNumber.HARDENED_BIT);
    DeterministicKey de = wallet.getKeyByPath(ImmutableList.of(childNumber));
    xprvKey = de.serializePrivB58(params);

    wifKey = wallet.currentReceiveKey().getPrivateKeyAsWiF(params);

    callback.run();


    RequestorBtc.getUTXOList(wallet.currentReceiveAddress().toString(), new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            UTXOListResponse utxoResponse = (UTXOListResponse) response;
            setUTXO(utxoResponse.getUTXOList());
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example 20
public void restoreFromBlock(String mnemonicCode, WalletCreationCallback callback) {
    mnemonicCode = mnemonicCode.trim();
    if (mnemonicCode.equals("")) {
        callback.onWalletCreated(null);
        return;
    }

    DeterministicSeed seed = new DeterministicSeed(Splitter.on(' ').splitToList(mnemonicCode), null, "", 0);

    wallet = Wallet.fromSeed(params, seed);
    mnemonicKey = Joiner.on(" ").join(seed.getMnemonicCode());
    //sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));
    walletFriendlyAddress = wallet.currentReceiveAddress().toString();

    ChildNumber childNumber = new ChildNumber(ChildNumber.HARDENED_BIT);
    DeterministicKey de = wallet.getKeyByPath(ImmutableList.of(childNumber));
    xprvKey = de.serializePrivB58(params);

    wifKey = wallet.currentReceiveKey().getPrivateKeyAsWiF(params);

    callback.onWalletCreated(wallet);

    RequestorBtc.getUTXOListBtgNew(wallet.currentReceiveAddress().toString(), new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example 21
public void restoreFromBlock2(String mnemonicCode, Runnable callback) {
    if (mnemonicCode.charAt(mnemonicCode.length() - 1) == ' ') {
        mnemonicCode = mnemonicCode.substring(0, mnemonicCode.length() - 1);
    }

    DeterministicSeed seed = new DeterministicSeed(Splitter.on(' ').splitToList(mnemonicCode), null, "", 0);

    wallet = Wallet.fromSeed(params, seed);
    mnemonicKey = Joiner.on(" ").join(seed.getMnemonicCode());
    sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));
    walletFriendlyAddress = wallet.currentReceiveAddress().toString();

    ChildNumber childNumber = new ChildNumber(ChildNumber.HARDENED_BIT);
    DeterministicKey de = wallet.getKeyByPath(ImmutableList.of(childNumber));
    xprvKey = de.serializePrivB58(params);

    wifKey = wallet.currentReceiveKey().getPrivateKeyAsWiF(params);

    callback.run();

    RequestorBtc.getUTXOListBtgNew(wallet.currentReceiveAddress().toString(), new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example 22
public void restoreFromBlock(String mnemonicCode, WalletCreationCallback callback) {
    mnemonicCode = mnemonicCode.trim();
    if (mnemonicCode.equals("")) {
        callback.onWalletCreated(null);
        return;
    }

    DeterministicSeed seed = new DeterministicSeed(Splitter.on(' ').splitToList(mnemonicCode), null, "", 0);

    wallet = Wallet.fromSeed(params, seed);
    mnemonicKey = Joiner.on(" ").join(seed.getMnemonicCode());
    //sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));

    walletFriendlyAddress = wallet.currentReceiveAddress().toString();

    ChildNumber childNumber = new ChildNumber(ChildNumber.HARDENED_BIT);
    DeterministicKey de = wallet.getKeyByPath(ImmutableList.of(childNumber));
    xprvKey = de.serializePrivB58(params);

    wifKey = wallet.currentReceiveKey().getPrivateKeyAsWiF(params);

    callback.onWalletCreated(wallet);


    RequestorBtc.getUTXOListBch(wallet.currentReceiveAddress().toString(), new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example 23
public void restoreFromBlock2(String mnemonicCode, Runnable callback) {
    if (mnemonicCode.charAt(mnemonicCode.length() - 1) == ' ') {
        mnemonicCode = mnemonicCode.substring(0, mnemonicCode.length() - 1);
    }

    DeterministicSeed seed = new DeterministicSeed(Splitter.on(' ').splitToList(mnemonicCode), null, "", 0);

    wallet = Wallet.fromSeed(params, seed);
    mnemonicKey = Joiner.on(" ").join(seed.getMnemonicCode());
    sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));

    walletFriendlyAddress = wallet.currentReceiveAddress().toString();

    ChildNumber childNumber = new ChildNumber(ChildNumber.HARDENED_BIT);
    DeterministicKey de = wallet.getKeyByPath(ImmutableList.of(childNumber));
    xprvKey = de.serializePrivB58(params);

    wifKey = wallet.currentReceiveKey().getPrivateKeyAsWiF(params);

    callback.run();


    RequestorBtc.getUTXOListBch(wallet.currentReceiveAddress().toString(), new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example 24
Source Project: Android-Wallet-Token-ERC20   Source File: GetCredentials.java    License: Apache License 2.0 5 votes vote down vote up
public Credentials FromSeed(String seedCode,
                            String passwordWallet) throws UnreadableWalletException {
    DeterministicSeed seed = new DeterministicSeed(seedCode, null, passwordWallet, 1409478661L);
    DeterministicKeyChain chain = DeterministicKeyChain.builder().seed(seed).build();
    List<ChildNumber> keyPath = HDUtils.parsePath("M/44H/60H/0H/0/0");
    DeterministicKey key = chain.getKeyByPath(keyPath, true);
    BigInteger privKey = key.getPrivKey();
    return Credentials.create(ECKeyPair.create(privKey));
}
 
Example 25
Source Project: status-keycard   Source File: KeycardTest.java    License: Apache License 2.0 5 votes vote down vote up
private DeterministicKey deriveKey(KeyPair keyPair, byte[] chainCode, int[] path) {
  DeterministicKey key = HDKeyDerivation.createMasterPrivKeyFromBytes(((org.bouncycastle.jce.interfaces.ECPrivateKey) keyPair.getPrivate()).getD().toByteArray(), chainCode);

  for (int i : path) {
    key = HDKeyDerivation.deriveChildKey(key, new ChildNumber(i));
  }

  return key;
}
 
Example 26
@Override
public DeterministicKeyChain makeWatchingKeyChain(Protos.Key key, Protos.Key firstSubKey, DeterministicKey accountKey,
                                                  boolean isFollowingKey, boolean isMarried) throws UnreadableWalletException {
    ImmutableList<ChildNumber> accountPath = useBitcoinDeterministicKeyChain ? BtcDeterministicKeyChain.BIP44_BTC_ACCOUNT_PATH : BisqDeterministicKeyChain.BIP44_BSQ_ACCOUNT_PATH;
    if (!accountKey.getPath().equals(accountPath))
        throw new UnreadableWalletException("Expecting account key but found key with path: " +
                HDUtils.formatPath(accountKey.getPath()));
    return useBitcoinDeterministicKeyChain ? new BtcDeterministicKeyChain(accountKey, isFollowingKey) : new BisqDeterministicKeyChain(accountKey, isFollowingKey);
}
 
Example 27
@Override
protected SignatureAndKey getSignature(Sha256Hash sighash, List<ChildNumber> derivationPath) {
    ImmutableList<ChildNumber> keyPath = ImmutableList.copyOf(derivationPath);
    DeterministicKey key = keyChain.getKeyByPath(keyPath, true);
    return new SignatureAndKey(key.sign(sighash), key.dropPrivateBytes().dropParent());
}
 
Example 28
@Override
protected ImmutableList<ChildNumber> getAccountPath() {
    return BIP44_BSQ_ACCOUNT_PATH;
}
 
Example 29
@Override
protected ImmutableList<ChildNumber> getAccountPath() {
    return BIP44_BTC_ACCOUNT_PATH;
}
 
Example 30
public void createWallet2(String passphrase, Runnable callback) {

        wallet = new Wallet(params);
        DeterministicSeed seed = wallet.getKeyChainSeed();

        mnemonicKey = Joiner.on(" ").join(seed.getMnemonicCode());
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));

        walletFriendlyAddress = wallet.currentReceiveAddress().toString();

        ChildNumber childNumber = new ChildNumber(ChildNumber.HARDENED_BIT);
        DeterministicKey de = wallet.getKeyByPath(ImmutableList.of(childNumber));
        xprvKey = de.serializePrivB58(params);

        wifKey = wallet.currentReceiveKey().getPrivateKeyAsWiF(params);

        callback.run();
    }