From 8184fe195de1e9024efa1994f2600212c3ac0032 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 8 May 2022 10:07:16 +0000 Subject: [PATCH] mmgen-tool: relocate ETH chksum and Geth wallet key commands --- mmgen/main_tool.py | 4 ++-- mmgen/tool/coin.py | 5 +++++ mmgen/tool/fileutil.py | 8 ++++++++ mmgen/tool/util.py | 13 ------------- test/tooltest2.py | 14 ++++++++------ 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/mmgen/main_tool.py b/mmgen/main_tool.py index 0bbd7b33..74619cf6 100755 --- a/mmgen/main_tool.py +++ b/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', ), diff --git a/mmgen/tool/coin.py b/mmgen/tool/coin.py index becf3530..d171664f 100755 --- a/mmgen/tool/coin.py +++ b/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) diff --git a/mmgen/tool/fileutil.py b/mmgen/tool/fileutil.py index 62d50e98..098a4fb4 100755 --- a/mmgen/tool/fileutil.py +++ b/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() diff --git a/mmgen/tool/util.py b/mmgen/tool/util.py index 2198d1ee..c116feff 100755 --- a/mmgen/tool/util.py +++ b/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() diff --git a/test/tooltest2.py b/test/tooltest2.py index 923c1396..c1fd15b6 100755 --- a/test/tooltest2.py +++ b/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' ),