Skip to content

Commit aae432a

Browse files
dhruvPieter Wuille
authored andcommitted
Unit test for ellswift creation/decoding roundtrip
Co-authored-by: Pieter Wuille <[email protected]>
1 parent eff72a0 commit aae432a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/test/key_tests.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,24 @@ BOOST_AUTO_TEST_CASE(bip340_test_vectors)
344344
}
345345
}
346346

347+
BOOST_AUTO_TEST_CASE(key_ellswift)
348+
{
349+
for (const auto& secret : {strSecret1, strSecret2, strSecret1C, strSecret2C}) {
350+
CKey key = DecodeSecret(secret);
351+
BOOST_CHECK(key.IsValid());
352+
353+
uint256 ent32 = InsecureRand256();
354+
auto ellswift = key.EllSwiftCreate(AsBytes(Span{ent32}));
355+
356+
CPubKey decoded_pubkey = ellswift.Decode();
357+
if (!key.IsCompressed()) {
358+
// The decoding constructor returns a compressed pubkey. If the
359+
// original was uncompressed, we must decompress the decoded one
360+
// to compare.
361+
decoded_pubkey.Decompress();
362+
}
363+
BOOST_CHECK(key.GetPubKey() == decoded_pubkey);
364+
}
365+
}
366+
347367
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)