Introduced AsyncAdaptorSign and AdaptorSign traits (#3037)

This commit is contained in:
Nadav Kohen 2021-05-05 09:34:03 -05:00 committed by GitHub
parent aacba1c077
commit 63a6f9309d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 14 deletions

View File

@ -234,6 +234,13 @@ sealed abstract class ExtPrivateKey
key.signWithEntropy(bytes, entropy)
}
override def adaptorSign(
adaptorPoint: ECPublicKey,
msg: ByteVector,
auxRand: ByteVector): ECAdaptorSignature = {
key.adaptorSign(adaptorPoint, msg, auxRand)
}
/** Signs the given bytes with the given [[BIP32Path path]] */
override def deriveAndSign(
bytes: ByteVector,

View File

@ -1,13 +1,13 @@
package org.bitcoins.core.crypto
import org.bitcoins.core.hd.BIP32Path
import org.bitcoins.crypto.{AsyncSign, ECDigitalSignature, Sign}
import org.bitcoins.crypto.{AdaptorSign, AsyncAdaptorSign, ECDigitalSignature}
import scodec.bits.ByteVector
import scala.concurrent.Future
/** A signing interface for [[ExtKey]] */
trait AsyncExtSign extends AsyncSign {
trait AsyncExtSign extends AsyncAdaptorSign {
def asyncDeriveAndSign(
bytes: ByteVector,
@ -21,7 +21,7 @@ trait AsyncExtSign extends AsyncSign {
}
}
trait ExtSign extends AsyncExtSign with Sign {
trait ExtSign extends AsyncExtSign with AdaptorSign {
def deriveAndSign(bytes: ByteVector, path: BIP32Path): ECDigitalSignature

View File

@ -14,7 +14,7 @@ sealed abstract class BaseECKey extends NetworkElement
*/
sealed abstract class ECPrivateKey
extends BaseECKey
with Sign
with AdaptorSign
with MaskedToString {
/** Signs a given sequence of bytes with the signingKey
@ -50,14 +50,7 @@ sealed abstract class ECPrivateKey
CryptoUtil.schnorrSignWithNonce(dataToSign, this, nonce)
}
def adaptorSign(
adaptorPoint: ECPublicKey,
msg: ByteVector): ECAdaptorSignature = {
val auxRand = ECPrivateKey.freshPrivateKey.bytes
adaptorSign(adaptorPoint, msg, auxRand)
}
def adaptorSign(
override def adaptorSign(
adaptorPoint: ECPublicKey,
msg: ByteVector,
auxRand: ByteVector): ECAdaptorSignature = {

View File

@ -107,6 +107,21 @@ object AsyncSign {
}
}
trait AsyncAdaptorSign extends AsyncSign {
def asyncAdaptorSign(
adaptorPoint: ECPublicKey,
msg: ByteVector,
auxRand: ByteVector): Future[ECAdaptorSignature]
def asyncAdaptorSign(
adaptorPoint: ECPublicKey,
msg: ByteVector): Future[ECAdaptorSignature] = {
val auxRand = ECPrivateKey.freshPrivateKey.bytes
asyncAdaptorSign(adaptorPoint, msg, auxRand)
}
}
trait Sign extends AsyncSign {
def sign(bytes: ByteVector): ECDigitalSignature
@ -198,3 +213,25 @@ object Sign {
constant(EmptyDigitalSignature, publicKey)
}
}
trait AdaptorSign extends Sign with AsyncAdaptorSign {
def adaptorSign(
adaptorPoint: ECPublicKey,
msg: ByteVector,
auxRand: ByteVector): ECAdaptorSignature
def adaptorSign(
adaptorPoint: ECPublicKey,
msg: ByteVector): ECAdaptorSignature = {
val auxRand = ECPrivateKey.freshPrivateKey.bytes
adaptorSign(adaptorPoint, msg, auxRand)
}
override def asyncAdaptorSign(
adaptorPoint: ECPublicKey,
msg: ByteVector,
auxRand: ByteVector): Future[ECAdaptorSignature] = {
Future.successful(adaptorSign(adaptorPoint, msg, auxRand))
}
}

View File

@ -15,7 +15,7 @@ import org.bitcoins.core.wallet.keymanagement.{
KeyManagerInitializeError,
KeyManagerParams
}
import org.bitcoins.crypto.{AesPassword, Sign}
import org.bitcoins.crypto.{AdaptorSign, AesPassword}
import org.bitcoins.keymanager._
import scodec.bits.BitVector
@ -50,7 +50,7 @@ class BIP39KeyManager(
/** Converts a non-sensitive DB representation of a UTXO into
* a signable (and sensitive) real-world UTXO
*/
def toSign(privKeyPath: HDPath): Sign = {
def toSign(privKeyPath: HDPath): AdaptorSign = {
val xpriv =
rootExtPrivKey.deriveChildPrivKey(privKeyPath)