diff --git a/mmgen/main_tool.py b/mmgen/main_tool.py index a76070c8..71d47d26 100755 --- a/mmgen/main_tool.py +++ b/mmgen/main_tool.py @@ -118,6 +118,7 @@ mods = { 'pubhash2addr', 'pubhex2addr', 'pubhex2redeem_script', + 'privhex2pair', 'randpair', 'randwif', 'redeem_script2addr', diff --git a/mmgen/tool/coin.py b/mmgen/tool/coin.py index 2f0e3c94..fbc49d71 100755 --- a/mmgen/tool/coin.py +++ b/mmgen/tool/coin.py @@ -58,19 +58,23 @@ class tool_cmd(tool_cmd_base): pubkey_type = self.mmtype.pubkey_type, compressed = self.mmtype.compressed).wif - def randpair(self): - "generate a random private key/address pair" + def privhex2pair(self, privhex: 'sstr'): + "generate a wifkey/address pair from the provided hexadecimal key" gd = self._init_generators() - from ..crypto import Crypto privkey = PrivKey( self.proto, - Crypto(self.cfg).get_random(32), + bytes.fromhex(privhex), pubkey_type = self.mmtype.pubkey_type, compressed = self.mmtype.compressed) return ( privkey.wif, gd.ag.to_addr(gd.kg.gen_data(privkey))) + def randpair(self): + "generate a random wifkey/address pair" + from ..crypto import Crypto + return self.privhex2pair(Crypto(self.cfg).get_random(32).hex()) + def wif2hex(self, wifkey: 'sstr'): "convert a private key from WIF to hexadecimal format" return PrivKey(