def test_invalid_derivation(self): xpriv = CBitcoinExtKey( 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi' ) with self.assertRaises(ValueError): xpriv.derive(1 << 32) final_xpriv_str = 'xprvJ9DiCzes6yvKjEy8duXR1Qg6Et6CBmrR4yFJvnburXG4X6VnKbNxoTYhvVdpsxkjdXwX3D2NJHFCAnnN1DdAJCVQitnFbFWv3fL3oB2BFo4' for _ in range(255): xpriv = xpriv.derive(0) self.assertEqual(str(CBitcoinExtKey.from_bytes(xpriv)), final_xpriv_str) with self.assertRaises(ValueError): xpriv.derive(0) # depth > 255
def test_extkey(self): xprv_str = 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi' xprv = CBitcoinExtKey(xprv_str) xprv2 = CExtKey(xprv) self.assertEqual(xprv_str, str(CBitcoinExtKey.from_bytes(xprv2))) self.assertEqual(bytes(xprv.derive(BIP32_HARDENED_KEY_LIMIT)), bytes(xprv2.derive(BIP32_HARDENED_KEY_LIMIT))) self.assertEqual(str(xprv.neuter()), str(CBitcoinExtPubKey.from_bytes(xprv2.neuter())))