Skip to content

Commit bdc2a65

Browse files
committed
tests: add test for KeyPair
Reuse existing bip340 test vectors.
1 parent 54b3c73 commit bdc2a65

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/test/key_tests.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,16 @@ BOOST_AUTO_TEST_CASE(bip340_test_vectors)
327327
// Verify those signatures for good measure.
328328
BOOST_CHECK(pubkey.VerifySchnorr(msg256, sig64));
329329

330+
// Repeat the same check, but use the KeyPair directly without any merkle tweak
331+
KeyPair keypair = key.ComputeKeyPair(/*merkle_root=*/nullptr);
332+
CKey keypair_seckey;
333+
BOOST_CHECK(keypair.GetKey(keypair_seckey));
334+
BOOST_CHECK(key == keypair_seckey);
335+
bool kp_ok = keypair.SignSchnorr(msg256, sig64, aux256);
336+
BOOST_CHECK(kp_ok);
337+
XOnlyPubKey keypair_xonly{keypair_seckey.GetPubKey()};
338+
BOOST_CHECK(keypair_xonly.VerifySchnorr(msg256, sig64));
339+
330340
// Do 10 iterations where we sign with a random Merkle root to tweak,
331341
// and compare against the resulting tweaked keys, with random aux.
332342
// In iteration i=0 we tweak with empty Merkle tree.
@@ -340,6 +350,16 @@ BOOST_AUTO_TEST_CASE(bip340_test_vectors)
340350
bool ok = key.SignSchnorr(msg256, sig64, &merkle_root, aux256);
341351
BOOST_CHECK(ok);
342352
BOOST_CHECK(tweaked_key.VerifySchnorr(msg256, sig64));
353+
354+
// Repeat the same check, but use the KeyPair class directly
355+
KeyPair keypair = key.ComputeKeyPair(&merkle_root);
356+
CKey keypair_seckey;
357+
BOOST_CHECK(keypair.GetKey(keypair_seckey));
358+
XOnlyPubKey keypair_xonly{keypair_seckey.GetPubKey()};
359+
BOOST_CHECK(tweaked_key == keypair_xonly);
360+
bool kp_ok = keypair.SignSchnorr(msg256, sig64, aux256);
361+
BOOST_CHECK(kp_ok);
362+
BOOST_CHECK(keypair_xonly.VerifySchnorr(msg256, sig64));
343363
}
344364
}
345365
}

0 commit comments

Comments
 (0)