use of org.bitcoinj.crypto.ChildNumber in project snowblossom by snowblossomcoin.
the class SeedTest method testVector.
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()));
}
use of org.bitcoinj.crypto.ChildNumber in project snowblossom by snowblossomcoin.
the class SeedTest method testGen.
private void testGen(int words) throws Exception {
String seed = SeedUtil.generateSeed(words);
List<String> lst = SeedUtil.getWordsFromSeed(seed);
Assert.assertEquals(words, lst.size());
ByteString seed_data = SeedUtil.decodeSeed(seed, "");
System.out.println("Seed: " + seed + " " + HexUtil.getHexString(seed_data));
DeterministicKey dk = HDKeyDerivation.createMasterPrivateKey(seed_data.toByteArray());
DeterministicHierarchy dh = new DeterministicHierarchy(dk);
System.out.println("Seed dk: " + dk.toString());
System.out.println("Seed ser: " + dk.serializePrivB58(org.bitcoinj.params.MainNetParams.get()));
DeterministicKey dk_acct = dh.get(ImmutableList.of(new ChildNumber(44, true), new ChildNumber(0, true), new ChildNumber(0, true)), true, true);
System.out.println("Seed ser: " + dk_acct.serializePubB58(org.bitcoinj.params.MainNetParams.get()));
System.out.println("Seed acct: " + dk_acct.toString());
System.out.println("Seed acct xprv: " + dk_acct.serializePrivB58(org.bitcoinj.params.MainNetParams.get()));
String xpub = SeedUtil.getSeedXpub(new NetworkParamsTestnet(), seed, "", 0);
for (int c = 0; c < 2; c++) for (int i = 0; i < 20; i++) {
WalletKeyPair wkp = SeedUtil.getKey(new NetworkParamsTestnet(), seed, "", 0, c, i);
System.out.println("Seed wkp: " + HexUtil.getHexString(wkp.getSeedId()) + " " + wkp.getHdPath());
Assert.assertTrue(wkp.getHdPath().startsWith("M/44H/2339H/0H/"));
Assert.assertTrue(wkp.getSeedId().size() == 20);
AddressSpecHash addr = AddressUtil.getHashForSpec(SeedUtil.getAddressSpec(new NetworkParamsTestnet(), xpub, c, i));
AddressSpecHash wkp_addr = AddressUtil.getHashForSpec(AddressUtil.getSimpleSpecForKey(wkp));
Assert.assertEquals(addr, wkp_addr);
testKeyPair(wkp, "hd");
}
ByteString seed_id_seed = SeedUtil.getSeedId(new NetworkParamsTestnet(), seed, "", 0);
ByteString seed_id_xpub = SeedUtil.getSeedIdFromXpub(xpub);
Assert.assertEquals(seed_id_seed, seed_id_xpub);
testSiteKey(seed);
}
use of org.bitcoinj.crypto.ChildNumber in project snowblossom by snowblossomcoin.
the class SeedUtil method getKey.
public static WalletKeyPair getKey(NetworkParams params, String seed_str, String pass, int account, int change, int index) {
ByteString seed = decodeSeed(seed_str, pass);
DeterministicKey dk = HDKeyDerivation.createMasterPrivateKey(seed.toByteArray());
DeterministicHierarchy dh = new DeterministicHierarchy(dk);
ByteString seed_id = getSeedId(params, seed_str, pass, 0);
DeterministicKey dk_addr = dh.get(ImmutableList.of(new ChildNumber(44, true), new ChildNumber(params.getBIP44CoinNumber(), true), new ChildNumber(account, true), new ChildNumber(change, false), new ChildNumber(index, false)), true, true);
return getKeyFromDeterministicKey(dk_addr, seed_id, change, index);
}
use of org.bitcoinj.crypto.ChildNumber in project snowblossom by snowblossomcoin.
the class SeedUtil method getSeedXpub.
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;
}
use of org.bitcoinj.crypto.ChildNumber in project opb-sdk-java by bianjieai.
the class Bip44Utils method parsePath.
private static List<ChildNumber> parsePath(String path) {
String[] parsedNodes = path.replace("m", "").split("/");
List<ChildNumber> nodes = new ArrayList<>();
for (String n : parsedNodes) {
n = n.replaceAll(" ", "");
if (n.length() == 0)
continue;
boolean isHard = n.endsWith("'");
if (isHard)
n = n.substring(0, n.length() - 1);
int nodeNumber = Integer.parseInt(n);
nodes.add(new ChildNumber(nodeNumber, isHard));
}
return nodes;
}
Aggregations