Skip to content

Commit

Permalink
tool addr2pubhash: check input, rejecting non-PKH addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
mmgen committed Apr 28, 2022
1 parent 17539c0 commit 4e3b11a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions mmgen/addr.py
Expand Up @@ -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'),
Expand Down
5 changes: 4 additions & 1 deletion mmgen/tool/coin.py
Expand Up @@ -160,9 +160,12 @@ def pubhash2addr(self,pubhashhex:'sstr'):

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'):
Expand Down

0 comments on commit 4e3b11a

Please sign in to comment.