Browse Source

mmgen-tool: relocate ETH chksum and Geth wallet key commands

The MMGen Project 2 years ago
parent
commit
8184fe195d
5 changed files with 23 additions and 21 deletions
  1. 2 2
      mmgen/main_tool.py
  2. 5 0
      mmgen/tool/coin.py
  3. 8 0
      mmgen/tool/fileutil.py
  4. 0 13
      mmgen/tool/util.py
  5. 8 6
      test/tooltest2.py

+ 2 - 2
mmgen/main_tool.py

@@ -83,8 +83,6 @@ mods = {
 		'b6dtohex',
 		'bytespec',
 		'bytestob58',
-		'eth_checksummed_addr',
-		'extract_key_from_geth_wallet',
 		'hash160',
 		'hash256',
 		'hexdump',
@@ -106,6 +104,7 @@ mods = {
 	'coin': (
 		'addr2pubhash',
 		'addr2scriptpubkey',
+		'eth_checksummed_addr',
 		'hex2wif',
 		'privhex2addr',
 		'privhex2pubhex',
@@ -142,6 +141,7 @@ mods = {
 		'encrypt',
 	),
 	'fileutil': (
+		'extract_key_from_geth_wallet',
 		'find_incog_data',
 		'rand2file',
 	),

+ 5 - 0
mmgen/tool/coin.py

@@ -184,3 +184,8 @@ class tool_cmd(tool_cmd_base):
 		"convert scriptPubKey to coin address"
 		from ..base_proto.bitcoin.tx.base import scriptPubKey2addr
 		return scriptPubKey2addr( self.proto, hexstr )[0]
+
+	def eth_checksummed_addr(self,addr:'sstr'):
+		"create a checksummed Ethereum address"
+		from ..protocol import init_proto
+		return init_proto('eth').checksummed_addr(addr)

+ 8 - 0
mmgen/tool/fileutil.py

@@ -125,3 +125,11 @@ class tool_cmd(tool_cmd_base):
 			qmsg(f'\r{nbytes} byte{suf(nbytes)} of random data written to file {outfile!r}')
 
 		return True
+
+	def extract_key_from_geth_wallet( self, wallet_file:str, check_addr=True ):
+		"decrypt the encrypted private key in a Geth keystore wallet, returning the decrypted key"
+		from ..util import line_input
+		from ..opts import opt
+		from ..base_proto.ethereum.misc import extract_key_from_geth_keystore_wallet
+		passwd = line_input( 'Enter passphrase: ', echo=opt.echo_passphrase ).strip().encode()
+		return extract_key_from_geth_keystore_wallet( wallet_file, passwd, check_addr ).hex()

+ 0 - 13
mmgen/tool/util.py

@@ -173,16 +173,3 @@ class tool_cmd(tool_cmd_base):
 		from ..baseconv import baseconv
 		from ..util import remove_whitespace
 		return baseconv('b6d').tohex( remove_whitespace(b6d_num), pad )
-
-	def eth_checksummed_addr(self,addr:'sstr'):
-		"create a checksummed Ethereum address"
-		from ..protocol import init_proto
-		return init_proto('eth').checksummed_addr(addr)
-
-	def extract_key_from_geth_wallet( self, wallet_file:str, check_addr=True ):
-		"decrypt the encrypted private key in a Geth keystore wallet, returning the decrypted key"
-		from ..util import line_input
-		from ..opts import opt
-		from ..base_proto.ethereum.misc import extract_key_from_geth_keystore_wallet
-		passwd = line_input( 'Enter passphrase: ', echo=opt.echo_passphrase ).strip().encode()
-		return extract_key_from_geth_keystore_wallet( wallet_file, passwd, check_addr ).hex()

+ 8 - 6
test/tooltest2.py

@@ -366,12 +366,6 @@ tests = {
 			( ['nbytes=16'], {'boolfunc':is_b58_str}, ['-r0'] ),
 			( ['nbytes=12','pad=0'], is_b58_str, ['-r0'] ),
 		],
-		'eth_checksummed_addr': [
-			( ['00a329c0648769a73afac7f9381e08fb43dbea72'], '00a329c0648769A73afAc7F9381E08FB43dBEA72' ),
-			( ['deadbeef'*5], 'DeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF' ),
-			( ['ffffffff'*5], 'FFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF' ),
-			( ['0'*39 + '1'], '0'*39 + '1' ),
-		],
 	},
 	'Wallet': {
 		'gen_key': [
@@ -442,6 +436,14 @@ tests = {
 				( [ btc_addr6 ], '3057f66ddd26fa6ef826b0d5ca067ec3e8f3c178' ),
 			],
 		},
+		'eth_checksummed_addr': {
+			'eth_mainnet': [
+				( ['00a329c0648769a73afac7f9381e08fb43dbea72'], '00a329c0648769A73afAc7F9381E08FB43dBEA72' ),
+				( ['deadbeef'*5], 'DeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF' ),
+				( ['ffffffff'*5], 'FFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF' ),
+				( ['0'*39 + '1'], '0'*39 + '1' ),
+			],
+		},
 		'pubhash2addr': {
 			'btc_mainnet': [
 				( ['118089d66b4a5853765e94923abdd5de4616c6e5'], btc_addr5, None, 'legacy' ),