fix: save key and load key

This commit is contained in:
Ren Amamiya
2026-04-08 13:16:36 +07:00
parent 4050afe93f
commit 3dd032e238
6 changed files with 257 additions and 247 deletions

View File

@@ -31774,7 +31774,9 @@ For more info, visit https://reactjs.org/link/mock-scheduler`);
(0, import_react3.useEffect)(() => {
import_webextension_polyfill2.default.storage.local.get(["private_key", "relays", "protocol_handler", "notifications"]).then((results) => {
if (results.private_key) {
setPrivKey(nip19_exports.nsecEncode(results.private_key));
const pkey = results.private_key;
const nsec = nip19_exports.nsecEncode(hexToBytes(pkey));
setPrivKey(nsec);
}
if (results.relays) {
const relaysList = [];
@@ -32327,8 +32329,7 @@ examples:
addUnsavedChanges("private_key");
}
async function generate() {
const sk = generateSecretKey();
setPrivKey(nip19_exports.nsecEncode(utils_exports.bytesToHex(sk)));
setPrivKey(nip19_exports.nsecEncode(generateSecretKey()));
addUnsavedChanges("private_key");
}
async function saveKey() {
@@ -32342,20 +32343,17 @@ examples:
if (type === "nsec")
hexOrEmptyKey = bytesToHex(data);
} catch (_) {
showMessage("Invalid private key format.");
return;
}
await import_webextension_polyfill2.default.storage.local.set({
private_key: hexOrEmptyKey
});
if (hexOrEmptyKey !== "") {
setPrivKey(nip19_exports.nsecEncode(hexToBytes(hexOrEmptyKey)));
}
showMessage("saved private key!");
showMessage("Private Key has been saved.");
}
function isKeyValid() {
if (privKey === "")
return true;
if (privKey.match(/^[a-f0-9]{64}$/))
return true;
try {
if (nip19_exports.decode(privKey).type === "nsec")
return true;