mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-11-02 18:26:43 +00:00
add message sign test for low r grinding (verified signatures against electrum 4.1.2)
This commit is contained in:
parent
173743ba0d
commit
f4730f7147
1 changed files with 37 additions and 0 deletions
37
src/test/java/com/sparrowwallet/drongo/crypto/ECKeyTest.java
Normal file
37
src/test/java/com/sparrowwallet/drongo/crypto/ECKeyTest.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
package com.sparrowwallet.drongo.crypto;
|
||||
|
||||
import com.sparrowwallet.drongo.KeyPurpose;
|
||||
import com.sparrowwallet.drongo.address.Address;
|
||||
import com.sparrowwallet.drongo.policy.Policy;
|
||||
import com.sparrowwallet.drongo.policy.PolicyType;
|
||||
import com.sparrowwallet.drongo.protocol.ScriptType;
|
||||
import com.sparrowwallet.drongo.wallet.*;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ECKeyTest {
|
||||
@Test
|
||||
public void testGrindLowR() throws MnemonicException {
|
||||
String words = "absent essay fox snake vast pumpkin height crouch silent bulb excuse razor";
|
||||
DeterministicSeed seed = new DeterministicSeed(words, "", 0, DeterministicSeed.Type.BIP39);
|
||||
Wallet wallet = new Wallet();
|
||||
wallet.setPolicyType(PolicyType.SINGLE);
|
||||
wallet.setScriptType(ScriptType.P2PKH);
|
||||
Keystore keystore = Keystore.fromSeed(seed, wallet.getScriptType().getDefaultDerivation());
|
||||
wallet.getKeystores().add(keystore);
|
||||
wallet.setDefaultPolicy(Policy.getPolicy(PolicyType.SINGLE, ScriptType.P2PKH, wallet.getKeystores(), 1));
|
||||
|
||||
WalletNode firstReceive = wallet.getNode(KeyPurpose.RECEIVE).getChildren().iterator().next();
|
||||
Address address = wallet.getAddress(firstReceive);
|
||||
Assert.assertEquals("14JmU9a7SzieZNEtBnsZo688rt3mGrw6hr", address.toString());
|
||||
ECKey privKey = keystore.getKey(firstReceive);
|
||||
|
||||
//2 attempts required for low R
|
||||
String signature = privKey.signMessage("Test", ScriptType.P2PKH, null);
|
||||
Assert.assertEquals("IDgMx1ljPhLHlKUOwnO/jBIgK+K8n8mvDUDROzTgU8gOaPDMs+eYXJpNXXINUx5WpeV605p5uO6B3TzBVcvs478=", signature);
|
||||
|
||||
//3 attempts required for low R
|
||||
String signature2 = privKey.signMessage("Test1", ScriptType.P2PKH, null);
|
||||
Assert.assertEquals("IEt/v9K95YVFuRtRtWaabPVwWOFv1FSA/e874I8ABgYMbRyVvHhSwLFz0RZuO87ukxDd4TOsRdofQwMEA90LCgI=", signature2);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue