You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've tried to debug my code for hours using different random methods that I could think of.
I'm trying to export my keys to a file (txt for now) and import it for later use.
Here's my code:
importeth_keysimportosdefgenerate_keys():
Priv=eth_keys.keys.PrivateKey(os.urandom(32))
Pub=Priv.public_keymsg=b'Sign Me 321'signature=Priv.sign_msg(msg)
recoveredPubKey=signature.recover_public_key_from_msg(msg)
ifrecoveredPubKey==Pub:
valid=Pub.verify_msg(msg, signature)
ifvalid:
withopen(r"C:\net\public.txt", "w") asf:
f.write(Pub.__str__())
withopen(r"C:\net\private.txt", "w") asf:
f.write(Priv.__str__())
defsign(message):
""" Signs a message using the private.txt, returns (Signed Message) """withopen(r"C:\net\private.txt") asf:
eth_keys.keys.PrivateKey(private_key_bytes=f.read())
signature=eth_keys.keys.PrivateKey.sign_msg(message=bytes(message))
verification=eth_keys.keys.PrivateKey.public_key.verify_msg(message=message, signature=signature)
ifverificationisTrue:
returnsignatureelse:
assertverificationisnotFalse, \
"Try again or contact support, public key and private key did not correlate in sign()"generate_keys()
sign("Hello")
How can it be fixed?
Well, I just want to export and import my keys without an error popping up. It would also be nice if you could tell me which file type is better to use to store private keys.
The text was updated successfully, but these errors were encountered:
What was wrong?
I've tried to debug my code for hours using different random methods that I could think of.
I'm trying to export my keys to a file (txt for now) and import it for later use.
Here's my code:
How can it be fixed?
Well, I just want to export and import my keys without an error popping up. It would also be nice if you could tell me which file type is better to use to store private keys.
The text was updated successfully, but these errors were encountered: