Esempio n. 1
0
    def test_invalid_derivation(self):
        xpub = CBitcoinExtPubKey(
            'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB'
        )

        with self.assertRaises(ValueError):
            xpub.derive(1 << 31)

        final_xpub_str = 'xpubEPPCAoZp7t6CN5GGoyYTEr91FCaPpQonRouneRKmRCzgfcWNHnyHMuQPCDn8wLv1vYyPrFpSK26VeA9dDXTKMCLm7FaSY9aVTWw5mTZLC7F'
        for _ in range(255):
            xpub = xpub.derive(0)
        self.assertEqual(str(CBitcoinExtPubKey.from_bytes(xpub)), final_xpub_str)

        with self.assertRaises(ValueError):
            xpub.derive(0)  # depth > 255
Esempio n. 2
0
 def test(self):
     xpub_str = 'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB'
     xpub = CBitcoinExtPubKey(xpub_str)
     xpub2 = CExtPubKey(xpub)
     self.assertEqual(xpub_str, str(CBitcoinExtPubKey.from_bytes(xpub2)))
     self.assertEqual(xpub, CBitcoinExtPubKey.from_bytes(xpub2))
     self.assertEqual(xpub.derive(0), xpub2.derive(0))
Esempio n. 3
0
        def T(base_xpub, expected_child, path):
            xpub = CBitcoinExtPubKey(base_xpub)
            for child_num in path:
                xpub = xpub.derive(child_num)

            self.assertEqual(str(CBitcoinExtPubKey.from_bytes(xpub)),
                             expected_child)

            xpub = CBitcoinExtPubKey(base_xpub).derive_path(
                str(BIP32Path(path)))
            self.assertEqual(str(CBitcoinExtPubKey.from_bytes(xpub)),
                             expected_child)
Esempio n. 4
0
        def T(base_xpub: str, expected_child: str, path: List[int]) -> None:
            xpub = CBitcoinExtPubKey(base_xpub)
            self.assertEqual(xpub.parent_fp, b'\x00\x00\x00\x00')
            for child_num in path:
                parent_fp = xpub.fingerprint
                xpub = xpub.derive(child_num)
                self.assertEqual(xpub.parent_fp, parent_fp)

            self.assertEqual(str(CBitcoinExtPubKey.from_bytes(xpub)),
                             expected_child)

            xpub = CBitcoinExtPubKey(base_xpub).derive_path(
                str(BIP32Path(path)))
            self.assertEqual(str(CBitcoinExtPubKey.from_bytes(xpub)),
                             expected_child)
Esempio n. 5
0
        def T(base_xpub, expected_child, path):
            xpub = CBitcoinExtPubKey(base_xpub)
            for child_num in path:
                xpub = xpub.derive(child_num)

            self.assertTrue(str(CBitcoinExtPubKey.from_bytes(xpub)) == expected_child)