Is there any way to do this? I've tried digging through the source code to use the internal functions to generate the WIF, but haven't found the way to do it correctly.
Anyone know which function calls to use with a plain 256-bit random number to get the WIF?
This "
serialize_privkey" internal function should work:
github.com/spesmilo/electrum/blob/master/electrum/bitcoin.py#L620For example, replace
"0000000000000000000000000000000000000000000000000000000000000002" with your HEX private key:
bitcoin.serialize_privkey(bytes.fromhex("0000000000000000000000000000000000000000000000000000000000000002"),"true","banana")You can replace "
true" compressed bool with a blank "
" if you want to derive a WIF without the compressed flag byte.
And the last positional arg is just the prefix shown when exporting a private key so it will be displayed in front of the encoded WIF like in the example below,
Use the standard prefixes (
e.g.: p2pkh) if you just want to copy-paste it to import.
Result of the example command:
'banana:cMahea7zqjxrtgAbB7LSGbcQUr1uX1ojuat9jZodMN87K7XCyj5v'
Exporting a wallet in plaintext likewise doesn't really work because the keys are 33 hex bytes long -- there appears to be either a checksum or something else appended or added to them. When I overwrite one of these hex numbers with my own hex private key, leaving either the front byte in place, and then reload the wallet, I get an error, which is why I think there must be a checksum. The front byte is always 02 or 03, and I've tried both, and still get errors either way.
Those exported keys are most likely "
public keys" based from your description.