From 4e3b11a313b53458fb1758b64d3335eaf6fa11cd Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 28 Apr 2022 11:00:51 +0000 Subject: [PATCH] tool addr2pubhash: check input, rejecting non-PKH addresses --- mmgen/addr.py | 1 + mmgen/tool/coin.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mmgen/addr.py b/mmgen/addr.py index 1084c7e2..fab522d8 100755 --- a/mmgen/addr.py +++ b/mmgen/addr.py @@ -43,6 +43,7 @@ class MMGenAddrType(str,Hilite,InitErrors,MMGenObject): extra_attrs = ImmutableAttr(tuple,set_none_ok=True) desc = ImmutableAttr(str) + pkh_fmts = ('p2pkh','bech32','ethereum') mmtypes = { 'L': ati('legacy', 'std', False,'p2pkh', 'p2pkh', 'wif', (), 'Legacy uncompressed address'), 'C': ati('compressed','std', True, 'p2pkh', 'p2pkh', 'wif', (), 'Compressed P2PKH address'), diff --git a/mmgen/tool/coin.py b/mmgen/tool/coin.py index 608a8c83..c654378f 100755 --- a/mmgen/tool/coin.py +++ b/mmgen/tool/coin.py @@ -160,9 +160,12 @@ class tool_cmd(tool_cmd_base): def addr2pubhash(self,addr:'sstr'): "convert coin address to public key hash" + from ..opts import opt ap = self.proto.parse_addr(addr) assert ap, f'coin address {addr!r} could not be parsed' - assert ap.fmt != 'p2sh', f'p2sh addresses cannot be converted to pubhash' + if ap.fmt not in MMGenAddrType.pkh_fmts: + from ..util import die + die(2,f'{ap.fmt} addresses cannot be converted to pubhash') return ap.bytes.hex() def addr2scriptpubkey(self,addr:'sstr'):