mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-03 18:47:38 +01:00
Update DLC Oracle Signing Algo (#2465)
This commit is contained in:
parent
b436f6cd2f
commit
be06fb13ab
4 changed files with 40 additions and 7 deletions
|
@ -72,9 +72,39 @@ object SigningVersion extends StringFactory[SigningVersion] {
|
|||
}
|
||||
}
|
||||
|
||||
val latest: SigningVersion = BasicSHA256SigningVersion
|
||||
/** V0 DLC Oracle singing algo, specified in https://github.com/discreetlogcontracts/dlcspecs/pull/113 */
|
||||
final case object DLCOracleV0SigningVersion extends SigningVersion {
|
||||
|
||||
val all: Vector[SigningVersion] = Vector(Mock, BasicSHA256SigningVersion)
|
||||
override def calcNonceTweak(
|
||||
nonce: SchnorrNonce,
|
||||
eventName: String): ByteVector = {
|
||||
val bytes = nonce.bytes ++ CryptoUtil.serializeForHash(eventName)
|
||||
|
||||
CryptoUtil.taggedSha256(bytes, "DLC/oracle/nonce/v0").bytes
|
||||
}
|
||||
|
||||
override def calcAnnouncementHash(eventTLV: OracleEventTLV): ByteVector =
|
||||
CryptoUtil
|
||||
.taggedSha256(eventTLV.bytes, "DLC/oracle/announcement/v0")
|
||||
.bytes
|
||||
|
||||
override def calcOutcomeHash(
|
||||
descriptor: EventDescriptorTLV,
|
||||
byteVector: ByteVector): ByteVector = {
|
||||
descriptor match {
|
||||
case _: EnumEventDescriptorV0TLV | _: RangeEventDescriptorV0TLV |
|
||||
_: DigitDecompositionEventDescriptorV0TLV =>
|
||||
CryptoUtil
|
||||
.taggedSha256(byteVector, "DLC/oracle/attestation/v0")
|
||||
.bytes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val latest: SigningVersion = DLCOracleV0SigningVersion
|
||||
|
||||
val all: Vector[SigningVersion] =
|
||||
Vector(Mock, BasicSHA256SigningVersion, DLCOracleV0SigningVersion)
|
||||
|
||||
override def fromStringOpt(str: String): Option[SigningVersion] = {
|
||||
all.find(state => str.toLowerCase() == state.toString.toLowerCase)
|
||||
|
|
|
@ -777,8 +777,11 @@ case class OracleAnnouncementV0TLV(
|
|||
announcementSignature.bytes ++ publicKey.bytes ++ eventTLV.bytes
|
||||
|
||||
override def validateSignature: Boolean = {
|
||||
publicKey.verify(CryptoUtil.sha256(eventTLV.bytes).bytes,
|
||||
announcementSignature)
|
||||
publicKey.verify(
|
||||
CryptoUtil
|
||||
.taggedSha256(eventTLV.bytes, "DLC/oracle/announcement/v0")
|
||||
.bytes,
|
||||
announcementSignature)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ class AttestationVerificationTest extends BitcoinSUnitTest {
|
|||
|
||||
behavior of "AttestationVerification"
|
||||
|
||||
val signingVersion = SigningVersion.latest
|
||||
val signingVersion = SigningVersion.BasicSHA256SigningVersion
|
||||
|
||||
val enumTlv = OracleAnnouncementV0TLV.fromHex(
|
||||
"""fdd824a350a5f6214e14574bc925a9d5d211961a8e4e9ed8d3cb8dbc7c65d8da767152759e7d8d7646ded432717c8a4616a8fac714
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.typesafe.config.Config
|
|||
import org.bitcoins.core.config.NetworkParameters
|
||||
import org.bitcoins.core.crypto.ExtKeyVersion.SegWitMainNetPriv
|
||||
import org.bitcoins.core.hd.HDPurpose
|
||||
import org.bitcoins.core.protocol.tlv.EventDescriptorTLV
|
||||
import org.bitcoins.core.protocol.tlv.EnumEventDescriptorV0TLV
|
||||
import org.bitcoins.core.util.FutureUtil
|
||||
import org.bitcoins.core.wallet.keymanagement.KeyManagerParams
|
||||
import org.bitcoins.crypto.AesPassword
|
||||
|
@ -65,7 +65,7 @@ case class DLCOracleAppConfig(
|
|||
if (migrations == 2 || migrations == 3) { // For V2/V3 migrations
|
||||
logger.debug(s"Doing V2/V3 Migration")
|
||||
|
||||
val dummyMigrationTLV = EventDescriptorTLV("fdd8060800010564756d6d79")
|
||||
val dummyMigrationTLV = EnumEventDescriptorV0TLV.dummy
|
||||
|
||||
val eventDAO = EventDAO()(ec, appConfig)
|
||||
for {
|
||||
|
|
Loading…
Add table
Reference in a new issue