| 652 | v = hmac.new(k, v, s256).digest() |
| 653 | |
| 654 | def wif(self, compressed=True, testnet=False): |
| 655 | # convert the secret from integer to a 32-bytes in big endian using num.to_bytes(32, 'big') |
| 656 | secret_bytes = self.secret.to_bytes(32, 'big') |
| 657 | # prepend b'\xef' on testnet, b'\x80' on mainnet |
| 658 | if testnet: |
| 659 | prefix = b'\xef' |
| 660 | else: |
| 661 | prefix = b'\x80' |
| 662 | # append b'\x01' if compressed |
| 663 | if compressed: |
| 664 | suffix = b'\x01' |
| 665 | else: |
| 666 | suffix = b'' |
| 667 | # encode_base58_checksum the whole thing |
| 668 | return encode_base58_checksum(prefix + secret_bytes + suffix) |
| 669 | |
| 670 | |
| 671 | class PrivateKeyTest(TestCase): |