|
1 | 1 | package fr.acinq.bitcoin.crypto.musig2 |
2 | 2 |
|
3 | 3 | import fr.acinq.bitcoin.* |
4 | | -import fr.acinq.bitcoin.reference.TransactionTestsCommon |
5 | 4 | import fr.acinq.secp256k1.Hex |
6 | 5 | import kotlinx.serialization.json.* |
7 | 6 | import kotlin.random.Random |
@@ -83,6 +82,13 @@ class Musig2TestsCommon { |
83 | 82 | } |
84 | 83 | } |
85 | 84 |
|
| 85 | + @Test |
| 86 | + fun `generate secret nonce from counter`() { |
| 87 | + val privateKey = PrivateKey.fromHex("EEC1CB7D1B7254C5CAB0D9C61AB02E643D464A59FE6C96A7EFE871F07C5AEF54") |
| 88 | + val nonce = SecretNonce.generateWithCounter(0UL, privateKey, null, null, null) |
| 89 | + assertEquals(ByteVector.fromHex("03A5B9B6907942EACDDA49A366016EC2E62404A1BF4AB6D4DB82067BC3ADF086D7033205DB9EB34D5C7CE02848CAC68A83ED73E3883477F563F23CE9A11A7721EC64"), nonce.second.data) |
| 90 | + } |
| 91 | + |
86 | 92 | @Test |
87 | 93 | fun `aggregate nonces`() { |
88 | 94 | val tests = TestHelpers.readResourceAsJson("musig2/nonce_agg_vectors.json") |
@@ -301,11 +307,11 @@ class Musig2TestsCommon { |
301 | 307 |
|
302 | 308 | val aliceSig = Musig2.signTaprootInput(alicePrivKey, spendingTx, 0, listOf(tx.txOut[0]), listOf(alicePubKey, bobPubKey), aliceNonce.first, publicNonces, scriptTree = null).right |
303 | 309 | assertNotNull(aliceSig) |
304 | | - assertTrue(Musig2.verifyTaprootSignature(aliceSig, aliceNonce.second, alicePubKey, spendingTx, 0, listOf(tx.txOut[0]), listOf(alicePubKey, bobPubKey), publicNonces, scriptTree = null)) |
| 310 | + assertTrue(Musig2.verify(aliceSig, aliceNonce.second, alicePubKey, spendingTx, 0, listOf(tx.txOut[0]), listOf(alicePubKey, bobPubKey), publicNonces, scriptTree = null)) |
305 | 311 |
|
306 | 312 | val bobSig = Musig2.signTaprootInput(bobPrivKey, spendingTx, 0, listOf(tx.txOut[0]), listOf(alicePubKey, bobPubKey), bobNonce.first, publicNonces, scriptTree = null).right |
307 | 313 | assertNotNull(bobSig) |
308 | | - assertTrue(Musig2.verifyTaprootSignature(bobSig, bobNonce.second, bobPubKey, spendingTx, 0, listOf(tx.txOut[0]), listOf(alicePubKey, bobPubKey), publicNonces, scriptTree = null)) |
| 314 | + assertTrue(Musig2.verify(bobSig, bobNonce.second, bobPubKey, spendingTx, 0, listOf(tx.txOut[0]), listOf(alicePubKey, bobPubKey), publicNonces, scriptTree = null)) |
309 | 315 |
|
310 | 316 | // Once they have each other's partial signature, they can aggregate them into a valid signature. |
311 | 317 | val aggregateSig = Musig2.aggregateTaprootSignatures(listOf(aliceSig, bobSig), spendingTx, 0, listOf(tx.txOut[0]), listOf(alicePubKey, bobPubKey), publicNonces, scriptTree = null).right |
@@ -359,11 +365,11 @@ class Musig2TestsCommon { |
359 | 365 | val publicNonces = listOf(userNonce.second, serverNonce.second) |
360 | 366 | val userSig = Musig2.signTaprootInput(userPrivateKey, tx, 0, swapInTx.txOut, listOf(userPublicKey, serverPublicKey), userNonce.first, publicNonces, scriptTree).right |
361 | 367 | assertNotNull(userSig) |
362 | | - assertTrue(Musig2.verifyTaprootSignature(userSig, userNonce.second, userPublicKey, tx, 0, swapInTx.txOut, listOf(userPublicKey, serverPublicKey), publicNonces, scriptTree)) |
| 368 | + assertTrue(Musig2.verify(userSig, userNonce.second, userPublicKey, tx, 0, swapInTx.txOut, listOf(userPublicKey, serverPublicKey), publicNonces, scriptTree)) |
363 | 369 |
|
364 | 370 | val serverSig = Musig2.signTaprootInput(serverPrivateKey, tx, 0, swapInTx.txOut, listOf(userPublicKey, serverPublicKey), serverNonce.first, publicNonces, scriptTree).right |
365 | 371 | assertNotNull(serverSig) |
366 | | - assertTrue(Musig2.verifyTaprootSignature(serverSig, serverNonce.second, serverPublicKey, tx, 0, swapInTx.txOut, listOf(userPublicKey, serverPublicKey), publicNonces, scriptTree)) |
| 372 | + assertTrue(Musig2.verify(serverSig, serverNonce.second, serverPublicKey, tx, 0, swapInTx.txOut, listOf(userPublicKey, serverPublicKey), publicNonces, scriptTree)) |
367 | 373 |
|
368 | 374 | // Once they have each other's partial signature, they can aggregate them into a valid signature. |
369 | 375 | val aggregateSig = Musig2.aggregateTaprootSignatures(listOf(userSig, serverSig), tx, 0, swapInTx.txOut, listOf(userPublicKey, serverPublicKey), publicNonces, scriptTree).right |
|
0 commit comments