From d67f87aed16b839e64eb5ee6d52175b342b8785e Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 26 Oct 2019 14:14:31 +0000 Subject: [PATCH] baseconv: remove b58encode() and b58decode() convenience methods --- mmgen/bip39.py | 8 -------- mmgen/seed.py | 10 +++++----- mmgen/tool.py | 2 +- mmgen/tx.py | 4 ++-- mmgen/util.py | 10 ---------- 5 files changed, 8 insertions(+), 26 deletions(-) diff --git a/mmgen/bip39.py b/mmgen/bip39.py index 1dc180f1..7ea982f9 100755 --- a/mmgen/bip39.py +++ b/mmgen/bip39.py @@ -2169,11 +2169,3 @@ zoo res = seed_bin + chk_bin return tuple(wl[int(res[i*11:(i+1)*11],2)] for i in range(mn_len)) - - @classmethod - def b58encode(cls,*args,**kwargs): - raise NotImplementedError('not implemented') - - @classmethod - def b58decode(cls,*args,**kwargs): - raise NotImplementedError('not implemented') diff --git a/mmgen/seed.py b/mmgen/seed.py index 79834ffb..40615e69 100755 --- a/mmgen/seed.py +++ b/mmgen/seed.py @@ -972,7 +972,7 @@ class MMGenSeedFile(SeedSourceUnenc): ext = 'mmseed' def _format(self): - b58seed = baseconv.b58encode(self.seed.data,pad='seed') + b58seed = baseconv.frombytes(self.seed.data,'b58',pad='seed',tostr=True) self.ssdata.chksum = make_chksum_6(b58seed) self.ssdata.b58seed = b58seed self.fmt_data = '{} {}\n'.format(self.ssdata.chksum,split_into_cols(4,b58seed)) @@ -1000,7 +1000,7 @@ class MMGenSeedFile(SeedSourceUnenc): if not compare_chksums(a,'file',make_chksum_6(b),'computed',verbose=True): return False - ret = baseconv.b58decode(b,pad='seed') + ret = baseconv.tobytes(b,'b58',pad='seed') if ret == False: msg('Invalid base-58 encoded seed: {}'.format(val)) @@ -1146,8 +1146,8 @@ class Wallet (SeedSourceEnc): def _format(self): d = self.ssdata s = self.seed - slt_fmt = baseconv.b58encode(d.salt,pad='seed') - es_fmt = baseconv.b58encode(d.enc_seed,pad='seed') + slt_fmt = baseconv.frombytes(d.salt,'b58',pad='seed',tostr=True) + es_fmt = baseconv.frombytes(d.enc_seed,'b58',pad='seed',tostr=True) lines = ( d.label, '{} {} {} {} {}'.format(s.sid.lower(), d.key_id.lower(), @@ -1219,7 +1219,7 @@ class Wallet (SeedSourceEnc): make_chksum_6(b58_val),'computed checksum',verbose=True): return False - val = baseconv.b58decode(b58_val,pad='seed') + val = baseconv.tobytes(b58_val,'b58',pad='seed') if val == False: msg('Invalid base 58 number: {}'.format(b58_val)) return False diff --git a/mmgen/tool.py b/mmgen/tool.py index 75e497d0..8dd5c770 100755 --- a/mmgen/tool.py +++ b/mmgen/tool.py @@ -316,7 +316,7 @@ class MMGenToolCmdUtil(MMGenToolCmdBase): def randb58(self,nbytes=32,pad=0): "generate random data (default: 32 bytes) and convert it to base 58" - return baseconv.b58encode(get_random(nbytes),pad=pad) + return baseconv.frombytes(get_random(nbytes),'b58',pad=pad,tostr=True) def bytestob58(self,infile:str,pad=0): "convert bytes to base 58 (supply data via STDIN)" diff --git a/mmgen/tx.py b/mmgen/tx.py index ecdfbbef..997bdafe 100755 --- a/mmgen/tx.py +++ b/mmgen/tx.py @@ -698,7 +698,7 @@ Selected non-{pnm} inputs: {{}}""".strip().format(pnm=g.proj_name,pnl=g.proj_nam repr([amt_to_str(e.__dict__) for e in self.outputs]) ] if self.label: - lines.append(baseconv.b58encode(self.label.encode())) + lines.append(baseconv.frombytes(self.label.encode(),'b58',tostr=True)) if self.coin_txid: if not self.label: lines.append('-') # keep old tx files backwards compatible lines.append(self.coin_txid) @@ -1214,7 +1214,7 @@ Selected non-{pnm} inputs: {{}}""".strip().format(pnm=g.proj_name,pnl=g.proj_nam c = tx_data.pop(-1) if c != '-': desc = 'encoded comment (not base58)' - comment = baseconv.b58decode(c).decode('utf8') + comment = baseconv.tobytes(c,'b58').decode() assert comment != False,'invalid comment' desc = 'comment' self.label = MMGenTXLabel(comment,on_fail='raise') diff --git a/mmgen/util.py b/mmgen/util.py index e736ab71..5d398886 100755 --- a/mmgen/util.py +++ b/mmgen/util.py @@ -432,16 +432,6 @@ class baseconv(object): o = [wl[n] for n in [0] * (pad-len(ret)) + ret[::-1]] return ''.join(o) if tostr else o - @classmethod - def b58decode(cls,s,pad=None): - 'convert base58 string to bytes' - return bytes.fromhex(cls.tohex(s,'b58',pad=pad)) - - @classmethod - def b58encode(cls,s,pad=None): - 'convert bytes to base58 string' - return cls.fromhex(s.hex(),'b58',pad=pad,tostr=True) - def match_ext(addr,ext): return addr.split('.')[-1] == ext