Render the keys and npub/nsec keys in the UI
This commit is contained in:
@@ -16,9 +16,13 @@ browser.runtime.onMessage.addListener(async (message, _sender, sendResponse) =>
|
|||||||
let profileIndex = await getProfileIndex();
|
let profileIndex = await getProfileIndex();
|
||||||
sendResponse(profileIndex);
|
sendResponse(profileIndex);
|
||||||
break;
|
break;
|
||||||
case 'getPrivKey':
|
case 'getNsecKey':
|
||||||
let privKey = await getPrivKey();
|
let nsecKey = await getNsecKey();
|
||||||
sendResponse(privKey);
|
sendResponse(nsecKey);
|
||||||
|
break;
|
||||||
|
case 'getNpubKey':
|
||||||
|
let npubKey = await getNpubKey();
|
||||||
|
sendResponse(npubKey);
|
||||||
break;
|
break;
|
||||||
case 'getPubKey':
|
case 'getPubKey':
|
||||||
let pubKey = await getPubKey();
|
let pubKey = await getPubKey();
|
||||||
@@ -85,14 +89,28 @@ async function initialize() {
|
|||||||
await getOrSetDefault('profiles', [{name: 'Default', privKey: generatePrivateKey(), hosts: []}]);
|
await getOrSetDefault('profiles', [{name: 'Default', privKey: generatePrivateKey(), hosts: []}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getNsecKey() {
|
||||||
|
let profile = await currentProfile();
|
||||||
|
return profile.nsecKey;
|
||||||
|
}
|
||||||
|
|
||||||
async function getPrivKey() {
|
async function getPrivKey() {
|
||||||
let profile = await currentProfile();
|
let profile = await currentProfile();
|
||||||
return profile.privKey;
|
return profile.privKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getNpubKey() {
|
||||||
|
let pubKey = await getPubKey();
|
||||||
|
console.log('pubKey: ', pubKey);
|
||||||
|
let npubKey = nip19.npubEncode(pubKey);
|
||||||
|
console.log('npub key: ', npubKey);
|
||||||
|
return npubKey;
|
||||||
|
}
|
||||||
|
|
||||||
async function getPubKey() {
|
async function getPubKey() {
|
||||||
let privKey = await getPrivKey();
|
let privKey = await getPrivKey();
|
||||||
return getPublicKey(privKey);
|
let pubKey = getPublicKey(privKey);
|
||||||
|
return pubKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getHosts() {
|
async function getHosts() {
|
||||||
@@ -121,6 +139,8 @@ async function getProfileIndex() {
|
|||||||
async function currentProfile() {
|
async function currentProfile() {
|
||||||
let index = await get('profileIndex');
|
let index = await get('profileIndex');
|
||||||
let profiles = await get('profiles');
|
let profiles = await get('profiles');
|
||||||
|
let currentProfile = profiles[index];
|
||||||
|
currentProfile.nsecKey = nip19.nsecEncode(currentProfile.privKey);
|
||||||
return profiles[index];
|
return profiles[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ Alpine.data('popup', () => ({
|
|||||||
},
|
},
|
||||||
|
|
||||||
async refreshProfile() {
|
async refreshProfile() {
|
||||||
await this.getPrivKey();
|
await this.getNsecKey();
|
||||||
await this.getPubKey();
|
await this.getNpubKey();
|
||||||
await this.getHosts();
|
await this.getHosts();
|
||||||
await this.getName();
|
await this.getName();
|
||||||
await this.getProfileNames();
|
await this.getProfileNames();
|
||||||
@@ -46,12 +46,14 @@ Alpine.data('popup', () => ({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async getPrivKey() {
|
async getNsecKey() {
|
||||||
this.privKey = await browser.runtime.sendMessage({kind: 'getPrivKey'});
|
this.privKey = await browser.runtime.sendMessage({kind: 'getNsecKey'});
|
||||||
|
console.log('privKey: ', this.privKey);
|
||||||
},
|
},
|
||||||
|
|
||||||
async getPubKey() {
|
async getNpubKey() {
|
||||||
this.pubKey = await browser.runtime.sendMessage({kind: 'getPubKey'});
|
this.pubKey = await browser.runtime.sendMessage({kind: 'getNpubKey'});
|
||||||
|
console.log('pubKey: ', this.pubKey);
|
||||||
},
|
},
|
||||||
|
|
||||||
async getHosts() {
|
async getHosts() {
|
||||||
@@ -60,14 +62,17 @@ Alpine.data('popup', () => ({
|
|||||||
|
|
||||||
async getProfileNames() {
|
async getProfileNames() {
|
||||||
this.profileNames = await browser.runtime.sendMessage({kind: 'getProfileNames'});
|
this.profileNames = await browser.runtime.sendMessage({kind: 'getProfileNames'});
|
||||||
|
console.log('Profile Names: ', this.profileNames);
|
||||||
},
|
},
|
||||||
|
|
||||||
async getName() {
|
async getName() {
|
||||||
this.name = await browser.runtime.sendMessage({kind: 'getName'});
|
this.name = await browser.runtime.sendMessage({kind: 'getName'});
|
||||||
|
console.log('Name: ', this.name);
|
||||||
},
|
},
|
||||||
|
|
||||||
async getProfileIndex() {
|
async getProfileIndex() {
|
||||||
this.profileIndex = await browser.runtime.sendMessage({kind: 'getProfileIndex'});
|
this.profileIndex = await browser.runtime.sendMessage({kind: 'getProfileIndex'});
|
||||||
|
console.log('Profile Index: ', this.profileIndex);
|
||||||
},
|
},
|
||||||
|
|
||||||
async newProfile() {
|
async newProfile() {
|
||||||
|
|||||||
Reference in New Issue
Block a user