mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-01-18 21:34:39 +01:00
Introduced AsyncAdaptorSign and AdaptorSign traits (#3037)
This commit is contained in:
parent
aacba1c077
commit
63a6f9309d
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 = {
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user