From 610d0dd24351f18e6d906779371c09db30654dce Mon Sep 17 00:00:00 2001 From: MMGen Date: Sat, 29 Sep 2018 10:57:32 +0000 Subject: [PATCH] =?UTF-8?q?mmgen-tool:=20add=20=E2=80=98hextob58chk?= =?UTF-8?q?=E2=80=99=20and=20=E2=80=98b58chktohex=E2=80=99=20cmds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mmgen/main_tool.py | 2 ++ mmgen/protocol.py | 1 + mmgen/tool.py | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/mmgen/main_tool.py b/mmgen/main_tool.py index 6566a843..e8fe0b4e 100755 --- a/mmgen/main_tool.py +++ b/mmgen/main_tool.py @@ -72,7 +72,9 @@ General utilities: b58tostr - convert a base 58 number to a string strtob58 - convert a string to base 58 b58tohex - convert a base 58 number to hexadecimal + b58chktohex - convert a base58-check encoded number to hexadecimal hextob58 - convert a hexadecimal number to base 58 + hextob58chk - convert a hexadecimal number to base58-check encoding b32tohex - convert a base 32 number to hexadecimal hextob32 - convert a hexadecimal number to base 32 diff --git a/mmgen/protocol.py b/mmgen/protocol.py index 0b8999dd..ac6b97fb 100755 --- a/mmgen/protocol.py +++ b/mmgen/protocol.py @@ -56,6 +56,7 @@ def _b58chk_encode(hexstr): def _b58chk_decode(s): hexstr = '{:x}'.format(_b58tonum(s)) + if len(hexstr) % 2: hexstr = '0' + hexstr if hexstr[-8:] == hash256(hexstr[:-8])[:8]: return hexstr[:-8] raise ValueError,'_b58chk_decode(): checksum incorrect' diff --git a/mmgen/tool.py b/mmgen/tool.py index a48f03c3..7444740d 100755 --- a/mmgen/tool.py +++ b/mmgen/tool.py @@ -38,7 +38,9 @@ cmd_data = OrderedDict([ ('Strtob58', [' [str-]','pad [int=0]']), ('B58tostr', [' [str-]']), ('Hextob58', [' [str-]','pad [int=0]']), + ('Hextob58chk', [' [str-]']), ('B58tohex', [' [str-]','pad [int=0]']), + ('B58chktohex', [' [str-]']), ('B58randenc', []), ('B32tohex', [' [str-]','pad [int=0]']), ('Hextob32', [' [str-]','pad [int=0]']), @@ -327,9 +329,15 @@ def Mn2hex(s,wordlist=dfl_wl_id): Msg(baseconv.tohex(s.split(),wordlist)) def Strtob58(s,pad=None): Msg(baseconv.fromhex(binascii.hexlify(s),'b58',pad,tostr=True)) def Hextob58(s,pad=None): Msg(baseconv.fromhex(s,'b58',pad,tostr=True)) +def Hextob58chk(s): + from mmgen.protocol import _b58chk_encode + Msg(_b58chk_encode(s)) def Hextob32(s,pad=None): Msg(baseconv.fromhex(s,'b32',pad,tostr=True)) def B58tostr(s): Msg(binascii.unhexlify(baseconv.tohex(s,'b58'))) def B58tohex(s,pad=None): Msg(baseconv.tohex(s,'b58',pad)) +def B58chktohex(s): + from mmgen.protocol import _b58chk_decode + Msg(_b58chk_decode(s)) def B32tohex(s,pad=None): Msg(baseconv.tohex(s.upper(),'b32',pad)) from mmgen.seed import Mnemonic