3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-14 19:25:51 +00:00

SegwitAddress: Allow only compressed keys in fromKey().

This commit is contained in:
Andreas Schildbach 2019-02-04 11:55:54 +01:00
parent 4c60984e14
commit 480150f87f

View File

@ -16,6 +16,9 @@
package org.bitcoinj.core; 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 java.io.ByteArrayOutputStream;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -24,8 +27,6 @@ import org.bitcoinj.params.Networks;
import org.bitcoinj.script.Script; import org.bitcoinj.script.Script;
import org.bitcoinj.script.Script.ScriptType; 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> * <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 * @return constructed address
*/ */
public static SegwitAddress fromKey(NetworkParameters params, ECKey key) { public static SegwitAddress fromKey(NetworkParameters params, ECKey key) {
checkArgument(key.isCompressed(), "only compressed keys allowed");
return fromHash(params, key.getPubKeyHash()); return fromHash(params, key.getPubKeyHash());
} }