diff --git a/Shared (Extension)/Resources/background.js b/Shared (Extension)/Resources/background.js
index 5a0ecf9..c1885b1 100644
--- a/Shared (Extension)/Resources/background.js
+++ b/Shared (Extension)/Resources/background.js
@@ -1,10 +1,26 @@
-import { generatePrivateKey } from "nostr-tools";
+import { generatePrivateKey, getPublicKey } from "nostr-tools";
-browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
- console.log('generating a key!');
- console.log(generatePrivateKey());
- console.log("Received request: ", request);
+let profiles = [
+ {name: 'Default', privKey: generatePrivateKey(), hosts: [
+ {host: 'yosup.app', allowed: true},
+ {host: 'iris.to', allowed: false},
+ ]},
+ {name: 'Extra', privKey: generatePrivateKey(), hosts: []},
+];
- if (request.greeting === "hello")
- sendResponse({ farewell: "goodbye" });
+let activeProfile = 0;
+
+browser.runtime.onMessage.addListener((message, _sender, sendResponse) => {
+ console.log(message);
+ if (message.kind === 'getPubKey') {
+ const privKey = getPublicKey(message.payload);
+ sendResponse(privKey);
+ } else if (message.kind === 'newKey') {
+ const privKey = generatePrivateKey();
+ sendResponse(privKey);
+ } else if (message.kind === 'getProfiles') {
+ sendResponse(profiles);
+ } else if (message.kind === 'getActiveProfile') {
+ sendResponse(activeProfile);
+ }
});
diff --git a/Shared (Extension)/Resources/popup.css b/Shared (Extension)/Resources/popup.css
index 9074ac3..4ad90c2 100644
--- a/Shared (Extension)/Resources/popup.css
+++ b/Shared (Extension)/Resources/popup.css
@@ -9,7 +9,16 @@ body {
font-family: system-ui;
}
-#priv-key {
+label {
+ display: inline-block;
+ width: 100px;
+}
+
+input {
+ width: 32em;
+}
+
+#priv-key, #pub-key {
font-family: monospace;
}
diff --git a/Shared (Extension)/Resources/popup.html b/Shared (Extension)/Resources/popup.html
index 43a610e..5444e1f 100644
--- a/Shared (Extension)/Resources/popup.html
+++ b/Shared (Extension)/Resources/popup.html
@@ -8,16 +8,22 @@
-
+
+
+
+
+
-
+
@@ -25,13 +31,18 @@
-
+
+
+
+
+
+
Allowed Sites
-
+
- |
- |
+ |
+ |
|
diff --git a/Shared (Extension)/Resources/popup.js b/Shared (Extension)/Resources/popup.js
index e26188d..fb6899e 100644
--- a/Shared (Extension)/Resources/popup.js
+++ b/Shared (Extension)/Resources/popup.js
@@ -2,42 +2,62 @@ import Alpine from "alpinejs";
window.Alpine = Alpine;
Alpine.data('popup', () => ({
- privKey: '',
- profiles: [],
- profile: '',
+ pubKey: '',
+ profiles: [{name: 'Default', privKey: '', hosts: []}],
+ activeProfile: 0,
visibleKey: false,
- allowedSites: [],
async init() {
await this.getProfiles();
await this.getPrivKeyForProfile();
- await this.getAllowedSites();
},
- saveKey() {
- console.log(`Saving key ${this.privKey}`);
+ async saveKey() {
+ await this.getPubKey();
},
async getProfiles() {
- this.profiles = ['Default', 'Extra'];
- this.profile = 'Default';
+ this.profiles = await browser.runtime.sendMessage({kind: 'getProfiles'});
+ this.activeProfile = await browser.runtime.sendMessage({kind: 'getActiveProfile'});
},
async getPrivKeyForProfile() {
- this.privKey = this.profile;
- },
-
- async getAllowedSites() {
- this.allowedSites = [
- {site: 'yosupp.app', allowed: true},
- {site: 'iris.to', allowed: false},
- ];
+ await this.getPubKey();
},
async deleteSite(index) {
- let newSites = [...this.allowedSites];
+ confirm("hello");
+ let newSites = [...this.hosts];
newSites.splice(index, 1);
- this.allowedSites = newSites;
+ this.hosts = newSites;
+ },
+
+ async getPubKey() {
+ this.pubKey = await browser.runtime.sendMessage({kind: 'getPubKey', payload: this.profile.privKey});
+ console.log('Pub key: ', this.pubKey);
+ },
+
+ async newProfile() {
+ let newKey = await browser.runtime.sendMessage({kind: 'newKey'});
+ const newProfile = {name: 'New Profile', privKey: newKey};
+ this.profiles.push(newProfile);
+ this.activeProfile = this.profiles.length - 1;
+ },
+
+ get hasValidPubKey() {
+ return typeof(this.pubKey) === 'string' && this.pubKey.length > 0;
+ },
+
+ get profile() {
+ return this.profiles[this.activeProfile];
+ },
+
+ get hosts() {
+ return this.profile.hosts;
+ },
+
+ set hosts(value) {
+ this.profiles[this.activeProfile].hosts = value;
}
}));