addrgen.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python3
  2. #
  3. # MMGen Wallet, a terminal-based cryptocurrency wallet
  4. # Copyright (C)2013-2026 The MMGen Project <mmgen@tuta.io>
  5. # Licensed under the GNU General Public License, Version 3:
  6. # https://www.gnu.org/licenses
  7. # Public project repositories:
  8. # https://github.com/mmgen/mmgen-wallet
  9. # https://gitlab.com/mmgen/mmgen-wallet
  10. """
  11. proto.btc.addrgen: Bitcoin address generation classes for the MMGen suite
  12. """
  13. from ...addrgen import addr_generator, check_data
  14. from .common import hash160
  15. class p2pkh(addr_generator.base):
  16. @check_data
  17. def to_addr(self, data):
  18. return self.proto.pubhash2addr(hash160(data.pubkey), 'p2pkh')
  19. class legacy(p2pkh):
  20. pass
  21. class compressed(p2pkh):
  22. pass
  23. class segwit(addr_generator.base):
  24. @check_data
  25. def to_addr(self, data):
  26. return self.proto.pubhash2segwitaddr(hash160(data.pubkey))
  27. def to_segwit_redeem_script(self, data): # NB: returns hex
  28. return self.proto.pubhash2redeem_script(hash160(data.pubkey)).hex()
  29. class bech32(addr_generator.base):
  30. @check_data
  31. def to_addr(self, data):
  32. return self.proto.pubhash2bech32addr(hash160(data.pubkey))