コード例 #1
0
 def test_public_derivation_with_path(self):
     node = HDKey.from_mnemonic(bip39_test_vectors.public_path_mnemonic)
     child = node.derive_child(0)
     grandchild = child.derive_child(0)
     self.assertEqual(child.xpub, self.public_path[1])
     self.assertEqual(grandchild.xpub, self.public_path[2])
     self.assertEqual(grandchild.path, 'm/0/0')
コード例 #2
0
 def test_from_mnemonic(self):
     for test_vector in self.english_vectors:
         root = HDKey.from_mnemonic(mnemonic=test_vector['mnemonic'],
                                    salt=test_vector['salt'])
         child = root.derive_path(test_vector['derived_node']['path'])
         for (obj, choice) in zip([root, child], ['root', 'derived_node']):
             self.assertEqual(obj.xpriv, test_vector[choice]['xpriv'])
             self.assertEqual(obj.xpub, test_vector[choice]['xpub'])
             self.assertEqual(obj.privkey.hex(),
                              test_vector[choice]['private_key'])
             self.assertEqual(obj.pubkey.hex(),
                              test_vector[choice]['public_key'])
             self.assertEqual(obj.index, test_vector[choice]['index'])
             self.assertEqual(
                 obj.fingerprint,
                 bytes.fromhex(test_vector[choice]['fingerprint']))
             self.assertEqual(
                 obj.chain_code,
                 bytes.fromhex(test_vector[choice]['chain_code']))
             self.assertEqual(obj.depth, test_vector[choice]['depth'])
コード例 #3
0
    def test_derive_child_invalid_result(self, mock_tweak):
        mock_tweak.side_effect = [b'\xff' * 32, b'\x33' * 32]

        node = HDKey.from_mnemonic(bip39_test_vectors.public_path_mnemonic)
        child = node.derive_child(0)
        self.assertEqual(child.path, 'm/1')
コード例 #4
0
 def test_derive_path_not_descendent(self):
     root = HDKey.from_mnemonic(bip39_test_vectors.public_path_mnemonic)
     child = root.derive_path('m/0/0')
     with self.assertRaises(ValueError) as context:
         child.derive_path('m/1/1')
     self.assertIn('requested child not in', str(context.exception))
コード例 #5
0
 def test_child_from_xpub(self):
     node = HDKey.from_mnemonic(bip39_test_vectors.public_path_mnemonic)
     child = node._child_from_xpub(0, self.public_path[1])
     self.assertEqual(child.path, 'm/0')