SegwitAddress: Allow only compressed keys in fromKey().
package org.bitcoinj.core;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+
import java.io.ByteArrayOutputStream;
import javax.annotation.Nullable;
@@ -24,8 +27,6 @@ import org.bitcoinj.params.Networks;
import org.bitcoinj.script.Script;
import org.bitcoinj.script.Script.ScriptType;
-import static com.google.common.base.Preconditions.checkState;
-
/**
* <p>Implementation of native segwit addresses. They are composed of two parts:</p>
*
@@ -202,6 +203,7 @@ public class SegwitAddress extends Address {
* @return constructed address
*/
public static SegwitAddress fromKey(NetworkParameters params, ECKey key) {
+ checkArgument(key.isCompressed(), "only compressed keys allowed");
return fromHash(params, key.getPubKeyHash());
}
