Author

Topic: Get adress from WIF private Key (Read 134 times)

hero member
Activity: 882
Merit: 5834
not your keys, not your coins!
November 29, 2021, 06:35:05 AM
#6
Thanks a lot.  My task turned out to be very successful Undecided

I am trying to generate these keys
https://keys.lol/bitcoin/1

and get the corresponding addresses. They all knock out a bug.

Maybe there is some way to hardcode and get these addresses without libraries?
Either remove that assertion which doesn't allow private key 1, which as @pooya87 said, is a bug anyway, or skip private key 1 and start with key 2 simply.
member
Activity: 96
Merit: 36
November 29, 2021, 01:47:07 AM
#5
Thanks a lot.  My task turned out to be very successful Undecided

I am trying to generate these keys
https://keys.lol/bitcoin/1

and get the corresponding addresses. They all knock out a bug.

Maybe there is some way to hardcode and get these addresses without libraries?
legendary
Activity: 3472
Merit: 10611
November 28, 2021, 11:22:44 PM
#4
We can see in the Java code that it doesn't permit private keys zero or one exactly because they're not allowed to be used:
It is worth mentioning that zero is an invalid bitcoin private key because it is outside the allowed private key range ([0,N)). But one is a perfectly valid private key and it is a bug in the library to reject it as invalid with an exception.
hero member
Activity: 882
Merit: 5834
not your keys, not your coins!
November 28, 2021, 10:17:46 PM
#3
According to the error message, I looked at the code and found this:

Code: (https://github.com/bitcoinj/bitcoinj/blob/31c7e5fbceb9884cb02d2dabc755009caa2d613e/core/src/main/java/org/bitcoinj/core/DumpedPrivateKey.java#L100)
public ECKey getKey() {
    return ECKey.fromPrivate(Arrays.copyOf(bytes, 32), isPubKeyCompressed());
}

So, you're calling getKey() just fine, but something breaks when this method calls ECKey.fromPrivate(...).
It seems to me that there's something wrong with bytes, so probably your initialization of dumpedPrivateKey is wrong. Might want to look into that a bit more.

Thanks to @larry_vw_1955, I think I got it.
that addresses corresponds to hex private key of 0x1.

We can see in the Java code that it doesn't permit private keys zero or one exactly because they're not allowed to be used:

Code: (https://github.com/bitcoinj/bitcoinj/blob/31c7e5fbceb9884cb02d2dabc755009caa2d613e/core/src/main/java/org/bitcoinj/core/ECKey.java#L193)
checkArgument(!priv.equals(BigInteger.ZERO));
checkArgument(!priv.equals(BigInteger.ONE));
sr. member
Activity: 1190
Merit: 469
November 28, 2021, 09:03:19 PM
#2
Java. bitcoinj


what am i doing wrong?

no idea about that but that addresses corresponds to hex private key of 0x1. cool. don't use that address because people knows about it alot. Grin
member
Activity: 96
Merit: 36
November 28, 2021, 03:32:45 PM
#1
Java. bitcoinj

i have private key

String str="5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf";

i try get compress and decompress. 2 adress. in this format :
1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm  1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH

i do

Quote
NetworkParameters params = MainNetParams.get();
      ECKey key;

      if (str.length() == 51 || str.length() == 52) {
          DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, str);
          key = dumpedPrivateKey.getKey();            //ERROR
      } else {
          BigInteger privKey = Base58.decodeToBigInteger(str);
          key = ECKey.fromPrivate(privKey);
      }
.
.
.


and
Quote
Exception in thread "main" java.lang.IllegalArgumentException
   at com.google.common.base.Preconditions.checkArgument(Preconditions.java:128)
   at org.bitcoinj.core.ECKey.(ECKey.java:195)
   at org.bitcoinj.core.ECKey.fromPrivate(ECKey.java:243)
   at org.bitcoinj.core.ECKey.fromPrivate(ECKey.java:259)
   at org.bitcoinj.core.DumpedPrivateKey.getKey(DumpedPrivateKey.java:101)
   at com.example.demo2.controllers.AdressFromKey.main(AdressFromKey.java:35)


what am i doing wrong?
Jump to: