mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Check private view key is a valid scalar.
This commit is contained in:
parent
e2b25c12e1
commit
165f2d000a
@ -131,7 +131,13 @@ public class WalletAddress {
|
||||
}
|
||||
|
||||
public boolean checkPrivateViewKey(String privateViewKey) {
|
||||
return arePubPrivKeysRelated(this.publicViewKeyHex, privateViewKey);
|
||||
return isPrivateKeyValid(privateViewKey) && arePubPrivKeysRelated(this.publicViewKeyHex, privateViewKey);
|
||||
}
|
||||
|
||||
public static boolean isPrivateKeyValid(String privateKey) {
|
||||
byte[] input = hexToBytes(privateKey);
|
||||
byte[] reduced = CryptoUtil.scReduce32(input);
|
||||
return Arrays.equals(input, reduced);
|
||||
}
|
||||
|
||||
public static boolean arePubPrivKeysRelated(String publicKey, String privateKey) {
|
||||
|
@ -66,5 +66,9 @@ public class WalletAddressTest {
|
||||
"0000111122223333444455556666777788889999AAAABBBBCCCCDDDDEEEEFFFF",
|
||||
"0000111122223333444455556666777788889999AAAABBBBCCCCDDDDEEEEFFFF"),
|
||||
false);
|
||||
|
||||
String nonReducedPrivateKey = "42594aba0e809490dec97b2dfaf64f7ae5bef1c2d19af636eb84544773df5b5f";
|
||||
assertEquals(WalletAddress.isPrivateKeyValid(nonReducedPrivateKey), false);
|
||||
assertEquals(WalletAddress.isPrivateKeyValid(privateViewKeyHex), true);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user