MCPcopy Index your code
hub / github.com/jimmysong/programmingbitcoin / wif

Method wif

code-ch13/ecc.py:654–668  ·  view source on GitHub ↗
(self, compressed=True, testnet=False)

Source from the content-addressed store, hash-verified

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
671class PrivateKeyTest(TestCase):

Callers 1

test_wifMethod · 0.95

Calls 1

encode_base58_checksumFunction · 0.90

Tested by 1

test_wifMethod · 0.76