Author

Topic: Trying to the I need help (Read 115 times)

member
Activity: 96
Merit: 36
September 18, 2021, 08:48:57 AM
#6
God bless you, dear friend. As soon as I have some merits, they are all will be yours. Very, very helpful. thanks a lot
legendary
Activity: 952
Merit: 1386
September 18, 2021, 08:19:47 AM
#5
Thanks a lot.
How can I integrate m / 84 '/ 0' / 0 '/ 0/0 into my code? I just need to get the first 5 addresses. I looked at your program, but there is a whole class forming a complex configuration. Too difficult for a beginner. How can I just hardcode the derivation path into my method?

Code:
public class Main {

    final static byte[] BITCOIN_SEED_BYTES = "Bitcoin seed".getBytes();
    final static byte[] SALT = "mnemonic".getBytes(StandardCharsets.UTF_8);

    public static void main(String[] args) throws IOException, MnemonicException, InterruptedException {       
        String seedCode = "tissue deliver beauty rare kind midnight focus indicate forum lawn this setup";
        byte[] seed = PBKDF2SHA512.derive(seedCode.getBytes(StandardCharsets.UTF_8), SALT, 2048, 64);
        DeterministicKey deterministicKey = createMasterPrivateKey(seed, createHmacSha512Digest());
        deterministicKey = HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(84, true));
        deterministicKey = HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(0, true));
        deterministicKey = HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(0, true));
        deterministicKey = HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(0, false));
        for (int i = 0; i <= 5; i++) {
            System.out.println(Address.fromKey(MainNetParams.get(), HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(i, false)), Script.ScriptType.P2WPKH));
        }
    }

    private static DeterministicKey createMasterPrivateKey(byte[] seed, HMac SHA512DIGEST) throws HDDerivationException {
        byte[] i = hmacSha512(SHA512DIGEST, seed);
        byte[] il = Arrays.copyOfRange(i, 0, 32);
        byte[] ir = Arrays.copyOfRange(i, 32, 64);
        Arrays.fill(i, (byte)0);
        DeterministicKey masterPrivKey = HDKeyDerivation.createMasterPrivKeyFromBytes(il, ir);
        Arrays.fill(il, (byte)0);
        Arrays.fill(ir, (byte)0);
        masterPrivKey.setCreationTimeSeconds(System.currentTimeMillis());
        return masterPrivKey;
    }

    private static byte[] hmacSha512(HMac hmacSha512, byte[] input) {
        hmacSha512.reset();
        hmacSha512.update(input, 0, input.length);
        byte[] out = new byte[64];
        hmacSha512.doFinal(out, 0);
        return out;
    }

    private static HMac createHmacSha512Digest() {
        SHA512Digest digest = new SHA512Digest();
        HMac hMac = new HMac(digest);
        hMac.init(new KeyParameter(BITCOIN_SEED_BYTES));
        return hMac;
    }
}
member
Activity: 96
Merit: 36
September 18, 2021, 06:27:40 AM
#4
Wrong derivation path for a child key. For bc1q0u... you need to use m/84'/0'/0'/0/0.
Take a look at my program https://github.com/PawelGorny/lostword, you may launch it with configuration:
Code:
KNOWN_POSITION
bc1q0u3r6fp8mctx45e75f6p4suzja68alcxkc4cje
12
tissue
deliver
beauty
rare
kind
midnight
focus
indicate
forum
lawn
this
?
m/84'/0'/0'/0/0

Thanks a lot.
How can I integrate m / 84 '/ 0' / 0 '/ 0/0 into my code? I just need to get the first 5 addresses. I looked at your program, but there is a whole class forming a complex configuration. Too difficult for a beginner. How can I just hardcode the derivation path into my method?
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
September 18, 2021, 06:00:58 AM
#3
Also you'll probably want to discard that seed that you used for testing above, now that it has been posted in the open and web crawlers have archived it.
legendary
Activity: 952
Merit: 1386
September 18, 2021, 03:17:52 AM
#2
Wrong derivation path for a child key. For bc1q0u... you need to use m/84'/0'/0'/0/0.
Take a look at my program https://github.com/PawelGorny/lostword, you may launch it with configuration:
Code:
KNOWN_POSITION
bc1q0u3r6fp8mctx45e75f6p4suzja68alcxkc4cje
12
tissue
deliver
beauty
rare
kind
midnight
focus
indicate
forum
lawn
this
?
m/84'/0'/0'/0/0
member
Activity: 96
Merit: 36
September 18, 2021, 03:00:01 AM
#1
I do
Quote
   NetworkParameters params = MainNetParams.get();
      String sedCode = "tissue deliver beauty rare kind midnight focus indicate forum lawn this setup";
      DeterministicSed sed;
      try {
         sed = new DeterministicSed(Code, null, "", 0L);
         Wallet wallet = Wallet.fromSed(params, sed);
         List keys = new ArrayList<>(5);
         for (int i = 0; i < 5; i++) {
            ECKey key = freshReceiveKey();
            e[] publickeyhash = key.getPubKeyHash();
            SegwitAddress Address = SegwitAddress(MainNetParams.get(), publickey);
            keys.add(segwitAddress.toBech32());
         }
         for (String key : keys) {
            System.out.println(key);
         }
......
I get
Quote
bc1qt9w4uxna2gdmscc67enj8azrld92msq6v87aty

but
gives me
Quote
bc1q0u3r6fp8mctx45e75f6p4suzja68alcxkc4cje   

what am I doing wrong?

I will be very grateful for any help  Smiley
Jump to: