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())))
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_from_xpriv(self): xpriv_str = 'xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt' xpriv = CBitcoinExtKey(xpriv_str) self.assertEqual(xpriv_str, str(CBitcoinExtKey.from_bytes(xpriv)))
def T(base58_xprivkey: str, expected_hex_xprivkey: str) -> None: key = CBitcoinExtKey(base58_xprivkey) self.assertEqual(b2x(key), expected_hex_xprivkey) key2 = CBitcoinExtKey.from_bytes(x(expected_hex_xprivkey)) self.assertEqual(b2x(key), b2x(key2))