mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-24 23:08:31 +01:00
Implementing public key derivation for both compressed and uncompressed public keys
This commit is contained in:
parent
32109fba4d
commit
486d652814
2 changed files with 5 additions and 5 deletions
|
@ -153,7 +153,7 @@ public class NativeSecp256k1 {
|
||||||
* @param pubkey ECDSA Public key, 33 or 65 bytes
|
* @param pubkey ECDSA Public key, 33 or 65 bytes
|
||||||
*/
|
*/
|
||||||
//TODO add a 'compressed' arg
|
//TODO add a 'compressed' arg
|
||||||
public static byte[] computePubkey(byte[] seckey) throws AssertFailException{
|
public static byte[] computePubkey(byte[] seckey, boolean fCompressed) throws AssertFailException{
|
||||||
checkInvariant(seckey.length == 32);
|
checkInvariant(seckey.length == 32);
|
||||||
|
|
||||||
ByteBuffer byteBuff = nativeECDSABuffer.get();
|
ByteBuffer byteBuff = nativeECDSABuffer.get();
|
||||||
|
@ -169,7 +169,7 @@ public class NativeSecp256k1 {
|
||||||
|
|
||||||
r.lock();
|
r.lock();
|
||||||
try {
|
try {
|
||||||
retByteArray = secp256k1_ec_pubkey_create(byteBuff, Secp256k1Context.getContext());
|
retByteArray = secp256k1_ec_pubkey_create(byteBuff, Secp256k1Context.getContext(), fCompressed);
|
||||||
} finally {
|
} finally {
|
||||||
r.unlock();
|
r.unlock();
|
||||||
}
|
}
|
||||||
|
@ -440,7 +440,7 @@ public class NativeSecp256k1 {
|
||||||
|
|
||||||
private static native int secp256k1_ec_seckey_verify(ByteBuffer byteBuff, long context);
|
private static native int secp256k1_ec_seckey_verify(ByteBuffer byteBuff, long context);
|
||||||
|
|
||||||
private static native byte[][] secp256k1_ec_pubkey_create(ByteBuffer byteBuff, long context);
|
private static native byte[][] secp256k1_ec_pubkey_create(ByteBuffer byteBuff, long context, boolean fCompressed);
|
||||||
|
|
||||||
private static native byte[][] secp256k1_ec_pubkey_parse(ByteBuffer byteBuff, long context, int inputLen);
|
private static native byte[][] secp256k1_ec_pubkey_parse(ByteBuffer byteBuff, long context, int inputLen);
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class NativeSecp256k1Test {
|
||||||
public void testPubKeyCreatePos() throws AssertFailException{
|
public void testPubKeyCreatePos() throws AssertFailException{
|
||||||
byte[] sec = BaseEncoding.base16().lowerCase().decode("67E56582298859DDAE725F972992A07C6C4FB9F62A8FFF58CE3CA926A1063530".toLowerCase());
|
byte[] sec = BaseEncoding.base16().lowerCase().decode("67E56582298859DDAE725F972992A07C6C4FB9F62A8FFF58CE3CA926A1063530".toLowerCase());
|
||||||
|
|
||||||
byte[] resultArr = NativeSecp256k1.computePubkey( sec);
|
byte[] resultArr = NativeSecp256k1.computePubkey( sec, true);
|
||||||
String pubkeyString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
|
String pubkeyString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
|
||||||
assertEquals( pubkeyString , "02C591A8FF19AC9C4E4E5793673B83123437E975285E7B442F4EE2654DFFCA5E2D" , "testPubKeyCreatePos");
|
assertEquals( pubkeyString , "02C591A8FF19AC9C4E4E5793673B83123437E975285E7B442F4EE2654DFFCA5E2D" , "testPubKeyCreatePos");
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ public class NativeSecp256k1Test {
|
||||||
public void testPubKeyCreateNeg() throws AssertFailException{
|
public void testPubKeyCreateNeg() throws AssertFailException{
|
||||||
byte[] sec = BaseEncoding.base16().lowerCase().decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".toLowerCase());
|
byte[] sec = BaseEncoding.base16().lowerCase().decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".toLowerCase());
|
||||||
|
|
||||||
byte[] resultArr = NativeSecp256k1.computePubkey( sec);
|
byte[] resultArr = NativeSecp256k1.computePubkey( sec, true);
|
||||||
String pubkeyString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
|
String pubkeyString = javax.xml.bind.DatatypeConverter.printHexBinary(resultArr);
|
||||||
assertEquals( pubkeyString, "" , "testPubKeyCreateNeg");
|
assertEquals( pubkeyString, "" , "testPubKeyCreateNeg");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue