How to know what account is linked to what priavbte key
Hey, today i wanted to share a little thing that i learned the other day while trying to connect me to this account from a new device. That's when i though that i lost my keys... turns out i didnt loose them but just didnt properly label them and thus had a a lot of private hive keys written on paper without knowing which one were for which account.
I could have just "brute forced them" by trying each key with a different account on key chain but i tough it might be the optimal time to look for a different solution (with the constraint being that i musn't be online to keep my keys private), and also i post this so that maybe someone can review what i did to tell me if it was the optimal way of doing so.

Let's clown me a bit on how i managed to run my keys haha
First step, ask Duck.ai on how to proceed. Duck.ai tells me about doing it via python script that would retrive the info from the public key, but since i only had the private key i would first need to find the public key.
So here i am, learning some python basics to learn how to retrieve a account from a private key.
Step 1 : install python in 3.12
Step 2 : Creat the script : ```
from getpass import getpass
import requests
from beemgraphenebase.account import PrivateKey
HIVE_API = "https://api.hive.blog"
def find_accounts(public_key):
payload = {
"jsonrpc": "2.0",
"method": "condenser_api.get_key_references",
"params": [[public_key]],
"id": 1,
}
response = requests.post(
HIVE_API,
json=payload,
timeout=30,
)
response.raise_for_status()
data = response.json()
if "error" in data:
raise RuntimeError(data["error"])
return data.get("result", [])
print("Hive private-key account checker")
print("Your private key is processed locally.")
print("Do not send it to anyone.")
print()
while True:
private_key = getpass(
"Paste one Hive private key, or press Enter to quit: "
).strip()
if not private_key:
break
try:
key = PrivateKey(private_key, prefix="STM")
public_key = str(key.pubkey)
print()
print("Derived public key:")
print(public_key)
accounts = find_accounts(public_key)
if accounts:
print()
print("Possible account matches:")
for account_group in accounts:
for account in account_group:
print(" " + account)
else:
print()
print("No Hive account was found for this key.")
except Exception as error:
print()
print("Error:", error)
print()
print("-" * 60)
print()
Step 3 : Name this file " check_hive_keys.py "
Step 4 : Create the environment and activate it :
py -3.12 -m venv hive-env
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
hive-env\Scripts\Activate.ps1
Step 5 : Install required packages :
python -m pip install --upgrade pip
python -m pip install requests beem
Step 6 : Run it
python check_hive_keys.py
This should display :

Step 7 : Paste your private key, which wont be displayed after vibe coding this though that it was broken turns out you must wait a bit even though there are no sign that it worked, and then it will display this :

Step 8 : Relax because you could sign back : )
In the era of AI that could easily help you produce this kind of script (like it did with me) is it still pertinent to post such step by step tutorial to share a solution that we could all find by our own or is hive loosing one more content source ? I dont have the answer but still hope this will be helpful to someone eventually.