addrgen.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
  4. # Copyright (C)2013-2022 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
  9. # https://gitlab.com/mmgen/mmgen
  10. """
  11. proto.btc.addrgen: Bitcoin address generation classes for the MMGen suite
  12. """
  13. from ...addrgen import addr_generator,check_data
  14. from ...addr import CoinAddr
  15. from .common import hash160
  16. class p2pkh(addr_generator.base):
  17. @check_data
  18. def to_addr(self,data):
  19. return CoinAddr(
  20. self.proto,
  21. self.proto.pubhash2addr( hash160(data.pubkey), p2sh=False ))
  22. class legacy(p2pkh):
  23. pass
  24. class compressed(p2pkh):
  25. pass
  26. class segwit(addr_generator.base):
  27. @check_data
  28. def to_addr(self,data):
  29. return CoinAddr(
  30. self.proto,
  31. self.proto.pubhash2segwitaddr( hash160(data.pubkey)) )
  32. def to_segwit_redeem_script(self,data): # NB: returns hex
  33. return self.proto.pubhash2redeem_script( hash160(data.pubkey) ).hex()
  34. class bech32(addr_generator.base):
  35. @check_data
  36. def to_addr(self,data):
  37. return CoinAddr(
  38. self.proto,
  39. self.proto.pubhash2bech32addr( hash160(data.pubkey) ))