mmgen-tool: new privhex2pair subcommand

This commit is contained in:
The MMGen Project 2025-06-21 11:14:08 +00:00
commit 1aff3980ee
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 9 additions and 4 deletions

View file

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

View file

@ -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(