Browse Source

baseconv: remove b58encode() and b58decode() convenience methods

The MMGen Project 5 years ago
parent
commit
d67f87aed1
5 changed files with 8 additions and 26 deletions
  1. 0 8
      mmgen/bip39.py
  2. 5 5
      mmgen/seed.py
  3. 1 1
      mmgen/tool.py
  4. 2 2
      mmgen/tx.py
  5. 0 10
      mmgen/util.py

+ 0 - 8
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')

+ 5 - 5
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

+ 1 - 1
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)"

+ 2 - 2
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')

+ 0 - 10
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