Browse Source

mmgen-tool: new `privhex2pair` subcommand

The MMGen Project 5 months ago
parent
commit
1aff3980ee
2 changed files with 9 additions and 4 deletions
  1. 1 0
      mmgen/main_tool.py
  2. 8 4
      mmgen/tool/coin.py

+ 1 - 0
mmgen/main_tool.py

@@ -118,6 +118,7 @@ mods = {
 		'pubhash2addr',
 		'pubhex2addr',
 		'pubhex2redeem_script',
+		'privhex2pair',
 		'randpair',
 		'randwif',
 		'redeem_script2addr',

+ 8 - 4
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(