mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-03 10:46:42 +01:00
Remove Sign trait from ECPublicKey, move signing functionality into ECPrivateKey (#962)
This commit is contained in:
parent
713d76ae67
commit
aedc03bdfe
1 changed files with 11 additions and 23 deletions
|
@ -27,7 +27,12 @@ import scala.util.{Failure, Success, Try}
|
||||||
/**
|
/**
|
||||||
* Created by chris on 2/16/16.
|
* Created by chris on 2/16/16.
|
||||||
*/
|
*/
|
||||||
sealed abstract class BaseECKey extends NetworkElement with Sign {
|
sealed abstract class BaseECKey extends NetworkElement
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by chris on 2/16/16.
|
||||||
|
*/
|
||||||
|
sealed abstract class ECPrivateKey extends BaseECKey with Sign {
|
||||||
|
|
||||||
override def signFunction: ByteVector => Future[ECDigitalSignature] = {
|
override def signFunction: ByteVector => Future[ECDigitalSignature] = {
|
||||||
bytes =>
|
bytes =>
|
||||||
|
@ -38,25 +43,16 @@ sealed abstract class BaseECKey extends NetworkElement with Sign {
|
||||||
/**
|
/**
|
||||||
* Signs a given sequence of bytes with the signingKey
|
* Signs a given sequence of bytes with the signingKey
|
||||||
* @param dataToSign the bytes to be signed
|
* @param dataToSign the bytes to be signed
|
||||||
* @param signingKey the key to sign the bytes with
|
|
||||||
* @return the digital signature
|
* @return the digital signature
|
||||||
*/
|
*/
|
||||||
private def sign(
|
override def sign(dataToSign: ByteVector): ECDigitalSignature = {
|
||||||
dataToSign: ByteVector,
|
require(dataToSign.length == 32 && bytes.length <= 32)
|
||||||
signingKey: BaseECKey): ECDigitalSignature = {
|
|
||||||
require(dataToSign.length == 32 && signingKey.bytes.length <= 32)
|
|
||||||
val signature =
|
val signature =
|
||||||
NativeSecp256k1.sign(dataToSign.toArray, signingKey.bytes.toArray)
|
NativeSecp256k1.sign(dataToSign.toArray, bytes.toArray)
|
||||||
ECDigitalSignature(ByteVector(signature))
|
ECDigitalSignature(ByteVector(signature))
|
||||||
}
|
}
|
||||||
|
|
||||||
override def sign(dataToSign: ByteVector): ECDigitalSignature =
|
def sign(hash: HashDigest): ECDigitalSignature = sign(hash.bytes)
|
||||||
sign(dataToSign, this)
|
|
||||||
|
|
||||||
def sign(hash: HashDigest, signingKey: BaseECKey): ECDigitalSignature =
|
|
||||||
sign(hash.bytes, signingKey)
|
|
||||||
|
|
||||||
def sign(hash: HashDigest): ECDigitalSignature = sign(hash, this)
|
|
||||||
|
|
||||||
def signFuture(hash: HashDigest)(
|
def signFuture(hash: HashDigest)(
|
||||||
implicit ec: ExecutionContext): Future[ECDigitalSignature] =
|
implicit ec: ExecutionContext): Future[ECDigitalSignature] =
|
||||||
|
@ -84,13 +80,6 @@ sealed abstract class BaseECKey extends NetworkElement with Sign {
|
||||||
signatureLowS
|
signatureLowS
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by chris on 2/16/16.
|
|
||||||
*/
|
|
||||||
sealed abstract class ECPrivateKey extends BaseECKey {
|
|
||||||
|
|
||||||
/** Signifies if the this private key corresponds to a compressed public key */
|
/** Signifies if the this private key corresponds to a compressed public key */
|
||||||
def isCompressed: Boolean
|
def isCompressed: Boolean
|
||||||
|
|
||||||
|
@ -122,7 +111,7 @@ sealed abstract class ECPrivateKey extends BaseECKey {
|
||||||
Base58.encode(encodedPrivKey)
|
Base58.encode(encodedPrivKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
override def toString = "ECPrivateKey(" + hex + "," + isCompressed + ")"
|
override def toString = s"ECPrivateKey($hex,$isCompressed)"
|
||||||
}
|
}
|
||||||
|
|
||||||
object ECPrivateKey extends Factory[ECPrivateKey] {
|
object ECPrivateKey extends Factory[ECPrivateKey] {
|
||||||
|
@ -332,7 +321,6 @@ sealed abstract class ECPublicKey extends BaseECKey {
|
||||||
}
|
}
|
||||||
resultTry.getOrElse(false)
|
resultTry.getOrElse(false)
|
||||||
}
|
}
|
||||||
override def publicKey: ECPublicKey = this
|
|
||||||
|
|
||||||
/** Checks if the [[org.bitcoins.core.crypto.ECPublicKey ECPublicKey]] is compressed */
|
/** Checks if the [[org.bitcoins.core.crypto.ECPublicKey ECPublicKey]] is compressed */
|
||||||
def isCompressed: Boolean = bytes.size == 33
|
def isCompressed: Boolean = bytes.size == 33
|
||||||
|
|
Loading…
Add table
Reference in a new issue