aboutsummaryrefslogtreecommitdiffstats
path: root/extension/src/popup.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-11-19 21:53:03 -0700
committerAdam Soltys <[email protected]>2026-11-19 21:53:03 -0700
commit69997b1cf47470bbe098ca042b5b64ef5e8873e6 (patch)
treefaa48099ca3582bf483bde0273fbe751aabb4219 /extension/src/popup.js
parent01c03a199f8aafacfcdbaac30af074dd1d56fc53 (diff)
downloadcoinosv3-69997b1cf47470bbe098ca042b5b64ef5e8873e6.tar.gz
coinosv3-69997b1cf47470bbe098ca042b5b64ef5e8873e6.zip
A browser extension that signs for nostr sites without asking twice, and pays from a Coinos wallet. "I'm using Sidecar right now, and I don't like how I have to reauthorize it. It prompts me too much. I just want it to automatically sign all the time with my key" (Adam, 2026-11-19). The extension (extension/, Chrome, Manifest V3) gives every page window.nostr (NIP-07: getPublicKey, signEvent, nip04, nip44) and window.webln. A site is asked once: "Always allow" is remembered with no expiry until the site is removed in the popup, "Never for this site" blocks it, and closing the window refuses that one call. Signing and paying are separate permissions. The key is an nsec or a wallet's twelve words (NIP-06), kept in the extension's storage unencrypted so it can sign without a prompt. The wallet is the person's own Coinos wallet over Nostr Wallet Connect: the extension holds a connection string, the wallet enforces that connection's budget, and the popup shows the balance and recent payments. Build with `bun extension/build.js` and load extension/dist unpacked. New extension-test loads the built extension into Chrome with its own relay and wallet service and passes (28 checks).HEADmaster
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6WFVA5qCuTtny8PRL6
Diffstat (limited to 'extension/src/popup.js')
-rw-r--r--extension/src/popup.js81
1 files changed, 81 insertions, 0 deletions
diff --git a/extension/src/popup.js b/extension/src/popup.js
new file mode 100644
index 0000000..8d9f8cf
--- /dev/null
+++ b/extension/src/popup.js
@@ -0,0 +1,81 @@
+// The extension's popup (and, opened in a tab, its settings page): the key,
+// the connected wallet's balance and recent payments, and the sites that
+// were allowed or blocked.
+const $ = (id) => document.getElementById(id);
+const send = async (m) => {
+ const r = await chrome.runtime.sendMessage(m);
+ if (!r || r.error) throw new Error((r && r.error) || 'No answer');
+ return r.result;
+};
+if (new URLSearchParams(location.search).has('tab') || window.innerWidth > 500) document.body.classList.add('tab');
+const sats = (n) => Number(n).toLocaleString('en-US');
+const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text != null) e.textContent = text; return e; };
+
+async function render() {
+ const s = await send({ type: 'state' });
+ $('setup').hidden = !!s.pubkey;
+ $('main').hidden = !s.pubkey;
+ if (!s.pubkey) { $('key-input').focus(); return; }
+
+ $('npub').textContent = s.npub.slice(0, 14) + '…' + s.npub.slice(-6);
+ $('name').textContent = 'Your key';
+ $('copy').onclick = async () => { await navigator.clipboard.writeText(s.npub); $('copy').textContent = 'Copied'; setTimeout(() => { $('copy').textContent = 'Copy'; }, 1200); };
+ send({ type: 'profile' }).then((p) => {
+ if (!p) return;
+ if (p.name) $('name').textContent = p.name;
+ if (p.picture) $('pic').src = p.picture;
+ }).catch(() => {});
+
+ $('wallet-on').hidden = !s.wallet;
+ $('wallet-off').hidden = !!s.wallet;
+ if (s.wallet) {
+ $('wallet-err').textContent = '';
+ send({ type: 'balance' }).then((b) => {
+ $('balance').textContent = sats(b);
+ $('balance').append(el('span', '', 'sats'));
+ }).catch((e) => { $('balance').textContent = '—'; $('wallet-err').textContent = e.message; });
+ send({ type: 'transactions' }).then((txs) => {
+ $('txs').replaceChildren(...txs.map((t) => {
+ const li = el('li');
+ li.append(el('span', 'grow', t.memo || (t.type === 'incoming' ? 'Received' : 'Sent')));
+ li.append(el('span', t.type === 'incoming' ? 'in' : '', (t.type === 'incoming' ? '+' : '−') + sats(t.sats)));
+ return li;
+ }));
+ }).catch(() => {});
+ }
+
+ const sites = Object.entries(s.sites).sort((a, b) => (b[1].at || 0) - (a[1].at || 0));
+ $('no-sites').hidden = sites.length > 0;
+ $('sites').replaceChildren(...sites.map(([origin, p]) => {
+ const li = el('li');
+ li.append(el('span', 'grow', origin.replace(/^https:\/\//, '')));
+ if (p.sign === true) li.append(el('span', 'tag', 'signs'));
+ if (p.pay === true) li.append(el('span', 'tag', 'pays'));
+ if (p.sign === false || p.pay === false) li.append(el('span', 'tag', 'blocked'));
+ const rm = el('button', 'link', 'Remove');
+ rm.setAttribute('aria-label', 'Remove ' + origin);
+ rm.onclick = async () => { await send({ type: 'removeSite', origin }); render(); };
+ li.append(rm);
+ return li;
+ }));
+}
+
+$('key-save').onclick = async () => {
+ $('key-err').textContent = '';
+ try { await send({ type: 'setKey', input: $('key-input').value }); $('key-input').value = ''; render(); }
+ catch (e) { $('key-err').textContent = e.message; }
+};
+$('nwc-save').onclick = async () => {
+ $('nwc-err').textContent = '';
+ try { await send({ type: 'setWallet', uri: $('nwc-input').value }); $('nwc-input').value = ''; render(); }
+ catch (e) { $('nwc-err').textContent = e.message; }
+};
+$('wallet-remove').onclick = async () => { await send({ type: 'removeWallet' }); render(); };
+$('key-remove').onclick = async () => {
+ const b = $('key-remove');
+ if (b.dataset.sure !== '1') { b.dataset.sure = '1'; b.textContent = 'Click again to remove the key'; return; }
+ await send({ type: 'removeKey' });
+ b.dataset.sure = ''; b.textContent = 'Remove key from this browser';
+ render();
+};
+render();