Status: New
Owner: ----
Labels: Type-Enhancement Priority-Medium
New issue 264 by n.e.baughman: ECKey constructor allows bogus key creation
http://code.google.com/p/bitcoinj/issues/detail?id=264
bitcoinj-0.6
The ECKey(byte[] privKeyBytes, byte[] pubKey) constructor is misleading.
The API docs explain that "The public key will be automatically derived
from the private key." However, providing a zero-length pubKey argument
results in an ECKey with a bogus (but valid-looking) public key.
new ECKey(privKeyBytes, new byte[0]).toAddress() yields an address
of "1HT7xU2Ngenf7D4yocz2SAcnNLW7rK8d4E" which is a known bogus address.
Google search yields:
https://bitcointalk.org/index.php?topic=8728.25;wap2
"... (an address derived from pubkey of length 0 which cannot exist)."
Minimally, the API docs should be made clear that the constructor blindly
accepts the values given.
Notice that the documented behavior is impossible without the
NetworkParameters (needed to derive the public key), so a privKeyBytes-only
constructor is not possible. Consider a static method, such as:
ECKey.create(byte[] privKeyBytes, NetworkParameters params)