示例#1
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))
示例#2
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)
示例#3
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)
示例#4
0
 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())))
示例#5
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
示例#6
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)
示例#7
0
 def test_from_xpub(self) -> None:
     xpub_str = 'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB'
     xpub = CBitcoinExtPubKey(xpub_str)
     self.assertEqual(xpub_str, str(CBitcoinExtPubKey.from_bytes(xpub)))
示例#8
0
 def T(base58_xpubkey: str, expected_hex_xpubkey: str) -> None:
     key = CBitcoinExtPubKey(base58_xpubkey)
     self.assertEqual(b2x(key), expected_hex_xpubkey)
     key2 = CBitcoinExtPubKey.from_bytes(x(expected_hex_xpubkey))
     self.assertEqual(b2x(key), b2x(key2))