Options is now showing keys, and changing keys as the dropdown is switched.

This commit is contained in:
Ryan Breen
2023-01-26 23:02:31 -05:00
parent 252c9d5234
commit 0ea7f11356
4 changed files with 116 additions and 17 deletions

View File

@@ -105,6 +105,18 @@ browser.runtime.onMessage.addListener(
let [srfpIndex, srfpRelays] = message.payload;
await saveRelaysForProfile(srfpIndex, srfpRelays);
break;
case 'getNameForProfile':
let nameForProfile = await getNameForProfile(message.payload);
sendResponse(nameForProfile);
break;
case 'getPubKeyForProfile':
let pubKeyForProfile = await getNpubKey(message.payload);
sendResponse(pubKeyForProfile);
break;
case 'getPrivKeyForProfile':
let privKeyForProfile = await getNsecKey(message.payload);
sendResponse(privKeyForProfile);
break;
default:
break;
}
@@ -138,9 +150,22 @@ async function initialize() {
]);
}
async function getNsecKey() {
let profile = await currentProfile();
return profile.nsecKey;
async function getProfile(index) {
let profiles = await get('profiles');
return profiles[index];
}
async function getNsecKey(index) {
let profile = await getProfile(index);
let nsecKey = nip19.nsecEncode(profile.privKey);
return nsecKey;
}
async function getNpubKey(index) {
let profile = await getProfile(index);
let pubKey = getPublicKey(profile.privKey);
let npubKey = nip19.npubEncode(pubKey);
return npubKey;
}
async function getPrivKey() {
@@ -148,12 +173,6 @@ async function getPrivKey() {
return profile.privKey;
}
async function getNpubKey() {
let pubKey = await getPubKey();
let npubKey = nip19.npubEncode(pubKey);
return npubKey;
}
async function getPubKey() {
let privKey = await getPrivKey();
let pubKey = getPublicKey(privKey);
@@ -260,3 +279,9 @@ async function saveRelaysForProfile(profileIndex, relays) {
profile.relays = relays;
await storage.set({ profiles });
}
async function getNameForProfile(profileIndex) {
let profiles = await get('profiles');
let profile = profiles[profileIndex];
return profile.name;
}