Now use secp256k1's verify functionality for verifying digital signatures

This commit is contained in:
Chris Stewart 2017-02-20 12:27:09 -06:00
parent 0030b9612f
commit 09b07d96ab
2 changed files with 12 additions and 12 deletions

View File

@ -86,7 +86,9 @@ public class NativeSecp256k1 {
* @param sig byte array of signature
*/
public static byte[] sign(byte[] data, byte[] sec) throws AssertFailException{
checkInvariant(data.length == 32 && sec.length <= 32);
checkInvariant(data != null);
checkInvariant(data.length == 32);
checkInvariant(sec.length <= 32);
ByteBuffer byteBuff = nativeECDSABuffer.get();
if (byteBuff == null || byteBuff.capacity() < 32 + 32) {

View File

@ -6,16 +6,10 @@ import org.bitcoins.core.util.{Factory, BitcoinSUtil}
* Created by chris on 5/24/16.
*/
sealed trait HashDigest {
/**
* The message digest represented in bytes
* @return
*/
/** The message digest represented in bytes */
def bytes : Seq[Byte]
/**
* The message digest represented in hexadecimal
* @return
*/
/** The message digest represented in hexadecimal */
def hex : String = BitcoinSUtil.encodeHex(bytes)
}
@ -39,6 +33,7 @@ sealed trait Sha256Digest extends HashDigest
object Sha256Digest extends Factory[Sha256Digest] {
private case class Sha256DigestImpl(bytes: Seq[Byte]) extends Sha256Digest {
require(bytes.length == 32, "Sha256Digest must be 32 bytes in size, got: " + bytes.length)
override def toString = "Sha256DigestImpl(" + hex + ")"
}
override def fromBytes(bytes:Seq[Byte]) : Sha256Digest = Sha256DigestImpl(bytes)
@ -51,6 +46,7 @@ sealed trait DoubleSha256Digest extends HashDigest
object DoubleSha256Digest extends Factory[DoubleSha256Digest] {
private case class DoubleSha256DigestImpl(bytes: Seq[Byte]) extends DoubleSha256Digest {
require(bytes.length == 32, "DoubleSha256Digest must always be 32 bytes, got: " + bytes.length)
override def toString = "DoubleSha256DigestImpl(" + hex + ")"
}
override def fromBytes(bytes : Seq[Byte]) : DoubleSha256Digest = DoubleSha256DigestImpl(bytes)
@ -64,19 +60,21 @@ sealed trait RipeMd160Digest extends HashDigest
object RipeMd160Digest extends Factory[RipeMd160Digest] {
private case class RipeMd160DigestImpl(bytes : Seq[Byte]) extends RipeMd160Digest {
require(bytes.length == 20, "RIPEMD160Digest must always be 20 bytes, got: " + bytes.length)
override def toString = "RipeMd160DigestImpl(" + hex + ")"
}
override def fromBytes(bytes : Seq[Byte]) : RipeMd160Digest = RipeMd160DigestImpl(bytes)
}
/**
* Represents the result of RIPEMD160(SHA256())
*/
sealed trait Sha256Hash160Digest extends HashDigest
object Sha256Hash160Digest extends Factory[Sha256Hash160Digest] {
case class Sha256Hash160DigestImpl(bytes : Seq[Byte]) extends Sha256Hash160Digest {
private case class Sha256Hash160DigestImpl(bytes : Seq[Byte]) extends Sha256Hash160Digest {
require(bytes.length == 20, "Sha256Hash160Digest must always be 20 bytes, got: " + bytes.length)
override def toString = "Sha256Hash160DigestImpl(" + hex + ")"
}
override def fromBytes(bytes : Seq[Byte]) = Sha256Hash160DigestImpl(bytes)
override def fromBytes(bytes : Seq[Byte]): Sha256Hash160Digest = Sha256Hash160DigestImpl(bytes)
}