Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bip32: add tests for Elements pubkey tweaking
Browse files Browse the repository at this point in the history
jgriffiths committed Jul 8, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent 1645863 commit a6bf2a1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/test/test_bip32.py
Original file line number Diff line number Diff line change
@@ -688,6 +688,29 @@ def test_get_fingerprint(self):
self.assertEqual(bip32_key_get_fingerprint(child, buf, buf_len), WALLY_OK)
self.assertEqual(h(buf), b'f09cb160')

def test_tweak(self):
_, is_elements = wally_is_elements_build()
if not is_elements:
return
pub, priv = get_test_master_key(vec_1), get_test_master_key(vec_1)
self.assertEqual(bip32_key_strip_private_key(pub), WALLY_OK)

path_1 = self.path_to_c([1])
tweak_1 = '6505fd0f948587ff19ecb8d9b3892125897eb445e28e0ba23086a888daeb00aa'
for flags, expected in [
(FLAG_KEY_PUBLIC, '00' * 32),
(FLAG_KEY_PUBLIC | FLAG_KEY_TWEAK_SUM, tweak_1)
]:
pub_out, priv_out = ext_key(), ext_key()
for parent, key_out in [ (pub, pub_out), (priv, priv_out) ]:
ret = bip32_key_from_parent(byref(parent), 1, flags, byref(key_out))
self.assertEqual(ret, WALLY_OK)
self.assertEqual(h(key_out.pub_key_tweak_sum), utf8(expected))
ret = bip32_key_from_parent_path(byref(parent), path_1, 1,
flags, byref(key_out))
self.assertEqual(ret, WALLY_OK)
self.assertEqual(h(key_out.pub_key_tweak_sum), utf8(expected))


if __name__ == '__main__':
unittest.main()

0 comments on commit a6bf2a1

Please sign in to comment.