def test_sign_verify_fail(self): wif = 'L3ULUjNr4gfjcxFEJVo6bETbDvY6Z3wwU5oribqt692o9a5SHV2R' wif2 = 'L3tJ46CAEaWr7YF5CZ6a1qg1cuhpeJEak5cr3esiVWA3To9PjWvn' ecpair = ECPair.from_wif(wif) ecpair2 = ECPair.from_wif(wif2) buffer = sha256(b"I am Satoshi Nakamoto") signature = ecpair.sign(buffer) self.assertFalse(ecpair2.verify(buffer, signature))
def assert_sign_verify(self, wif, message): ecpair = ECPair.from_wif(wif) buffer = sha256(message) wrong_message = message[1:] signature = ecpair.sign(buffer) self.assertTrue(ecpair.verify(buffer, signature)) self.assertFalse(ecpair.verify(sha256(wrong_message), signature))
def test_from_wif_uncompressed(self): ecpair = ECPair.from_wif( '5KESiB48wksvA4141nwrJGjjC5szu81fd3T2J8SaKqVW2zmxdCr') self.assertEqual( ecpair.privkey, int( 'ba8c65b5e47143979b3506a742b4bd95c1ddb419195915c3679e38e9bffbeb45', 16)) self.assertFalse(ecpair.compressed)
def test_from_wif_compressed(self): ecpair = ECPair.from_wif( 'L3ULUjNr4gfjcxFEJVo6bETbDvY6Z3wwU5oribqt692o9a5SHV2R') self.assertEqual( ecpair.privkey, int( 'ba8c65b5e47143979b3506a742b4bd95c1ddb419195915c3679e38e9bffbeb45', 16)) self.assertTrue(ecpair.compressed)
def test_from_wif_invalid(self): # 32 bytes with self.assertRaises(ValueError): ECPair.from_wif( 'mdWSTVi6STwH9sLTF2zhRAg7AJUMKQsDgMeDc6sjaTgV7miXA') # 35 bytes with self.assertRaises(ValueError): ECPair.from_wif( '3Yi64vA349642Ch7sPXUcpdDNmmfQg7XAw3bx1mVNL6hCQrFV4XQgy') # 34 bytes not started with \x01 with self.assertRaises(ValueError): ECPair.from_wif( 'LWjVhLCGgaLZ3stB33SWvSFAvtkKWjsqET84r9Se5E96smt318gK')
def test_sign_no_privkey(self): wif = 'KzHvGCQJWGr3NT8L83Kpj6KK245QTKeXPy1jGV14LRWd1XA74Ngy' ecpair = ECPair.from_wif(wif) neutered_ecpair = ECPair(None, ecpair.pubkey_buffer) with self.assertRaises(RuntimeError): neutered_ecpair.sign(sha256(b'test'))
def test_from_wif_network_not_supported(self): b = b"\x00" + bytes(random.getrandbits(8) for _ in range(32)) s = base58.b58encode_check(b) with self.assertRaises(Exception): ECPair.from_wif(s)