wip: update

This commit is contained in:
reya
2024-12-22 07:35:25 +07:00
parent 8349bec65a
commit a1d87bcd74
24 changed files with 39476 additions and 33318 deletions

View File

@@ -1,148 +0,0 @@
{
"root": true,
"parserOptions": {
"ecmaVersion": 2020,
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module",
"allowImportExportEverywhere": false
},
"env": {
"es6": true,
"node": true
},
"plugins": [
"react",
"babel"
],
"globals": {
"document": false,
"navigator": false,
"window": false,
"location": false,
"URL": false,
"URLSearchParams": false,
"fetch": false,
"EventSource": false,
"localStorage": false,
"sessionStorage": false
},
"rules": {
"react/jsx-uses-vars": 2,
"react/jsx-no-undef": 2,
"react/jsx-uses-react": 2,
"accessor-pairs": 2,
"arrow-spacing": [2, { "before": true, "after": true }],
"block-spacing": [2, "always"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"comma-dangle": 0,
"comma-spacing": [2, { "before": false, "after": true }],
"comma-style": [2, "last"],
"constructor-super": 2,
"curly": [0, "multi-line"],
"dot-location": [2, "property"],
"eol-last": 2,
"eqeqeq": [2, "allow-null"],
"generator-star-spacing": [2, { "before": true, "after": true }],
"handle-callback-err": [2, "^(err|error)$" ],
"indent": 0,
"jsx-quotes": [2, "prefer-double"],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"keyword-spacing": [2, { "before": true, "after": true }],
"new-cap": 0,
"new-parens": 0,
"no-array-constructor": 2,
"no-caller": 2,
"no-class-assign": 2,
"no-cond-assign": 2,
"no-const-assign": 2,
"no-control-regex": 0,
"no-debugger": 0,
"no-delete-var": 2,
"no-dupe-args": 2,
"no-dupe-class-members": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty-character-class": 2,
"no-empty-pattern": 2,
"no-eval": 0,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": [2, "functions"],
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-implied-eval": 2,
"no-inner-declarations": [0, "functions"],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": [2, { "allowLoop": false, "allowSwitch": false }],
"no-lone-blocks": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-multiple-empty-lines": [2, { "max": 2 }],
"no-native-reassign": 2,
"no-negated-in-lhs": 2,
"no-new": 0,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 2,
"no-new-symbol": 2,
"no-new-wrappers": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-path-concat": 0,
"no-proto": 2,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-return-assign": 0,
"no-self-assign": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-sparse-arrays": 2,
"no-this-before-super": 2,
"no-throw-literal": 2,
"no-trailing-spaces": 2,
"no-undef": 2,
"no-undef-init": 2,
"no-unexpected-multiline": 2,
"no-unneeded-ternary": [2, { "defaultAssignment": false }],
"no-unreachable": 2,
"no-unused-vars": [2, { "vars": "local", "args": "none", "varsIgnorePattern": "^_"}],
"no-useless-call": 2,
"no-useless-constructor": 2,
"no-with": 2,
"one-var": [0, { "initialized": "never" }],
"operator-linebreak": [2, "after", { "overrides": { "?": "before", ":": "before" } }],
"padded-blocks": [2, "never"],
"quotes": [2, "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
"semi": [2, "never"],
"semi-spacing": [2, { "before": false, "after": true }],
"space-before-blocks": [2, "always"],
"space-before-function-paren": 0,
"space-in-parens": [2, "never"],
"space-infix-ops": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-comment": 0,
"template-curly-spacing": [2, "never"],
"use-isnan": 2,
"valid-typeof": 2,
"wrap-iife": [2, "any"],
"yield-star-spacing": [2, "both"],
"yoda": 0,
"no-unsafe-optional-chaning": 0
}
}

View File

@@ -1,9 +0,0 @@
arrowParens: avoid
bracketSpacing: false
jsxBracketSameLine: false
printWidth: 80
proseWrap: preserve
semi: false
singleQuote: true
trailingComma: none
useTabs: false

28
biome.json Normal file
View File

@@ -0,0 +1,28 @@
{
"$schema": "https://biomejs.dev/schemas/1.4.1/schema.json",
"organizeImports": {
"enabled": true
},
"files": {
"ignore": []
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"noNonNullAssertion": "warn",
"noUselessElse": "off"
},
"correctness": {
"useExhaustiveDependencies": "off"
},
"a11y": {
"noSvgWithoutTitle": "off"
},
"complexity": {
"noStaticOnlyClass": "off"
}
}
}
}

View File

@@ -1,225 +1,227 @@
import browser from 'webextension-polyfill' import { Mutex } from "async-mutex";
import { import {
validateEvent,
getSignature,
getEventHash, getEventHash,
getPublicKey, getPublicKey,
nip19 getSignature,
} from 'nostr-tools' nip19,
import {nip04} from 'nostr-tools' validateEvent,
import {Mutex} from 'async-mutex' } from "nostr-tools";
import { nip04 } from "nostr-tools";
import browser from "webextension-polyfill";
import { import {
NO_PERMISSIONS_REQUIRED, NO_PERMISSIONS_REQUIRED,
getPermissionStatus, getPermissionStatus,
showNotification,
updatePermission, updatePermission,
showNotification } from "./common";
} from './common'
const {encrypt, decrypt} = nip04 const { encrypt, decrypt } = nip04;
let openPrompt = null let openPrompt = null;
let promptMutex = new Mutex() const promptMutex = new Mutex();
let releasePromptMutex = () => {} let releasePromptMutex = () => {};
browser.runtime.onInstalled.addListener((_, __, reason) => { browser.runtime.onInstalled.addListener((_, __, reason) => {
if (reason === 'install') browser.runtime.openOptionsPage() if (reason === "install") browser.runtime.openOptionsPage();
}) });
browser.runtime.onMessage.addListener(async (req, sender) => { browser.runtime.onMessage.addListener(async (req, sender) => {
let {prompt} = req const { prompt } = req;
if (prompt) { if (prompt) {
handlePromptMessage(req, sender) handlePromptMessage(req, sender);
} else { } else {
return handleContentScriptMessage(req) return handleContentScriptMessage(req);
} }
}) });
browser.runtime.onMessageExternal.addListener( browser.runtime.onMessageExternal.addListener(
async ({ type, params }, sender) => { async ({ type, params }, sender) => {
let extensionId = new URL(sender.url).host const extensionId = new URL(sender.url).host;
return handleContentScriptMessage({type, params, host: extensionId}) return handleContentScriptMessage({ type, params, host: extensionId });
} },
) );
browser.windows.onRemoved.addListener(windowId => { browser.windows.onRemoved.addListener((windowId) => {
if (openPrompt) { if (openPrompt) {
// calling this with a simple "no" response will not store anything, so it's fine // calling this with a simple "no" response will not store anything, so it's fine
// it will just return a failure // it will just return a failure
handlePromptMessage({accept: false}, null) handlePromptMessage({ accept: false }, null);
} }
}) });
async function handleContentScriptMessage({ type, params, host }) { async function handleContentScriptMessage({ type, params, host }) {
if (NO_PERMISSIONS_REQUIRED[type]) { if (NO_PERMISSIONS_REQUIRED[type]) {
// authorized, and we won't do anything with private key here, so do a separate handler // authorized, and we won't do anything with private key here, so do a separate handler
switch (type) { switch (type) {
case 'replaceURL': { case "replaceURL": {
let {protocol_handler: ph} = await browser.storage.local.get([ const { protocol_handler: ph } = await browser.storage.local.get([
'protocol_handler' "protocol_handler",
]) ]);
if (!ph) return false if (!ph) return false;
let {url} = params const { url } = params;
let raw = url.split('nostr:')[1] const raw = url.split("nostr:")[1];
let {type, data} = nip19.decode(raw) const { type, data } = nip19.decode(raw);
let replacements = { const replacements = {
raw, raw,
hrp: type, hrp: type,
hex: hex:
type === 'npub' || type === 'note' type === "npub" || type === "note"
? data ? data
: type === 'nprofile' : type === "nprofile"
? data.pubkey ? data.pubkey
: type === 'nevent' : type === "nevent"
? data.id ? data.id
: null, : null,
p_or_e: {npub: 'p', note: 'e', nprofile: 'p', nevent: 'e'}[type], p_or_e: { npub: "p", note: "e", nprofile: "p", nevent: "e" }[type],
u_or_n: {npub: 'u', note: 'n', nprofile: 'u', nevent: 'n'}[type], u_or_n: { npub: "u", note: "n", nprofile: "u", nevent: "n" }[type],
relay0: type === 'nprofile' ? data.relays[0] : null, relay0: type === "nprofile" ? data.relays[0] : null,
relay1: type === 'nprofile' ? data.relays[1] : null, relay1: type === "nprofile" ? data.relays[1] : null,
relay2: type === 'nprofile' ? data.relays[2] : null relay2: type === "nprofile" ? data.relays[2] : null,
} };
let result = ph let result = ph;
// biome-ignore lint/complexity/noForEach: TODO: fix this
Object.entries(replacements).forEach(([pattern, value]) => { Object.entries(replacements).forEach(([pattern, value]) => {
result = result.replace(new RegExp(`{ *${pattern} *}`, 'g'), value) result = result.replace(new RegExp(`{ *${pattern} *}`, "g"), value);
}) });
return result return result;
} }
} }
return return;
} else { } else {
// acquire mutex here before reading policies // acquire mutex here before reading policies
releasePromptMutex = await promptMutex.acquire() releasePromptMutex = await promptMutex.acquire();
let allowed = await getPermissionStatus( const allowed = await getPermissionStatus(
host, host,
type, type,
type === 'signEvent' ? params.event : undefined type === "signEvent" ? params.event : undefined,
) );
if (allowed === true) { if (allowed === true) {
// authorized, proceed // authorized, proceed
releasePromptMutex() releasePromptMutex();
showNotification(host, allowed, type, params) showNotification(host, allowed, type, params);
} else if (allowed === false) { } else if (allowed === false) {
// denied, just refuse immediately // denied, just refuse immediately
releasePromptMutex() releasePromptMutex();
showNotification(host, allowed, type, params) showNotification(host, allowed, type, params);
return { return {
error: 'denied' error: "denied",
} };
} else { } else {
// ask for authorization // ask for authorization
try { try {
let id = Math.random().toString().slice(4) const id = Math.random().toString().slice(4);
let qs = new URLSearchParams({ const qs = new URLSearchParams({
host, host,
id, id,
params: JSON.stringify(params), params: JSON.stringify(params),
type type,
}) });
// prompt will be resolved with true or false // prompt will be resolved with true or false
let accept = await new Promise((resolve, reject) => { const accept = await new Promise((resolve, reject) => {
openPrompt = {resolve, reject} openPrompt = { resolve, reject };
const url = `${browser.runtime.getURL( const url = `${browser.runtime.getURL(
'prompt.html' "prompt.html",
)}?${qs.toString()}` )}?${qs.toString()}`;
if (browser.windows) { if (browser.windows) {
browser.windows.create({ browser.windows.create({
url, url,
type: 'popup', type: "popup",
width: 600, width: 600,
height: 600 height: 600,
}) });
} else { } else {
browser.tabs.create({ browser.tabs.create({
url, url,
active: true active: true,
}) });
} }
}) });
// denied, stop here // denied, stop here
if (!accept) return {error: 'denied'} if (!accept) return { error: "denied" };
} catch (err) { } catch (err) {
// errored, stop here // errored, stop here
releasePromptMutex() releasePromptMutex();
return { return {
error: `error: ${err}` error: `error: ${err}`,
} };
} }
} }
} }
// if we're here this means it was accepted // if we're here this means it was accepted
let results = await browser.storage.local.get('private_key') const results = await browser.storage.local.get("private_key");
if (!results || !results.private_key) { if (!results || !results.private_key) {
return {error: 'no private key found'} return { error: "no private key found" };
} }
let sk = results.private_key const sk = results.private_key;
try { try {
switch (type) { switch (type) {
case 'getPublicKey': { case "getPublicKey": {
return getPublicKey(sk) return getPublicKey(sk);
} }
case 'getRelays': { case "getRelays": {
let results = await browser.storage.local.get('relays') const results = await browser.storage.local.get("relays");
return results.relays || {} return results.relays || {};
} }
case 'signEvent': { case "signEvent": {
let {event} = params const { event } = params;
if (!event.pubkey) event.pubkey = getPublicKey(sk) if (!event.pubkey) event.pubkey = getPublicKey(sk);
if (!event.id) event.id = getEventHash(event) if (!event.id) event.id = getEventHash(event);
if (!validateEvent(event)) return {error: {message: 'invalid event'}} if (!validateEvent(event))
return { error: { message: "invalid event" } };
event.sig = await getSignature(event, sk) event.sig = await getSignature(event, sk);
return event return event;
} }
case 'nip04.encrypt': { case "nip04.encrypt": {
let {peer, plaintext} = params const { peer, plaintext } = params;
return encrypt(sk, peer, plaintext) return encrypt(sk, peer, plaintext);
} }
case 'nip04.decrypt': { case "nip04.decrypt": {
let {peer, ciphertext} = params const { peer, ciphertext } = params;
return decrypt(sk, peer, ciphertext) return decrypt(sk, peer, ciphertext);
} }
} }
} catch (error) { } catch (error) {
return {error: {message: error.message, stack: error.stack}} return { error: { message: error.message, stack: error.stack } };
} }
} }
async function handlePromptMessage({ host, type, accept, conditions }, sender) { async function handlePromptMessage({ host, type, accept, conditions }, sender) {
// return response // return response
openPrompt?.resolve?.(accept) openPrompt?.resolve?.(accept);
// update policies // update policies
if (conditions) { if (conditions) {
await updatePermission(host, type, accept, conditions) await updatePermission(host, type, accept, conditions);
} }
// cleanup this // cleanup this
openPrompt = null openPrompt = null;
// release mutex here after updating policies // release mutex here after updating policies
releasePromptMutex() releasePromptMutex();
// close prompt // close prompt
if (sender) { if (sender) {
if (browser.windows) { if (browser.windows) {
browser.windows.remove(sender.tab.windowId) browser.windows.remove(sender.tab.windowId);
} else { } else {
// Android Firefox // Android Firefox
browser.tabs.remove(sender.tab.id) browser.tabs.remove(sender.tab.id);
} }
} }
} }

1137
extension/build/style.css Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,116 +1,118 @@
import browser from 'webextension-polyfill' import browser from "webextension-polyfill";
export const NO_PERMISSIONS_REQUIRED = { export const NO_PERMISSIONS_REQUIRED = {
replaceURL: true replaceURL: true,
} };
export const PERMISSION_NAMES = Object.fromEntries([ export const PERMISSION_NAMES = Object.fromEntries([
['getPublicKey', 'read your public key'], ["getPublicKey", "read your public key"],
['getRelays', 'read your list of preferred relays'], ["getRelays", "read your list of preferred relays"],
['signEvent', 'sign events using your private key'], ["signEvent", "sign events using your private key"],
['nip04.encrypt', 'encrypt messages to peers'], ["nip04.encrypt", "encrypt messages to peers"],
['nip04.decrypt', 'decrypt messages from peers'] ["nip04.decrypt", "decrypt messages from peers"],
]) ]);
function matchConditions(conditions, event) { function matchConditions(conditions, event) {
if (conditions?.kinds) { if (conditions?.kinds) {
if (event.kind in conditions.kinds) return true if (event.kind in conditions.kinds) return true;
else return false else return false;
} }
return true return true;
} }
export async function getPermissionStatus(host, type, event) { export async function getPermissionStatus(host, type, event) {
let {policies} = await browser.storage.local.get('policies') const { policies } = await browser.storage.local.get("policies");
let answers = [true, false] const answers = [true, false];
for (let i = 0; i < answers.length; i++) { for (let i = 0; i < answers.length; i++) {
let accept = answers[i] const accept = answers[i];
let {conditions} = policies?.[host]?.[accept]?.[type] || {} const { conditions } = policies?.[host]?.[accept]?.[type] || {};
if (conditions) { if (conditions) {
if (type === 'signEvent') { if (type === "signEvent") {
if (matchConditions(conditions, event)) { if (matchConditions(conditions, event)) {
return accept // may be true or false return accept; // may be true or false
} else { } else {
// if this doesn't match we just continue so it will either match for the opposite answer (reject) // if this doesn't match we just continue so it will either match for the opposite answer (reject)
// or it will end up returning undefined at the end // or it will end up returning undefined at the end
continue // biome-ignore lint/correctness/noUnnecessaryContinue: <explanation>
continue;
} }
} else { } else {
return accept // may be true or false return accept; // may be true or false
} }
} }
} }
return undefined return undefined;
} }
export async function updatePermission(host, type, accept, conditions) { export async function updatePermission(host, type, accept, conditions) {
let {policies = {}} = await browser.storage.local.get('policies') const { policies = {} } = await browser.storage.local.get("policies");
// if the new conditions is "match everything", override the previous // if the new conditions is "match everything", override the previous
if (Object.keys(conditions).length === 0) { if (Object.keys(conditions).length === 0) {
conditions = {} conditions = {};
} else { } else {
// if we already had a policy for this, merge the conditions // if we already had a policy for this, merge the conditions
let existingConditions = policies[host]?.[accept]?.[type]?.conditions const existingConditions = policies[host]?.[accept]?.[type]?.conditions;
if (existingConditions) { if (existingConditions) {
if (existingConditions.kinds && conditions.kinds) { if (existingConditions.kinds && conditions.kinds) {
Object.keys(existingConditions.kinds).forEach(kind => { Object.keys(existingConditions.kinds).forEach((kind) => {
conditions.kinds[kind] = true conditions.kinds[kind] = true;
}) });
} }
} }
} }
// if we have a reverse policy (accept / reject) that is exactly equal to this, remove it // if we have a reverse policy (accept / reject) that is exactly equal to this, remove it
let other = !accept const other = !accept;
let reverse = policies?.[host]?.[other]?.[type] const reverse = policies?.[host]?.[other]?.[type];
if ( if (
reverse && reverse &&
JSON.stringify(reverse.conditions) === JSON.stringify(conditions) JSON.stringify(reverse.conditions) === JSON.stringify(conditions)
) { ) {
delete policies[host][other][type] delete policies[host][other][type];
} }
// insert our new policy // insert our new policy
policies[host] = policies[host] || {} policies[host] = policies[host] || {};
policies[host][accept] = policies[host][accept] || {} policies[host][accept] = policies[host][accept] || {};
policies[host][accept][type] = { policies[host][accept][type] = {
conditions, // filter that must match the event (in case of signEvent) conditions, // filter that must match the event (in case of signEvent)
created_at: Math.round(Date.now() / 1000) created_at: Math.round(Date.now() / 1000),
} };
browser.storage.local.set({policies}) browser.storage.local.set({ policies });
} }
export async function removePermissions(host, accept, type) { export async function removePermissions(host, accept, type) {
let {policies = {}} = await browser.storage.local.get('policies') const { policies = {} } = await browser.storage.local.get("policies");
delete policies[host]?.[accept]?.[type] delete policies[host]?.[accept]?.[type];
browser.storage.local.set({policies}) browser.storage.local.set({ policies });
} }
export async function showNotification(host, answer, type, params) { export async function showNotification(host, answer, type, params) {
let ok = await browser.storage.local.get('notifications') const ok = await browser.storage.local.get("notifications");
if (ok) { if (ok) {
let action = answer ? 'allowed' : 'denied' const action = answer ? "allowed" : "denied";
browser.notifications.create(undefined, { browser.notifications.create(undefined, {
type: 'basic', type: "basic",
title: `${type} ${action} for ${host}`, title: `${type} ${action} for ${host}`,
message: JSON.stringify( message: JSON.stringify(
params?.event params?.event
? { ? {
kind: params.event.kind, kind: params.event.kind,
content: params.event.content, content: params.event.content,
tags: params.event.tags tags: params.event.tags,
} }
: params, : params,
null, null,
2 2,
), ),
iconUrl: 'icons/48x48.png' iconUrl: "icons/48x48.png",
}) });
} }
} }

View File

@@ -1,36 +1,37 @@
import browser from 'webextension-polyfill' import browser from "webextension-polyfill";
const EXTENSION = 'nostrconnect' const EXTENSION = "nostrconnect";
// inject the script that will provide window.nostr // inject the script that will provide window.nostr
let script = document.createElement('script') const script = document.createElement("script");
script.setAttribute('async', 'false') script.setAttribute("async", "false");
script.setAttribute('type', 'text/javascript') script.setAttribute("type", "text/javascript");
script.setAttribute('src', browser.runtime.getURL('nostr-provider.js')) script.setAttribute("src", browser.runtime.getURL("nostr-provider.js"));
document.head.appendChild(script) document.head.appendChild(script);
// listen for messages from that script // listen for messages from that script
window.addEventListener('message', async message => { window.addEventListener("message", async (message) => {
if (message.source !== window) return if (message.source !== window) return;
if (!message.data) return if (!message.data) return;
if (!message.data.params) return if (!message.data.params) return;
if (message.data.ext !== EXTENSION) return if (message.data.ext !== EXTENSION) return;
// pass on to background // pass on to background
var response let response;
try { try {
response = await browser.runtime.sendMessage({ response = await browser.runtime.sendMessage({
type: message.data.type, type: message.data.type,
params: message.data.params, params: message.data.params,
host: location.host host: location.host,
}) });
} catch (error) { } catch (error) {
response = {error} response = { error };
} }
// return response // return response
window.postMessage( window.postMessage(
{ id: message.data.id, ext: EXTENSION, response }, { id: message.data.id, ext: EXTENSION, response },
message.origin message.origin,
) );
}) });

View File

@@ -1,4 +1,4 @@
import React from 'react' import React from "react";
export function LogoIcon() { export function LogoIcon() {
return ( return (
@@ -9,7 +9,7 @@ export function LogoIcon() {
fill="none" fill="none"
viewBox="0 0 56 56" viewBox="0 0 56 56"
> >
<rect width="56" height="56" fill="#EEECFD" rx="16"></rect> <rect width="56" height="56" fill="#EEECFD" rx="16" />
<rect <rect
width="55" width="55"
height="55" height="55"
@@ -18,7 +18,7 @@ export function LogoIcon() {
stroke="#5A41F4" stroke="#5A41F4"
strokeOpacity="0.25" strokeOpacity="0.25"
rx="15.5" rx="15.5"
></rect> />
<rect <rect
width="39" width="39"
height="39" height="39"
@@ -26,17 +26,10 @@ export function LogoIcon() {
y="8.5" y="8.5"
fill="url(#paint0_linear_24_2379)" fill="url(#paint0_linear_24_2379)"
rx="19.5" rx="19.5"
></rect> />
<rect <rect width="39" height="39" x="8.5" y="8.5" stroke="#6149F6" rx="19.5" />
width="39"
height="39"
x="8.5"
y="8.5"
stroke="#6149F6"
rx="19.5"
></rect>
<g fill="#fff" stroke="#6149F6" clipPath="url(#clip0_24_2379)"> <g fill="#fff" stroke="#6149F6" clipPath="url(#clip0_24_2379)">
<path d="M23.78 20.634l.408-.235-.21-.422a4.432 4.432 0 01-.458-1.797l-.031-.78-.696.355A11.533 11.533 0 0016.5 27.998h0V28c.002.87.103 1.738.302 2.585a3.525 3.525 0 102.843-1.058A8.377 8.377 0 0119.5 28a8.523 8.523 0 014.28-7.366zM36.5 28.023v.468l.467.03c.621.042 1.227.212 1.778.5l.687.36.044-.774.005-.075c.01-.166.02-.349.02-.532v-.001a11.524 11.524 0 00-8.142-10.99 3.526 3.526 0 10-.501 2.989A8.524 8.524 0 0136.5 28s0 0 0 0v.022zM33.185 32.622a3.49 3.49 0 00.311 1.844 8.442 8.442 0 01-9.766.877l-.407-.239-.262.392c-.343.514-.79.95-1.311 1.282l-.652.414.645.425a11.39 11.39 0 0014.092-1.23c.264.069.536.107.81.113h.01a3.5 3.5 0 002.803-5.6h.556l-1.603-.932a3.49 3.49 0 00-5.226 2.654z"></path> <path d="M23.78 20.634l.408-.235-.21-.422a4.432 4.432 0 01-.458-1.797l-.031-.78-.696.355A11.533 11.533 0 0016.5 27.998h0V28c.002.87.103 1.738.302 2.585a3.525 3.525 0 102.843-1.058A8.377 8.377 0 0119.5 28a8.523 8.523 0 014.28-7.366zM36.5 28.023v.468l.467.03c.621.042 1.227.212 1.778.5l.687.36.044-.774.005-.075c.01-.166.02-.349.02-.532v-.001a11.524 11.524 0 00-8.142-10.99 3.526 3.526 0 10-.501 2.989A8.524 8.524 0 0136.5 28s0 0 0 0v.022zM33.185 32.622a3.49 3.49 0 00.311 1.844 8.442 8.442 0 01-9.766.877l-.407-.239-.262.392c-.343.514-.79.95-1.311 1.282l-.652.414.645.425a11.39 11.39 0 0014.092-1.23c.264.069.536.107.81.113h.01a3.5 3.5 0 002.803-5.6h.556l-1.603-.932a3.49 3.49 0 00-5.226 2.654z" />
</g> </g>
<defs> <defs>
<linearGradient <linearGradient
@@ -47,19 +40,15 @@ export function LogoIcon() {
y2="48" y2="48"
gradientUnits="userSpaceOnUse" gradientUnits="userSpaceOnUse"
> >
<stop stopColor="#8E7CFF"></stop> <stop stopColor="#8E7CFF" />
<stop offset="1" stopColor="#5A41F4"></stop> <stop offset="1" stopColor="#5A41F4" />
</linearGradient> </linearGradient>
<clipPath id="clip0_24_2379"> <clipPath id="clip0_24_2379">
<path <path fill="#fff" d="M0 0H24V24H0z" transform="translate(16 15)" />
fill="#fff"
d="M0 0H24V24H0z"
transform="translate(16 15)"
></path>
</clipPath> </clipPath>
</defs> </defs>
</svg> </svg>
) );
} }
export function SettingsIcon(props) { export function SettingsIcon(props) {
@@ -83,5 +72,5 @@ export function SettingsIcon(props) {
d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
/> />
</svg> </svg>
) );
} }

View File

@@ -1,66 +1,61 @@
const EXTENSION = 'nostrconnect' const EXTENSION = "nostrconnect";
window.nostr = { window.nostr = {
_requests: {}, _requests: {},
_pubkey: null, _pubkey: null,
async getPublicKey() { async getPublicKey() {
if (this._pubkey) return this._pubkey if (this._pubkey) return this._pubkey;
this._pubkey = await this._call('getPublicKey', {}) this._pubkey = await this._call("getPublicKey", {});
return this._pubkey return this._pubkey;
}, },
async signEvent(event) { async signEvent(event) {
return this._call('signEvent', {event}) return this._call("signEvent", { event });
}, },
async getRelays() { async getRelays() {
return this._call('getRelays', {}) return this._call("getRelays", {});
}, },
nip04: { nip04: {
async encrypt(peer, plaintext) { async encrypt(peer, plaintext) {
return window.nostr._call('nip04.encrypt', {peer, plaintext}) return window.nostr._call("nip04.encrypt", { peer, plaintext });
}, },
async decrypt(peer, ciphertext) { async decrypt(peer, ciphertext) {
return window.nostr._call('nip04.decrypt', {peer, ciphertext}) return window.nostr._call("nip04.decrypt", { peer, ciphertext });
} },
}, },
_call(type, params) { _call(type, params) {
let id = Math.random().toString().slice(-4) const id = Math.random().toString().slice(-4);
console.log( console.log(
'%c[nostrconnect:%c' + `%c[nostrconnect:%c${id}%c]%c calling %c${type}%c with %c${JSON.stringify(params || {})}`,
id + "background-color:#f1b912;font-weight:bold;color:white",
'%c]%c calling %c' + "background-color:#f1b912;font-weight:bold;color:#a92727",
type + "background-color:#f1b912;color:white;font-weight:bold",
'%c with %c' + "color:auto",
JSON.stringify(params || {}), "font-weight:bold;color:#08589d;font-family:monospace",
'background-color:#f1b912;font-weight:bold;color:white', "color:auto",
'background-color:#f1b912;font-weight:bold;color:#a92727', "font-weight:bold;color:#90b12d;font-family:monospace",
'background-color:#f1b912;color:white;font-weight:bold', );
'color:auto',
'font-weight:bold;color:#08589d;font-family:monospace',
'color:auto',
'font-weight:bold;color:#90b12d;font-family:monospace'
)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this._requests[id] = {resolve, reject} this._requests[id] = { resolve, reject };
window.postMessage( window.postMessage(
{ {
id, id,
ext: EXTENSION, ext: EXTENSION,
type, type,
params params,
}, },
'*' "*",
) );
}) });
} },
} };
window.addEventListener('message', message => { window.addEventListener("message", (message) => {
if ( if (
!message.data || !message.data ||
message.data.response === null || message.data.response === null ||
@@ -68,47 +63,46 @@ window.addEventListener('message', message => {
message.data.ext !== EXTENSION || message.data.ext !== EXTENSION ||
!window.nostr._requests[message.data.id] !window.nostr._requests[message.data.id]
) )
return return;
if (message.data.response.error) { if (message.data.response.error) {
let error = new Error( const error = new Error(
`${EXTENSION}: ` + message.data.response.error.message `${EXTENSION}: ${message.data.response.error.message}`,
) );
error.stack = message.data.response.error.stack error.stack = message.data.response.error.stack;
window.nostr._requests[message.data.id].reject(error) window.nostr._requests[message.data.id].reject(error);
} else { } else {
window.nostr._requests[message.data.id].resolve(message.data.response) window.nostr._requests[message.data.id].resolve(message.data.response);
} }
console.log( console.log(
'%c[nostrconnect:%c' + `%c[nostrconnect:%c${message.data.id}%c]%c result: %c${JSON.stringify(
message.data.id + message?.data?.response || message?.data?.response?.error?.message || {},
'%c]%c result: %c' + )}`,
JSON.stringify( "background-color:#f1b912;font-weight:bold;color:white",
message?.data?.response || message?.data?.response?.error?.message || {} "background-color:#f1b912;font-weight:bold;color:#a92727",
), "background-color:#f1b912;color:white;font-weight:bold",
'background-color:#f1b912;font-weight:bold;color:white', "color:auto",
'background-color:#f1b912;font-weight:bold;color:#a92727', "font-weight:bold;color:#08589d",
'background-color:#f1b912;color:white;font-weight:bold', );
'color:auto',
'font-weight:bold;color:#08589d'
)
delete window.nostr._requests[message.data.id] delete window.nostr._requests[message.data.id];
}) });
// hack to replace nostr:nprofile.../etc links with something else // hack to replace nostr:nprofile.../etc links with something else
let replacing = null let replacing = null;
document.addEventListener('mousedown', replaceNostrSchemeLink) document.addEventListener("mousedown", replaceNostrSchemeLink);
async function replaceNostrSchemeLink(e) { async function replaceNostrSchemeLink(e) {
if (e.target.tagName !== 'A' || !e.target.href.startsWith('nostr:')) return if (e.target.tagName !== "A" || !e.target.href.startsWith("nostr:")) return;
if (replacing === false) return if (replacing === false) return;
let response = await window.nostr._call('replaceURL', {url: e.target.href}) const response = await window.nostr._call("replaceURL", {
url: e.target.href,
});
if (response === false) { if (response === false) {
replacing = false replacing = false;
return return;
} }
e.target.href = response e.target.href = response;
} }

View File

@@ -1,83 +1,87 @@
import browser from 'webextension-polyfill' import * as Checkbox from "@radix-ui/react-checkbox";
import React, {useState, useCallback, useEffect} from 'react' import * as Tabs from "@radix-ui/react-tabs";
import {render} from 'react-dom' import { generatePrivateKey, nip19 } from "nostr-tools";
import {generatePrivateKey, nip19} from 'nostr-tools' import React, { useState, useCallback, useEffect } from "react";
import QRCode from 'react-qr-code' import QRCode from "react-qr-code";
import * as Tabs from '@radix-ui/react-tabs' import browser from "webextension-polyfill";
import {LogoIcon} from './icons' import { removePermissions } from "./common";
import {removePermissions} from './common' import { LogoIcon } from "./icons";
import * as Checkbox from '@radix-ui/react-checkbox'
function Options() { function Options() {
let [privKey, setPrivKey] = useState('') const [privKey, setPrivKey] = useState("");
let [relays, setRelays] = useState([]) const [relays, setRelays] = useState([]);
let [newRelayURL, setNewRelayURL] = useState('') const [newRelayURL, setNewRelayURL] = useState("");
let [policies, setPermissions] = useState([]) const [policies, setPermissions] = useState([]);
let [protocolHandler, setProtocolHandler] = useState('https://njump.me/{raw}') const [protocolHandler, setProtocolHandler] = useState(
let [hidingPrivateKey, hidePrivateKey] = useState(true) "https://njump.me/{raw}",
let [showNotifications, setNotifications] = useState(false) );
let [messages, setMessages] = useState([]) const [hidingPrivateKey, hidePrivateKey] = useState(true);
let [handleNostrLinks, setHandleNostrLinks] = useState(false) const [showNotifications, setNotifications] = useState(false);
let [showProtocolHandlerHelp, setShowProtocolHandlerHelp] = useState(false) const [messages, setMessages] = useState([]);
let [unsavedChanges, setUnsavedChanges] = useState([]) const [handleNostrLinks, setHandleNostrLinks] = useState(false);
const [showProtocolHandlerHelp, setShowProtocolHandlerHelp] = useState(false);
const [unsavedChanges, setUnsavedChanges] = useState([]);
const showMessage = useCallback(msg => { const showMessage = useCallback((msg) => {
messages.push(msg) messages.push(msg);
setMessages(messages) setMessages(messages);
setTimeout(() => setMessages([]), 3000) setTimeout(() => setMessages([]), 3000);
}) });
useEffect(() => { useEffect(() => {
browser.storage.local browser.storage.local
.get(['private_key', 'relays', 'protocol_handler', 'notifications']) .get(["private_key", "relays", "protocol_handler", "notifications"])
.then(results => { .then((results) => {
if (results.private_key) { if (results.private_key) {
setPrivKey(nip19.nsecEncode(results.private_key)) setPrivKey(nip19.nsecEncode(results.private_key));
} }
if (results.relays) { if (results.relays) {
let relaysList = [] const relaysList = [];
for (let url in results.relays) { for (const url in results.relays) {
relaysList.push({ relaysList.push({
url, url,
policy: results.relays[url] policy: results.relays[url],
}) });
} }
setRelays(relaysList) setRelays(relaysList);
} }
if (results.protocol_handler) { if (results.protocol_handler) {
setProtocolHandler(results.protocol_handler) setProtocolHandler(results.protocol_handler);
setHandleNostrLinks(true) setHandleNostrLinks(true);
setShowProtocolHandlerHelp(false) setShowProtocolHandlerHelp(false);
} }
if (results.notifications) { if (results.notifications) {
setNotifications(true) setNotifications(true);
} }
}) });
}, []) }, []);
useEffect(() => { useEffect(() => {
loadPermissions() loadPermissions();
}, []) }, []);
async function loadPermissions() { async function loadPermissions() {
let {policies = {}} = await browser.storage.local.get('policies') const { policies = {} } = await browser.storage.local.get("policies");
let list = [] const list = [];
// biome-ignore lint/complexity/noForEach: TODO: fix this
Object.entries(policies).forEach(([host, accepts]) => { Object.entries(policies).forEach(([host, accepts]) => {
// biome-ignore lint/complexity/noForEach: TODO: fix this
Object.entries(accepts).forEach(([accept, types]) => { Object.entries(accepts).forEach(([accept, types]) => {
// biome-ignore lint/complexity/noForEach: TODO: fix this
Object.entries(types).forEach(([type, { conditions, created_at }]) => { Object.entries(types).forEach(([type, { conditions, created_at }]) => {
list.push({ list.push({
host, host,
type, type,
accept, accept,
conditions, conditions,
created_at created_at,
}) });
}) });
}) });
}) });
setPermissions(list) setPermissions(list);
} }
return ( return (
@@ -96,7 +100,7 @@ function Options() {
<div> <div>
<div className="flex gap-2"> <div className="flex gap-2">
<input <input
type={hidingPrivateKey ? 'password' : 'text'} type={hidingPrivateKey ? "password" : "text"}
value={privKey} value={privKey}
onChange={handleKeyChange} onChange={handleKeyChange}
className="flex-1 h-9 bg-transparent border border-primary px-3 py-1 rounded-lg" className="flex-1 h-9 bg-transparent border border-primary px-3 py-1 rounded-lg"
@@ -146,7 +150,7 @@ function Options() {
<QRCode <QRCode
size={256} size={256}
value={privKey.toUpperCase()} value={privKey.toUpperCase()}
viewBox={`0 0 256 256`} viewBox="0 0 256 256"
className="w-full max-w-full" className="w-full max-w-full"
/> />
</div> </div>
@@ -179,7 +183,7 @@ function Options() {
<div className="font-semibold text-base">Preferred Relays:</div> <div className="font-semibold text-base">Preferred Relays:</div>
<div className="flex flex-col gap-2"> <div className="flex flex-col gap-2">
{relays.map(({ url, policy }, i) => ( {relays.map(({ url, policy }, i) => (
<div key={i} className="flex items-center gap-4"> <div key={url} className="flex items-center gap-4">
<input <input
value={url} value={url}
onChange={changeRelayURL.bind(null, i)} onChange={changeRelayURL.bind(null, i)}
@@ -193,7 +197,7 @@ function Options() {
onCheckedChange={toggleRelayPolicy.bind( onCheckedChange={toggleRelayPolicy.bind(
null, null,
i, i,
'read' "read",
)} )}
className="flex h-6 w-6 appearance-none items-center justify-center rounded-lg bg-white outline-none border border-primary data-[state=checked]:bg-primary data-[state=checked]:border-secondary" className="flex h-6 w-6 appearance-none items-center justify-center rounded-lg bg-white outline-none border border-primary data-[state=checked]:bg-primary data-[state=checked]:border-secondary"
> >
@@ -228,7 +232,7 @@ function Options() {
onCheckedChange={toggleRelayPolicy.bind( onCheckedChange={toggleRelayPolicy.bind(
null, null,
i, i,
'write' "write",
)} )}
className="flex h-6 w-6 appearance-none items-center justify-center rounded-lg bg-white outline-none border border-primary data-[state=checked]:bg-primary data-[state=checked]:border-secondary" className="flex h-6 w-6 appearance-none items-center justify-center rounded-lg bg-white outline-none border border-primary data-[state=checked]:bg-primary data-[state=checked]:border-secondary"
> >
@@ -258,6 +262,7 @@ function Options() {
</div> </div>
</div> </div>
<button <button
type="button"
onClick={removeRelay.bind(null, i)} onClick={removeRelay.bind(null, i)}
className="shrink-0 px-3 w-24 h-9 font-semibold border border-primary shadow-sm rounded-lg inline-flex items-center justify-center disabled:text-muted" className="shrink-0 px-3 w-24 h-9 font-semibold border border-primary shadow-sm rounded-lg inline-flex items-center justify-center disabled:text-muted"
> >
@@ -268,14 +273,15 @@ function Options() {
<div className="flex gap-2"> <div className="flex gap-2">
<input <input
value={newRelayURL} value={newRelayURL}
onChange={e => setNewRelayURL(e.target.value)} onChange={(e) => setNewRelayURL(e.target.value)}
onKeyDown={e => { onKeyDown={(e) => {
if (e.key === 'Enter') addNewRelay() if (e.key === "Enter") addNewRelay();
}} }}
placeholder="wss://" placeholder="wss://"
className="flex-1 h-9 bg-transparent border px-3 py-1 border-primary rounded-lg placeholder:text-muted" className="flex-1 h-9 bg-transparent border px-3 py-1 border-primary rounded-lg placeholder:text-muted"
/> />
<button <button
type="button"
disabled={!newRelayURL} disabled={!newRelayURL}
onClick={addNewRelay} onClick={addNewRelay}
className="shrink-0 px-3 w-24 h-9 font-semibold border border-primary shadow-sm rounded-lg inline-flex items-center justify-center disabled:text-muted" className="shrink-0 px-3 w-24 h-9 font-semibold border border-primary shadow-sm rounded-lg inline-flex items-center justify-center disabled:text-muted"
@@ -312,7 +318,7 @@ function Options() {
<th className="text-left border-b-8 border-transparent"> <th className="text-left border-b-8 border-transparent">
Since Since
</th> </th>
<th></th> <th />
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -326,24 +332,25 @@ function Options() {
<td className="font-semibold">{host}</td> <td className="font-semibold">{host}</td>
<td className="text-muted">{type}</td> <td className="text-muted">{type}</td>
<td className="text-muted"> <td className="text-muted">
{accept === 'true' ? 'allow' : 'deny'} {accept === "true" ? "allow" : "deny"}
</td> </td>
<td className="text-muted"> <td className="text-muted">
{conditions.kinds {conditions.kinds
? `kinds: ${Object.keys(conditions.kinds).join( ? `kinds: ${Object.keys(conditions.kinds).join(
', ' ", ",
)}` )}`
: 'always'} : "always"}
</td> </td>
<td className="text-muted"> <td className="text-muted">
{new Date(created_at * 1000) {new Date(created_at * 1000)
.toISOString() .toISOString()
.split('.')[0] .split(".")[0]
.split('T') .split("T")
.join(' ')} .join(" ")}
</td> </td>
<td> <td>
<button <button
type="button"
onClick={handleRevoke} onClick={handleRevoke}
data-host={host} data-host={host}
data-accept={accept} data-accept={accept}
@@ -354,14 +361,14 @@ function Options() {
</button> </button>
</td> </td>
</tr> </tr>
) ),
)} )}
{!policies.length && ( {!policies.length && (
<tr> <tr>
{Array(5) {Array(5)
.fill('N/A') .fill("N/A")
.map((v, i) => ( .map((v) => (
<td key={i}>{v}</td> <td key={v}>{v}</td>
))} ))}
</tr> </tr>
)} )}
@@ -458,7 +465,10 @@ function Options() {
onChange={handleChangeProtocolHandler} onChange={handleChangeProtocolHandler}
/> />
{!showProtocolHandlerHelp && ( {!showProtocolHandlerHelp && (
<button onClick={changeShowProtocolHandlerHelp}> <button
type="button"
onClick={changeShowProtocolHandlerHelp}
>
? ?
</button> </button>
)} )}
@@ -487,6 +497,7 @@ examples:
</div> </div>
</div> </div>
<button <button
type="button"
disabled={!unsavedChanges.length} disabled={!unsavedChanges.length}
onClick={saveChanges} onClick={saveChanges}
className="w-full h-10 bg-primary rounded-xl font-bold inline-flex items-center justify-center text-white disabled:cursor-not-allowed disabled:opacity-70 transform active:translate-y-1 transition-transform ease-in-out duration-75" className="w-full h-10 bg-primary rounded-xl font-bold inline-flex items-center justify-center text-white disabled:cursor-not-allowed disabled:opacity-70 transform active:translate-y-1 transition-transform ease-in-out duration-75"
@@ -495,59 +506,59 @@ examples:
</button> </button>
</div> </div>
</div> </div>
) );
async function handleKeyChange(e) { async function handleKeyChange(e) {
let key = e.target.value.toLowerCase().trim() const key = e.target.value.toLowerCase().trim();
setPrivKey(key) setPrivKey(key);
addUnsavedChanges('private_key') addUnsavedChanges("private_key");
} }
async function generate() { async function generate() {
setPrivKey(nip19.nsecEncode(generatePrivateKey())) setPrivKey(nip19.nsecEncode(generatePrivateKey()));
addUnsavedChanges('private_key') addUnsavedChanges("private_key");
} }
async function saveKey() { async function saveKey() {
if (!isKeyValid()) { if (!isKeyValid()) {
showMessage('PRIVATE KEY IS INVALID! did not save private key.') showMessage("PRIVATE KEY IS INVALID! did not save private key.");
return return;
} }
let hexOrEmptyKey = privKey let hexOrEmptyKey = privKey;
try { try {
let {type, data} = nip19.decode(privKey) const { type, data } = nip19.decode(privKey);
if (type === 'nsec') hexOrEmptyKey = data if (type === "nsec") hexOrEmptyKey = data;
} catch (_) {} } catch (_) {}
await browser.storage.local.set({ await browser.storage.local.set({
private_key: hexOrEmptyKey private_key: hexOrEmptyKey,
}) });
if (hexOrEmptyKey !== '') { if (hexOrEmptyKey !== "") {
setPrivKey(nip19.nsecEncode(hexOrEmptyKey)) setPrivKey(nip19.nsecEncode(hexOrEmptyKey));
} }
showMessage('saved private key!') showMessage("saved private key!");
} }
function isKeyValid() { function isKeyValid() {
if (privKey === '') return true if (privKey === "") return true;
if (privKey.match(/^[a-f0-9]{64}$/)) return true if (privKey.match(/^[a-f0-9]{64}$/)) return true;
try { try {
if (nip19.decode(privKey).type === 'nsec') return true if (nip19.decode(privKey).type === "nsec") return true;
} catch (_) {} } catch (_) {}
return false return false;
} }
function changeRelayURL(i, ev) { function changeRelayURL(i, ev) {
setRelays([ setRelays([
...relays.slice(0, i), ...relays.slice(0, i),
{ url: ev.target.value, policy: relays[i].policy }, { url: ev.target.value, policy: relays[i].policy },
...relays.slice(i + 1) ...relays.slice(i + 1),
]) ]);
addUnsavedChanges('relays') addUnsavedChanges("relays");
} }
function toggleRelayPolicy(i, cat) { function toggleRelayPolicy(i, cat) {
@@ -555,122 +566,125 @@ examples:
...relays.slice(0, i), ...relays.slice(0, i),
{ {
url: relays[i].url, url: relays[i].url,
policy: {...relays[i].policy, [cat]: !relays[i].policy[cat]} policy: { ...relays[i].policy, [cat]: !relays[i].policy[cat] },
}, },
...relays.slice(i + 1) ...relays.slice(i + 1),
]) ]);
addUnsavedChanges('relays') addUnsavedChanges("relays");
} }
function removeRelay(i) { function removeRelay(i) {
setRelays([...relays.slice(0, i), ...relays.slice(i + 1)]) setRelays([...relays.slice(0, i), ...relays.slice(i + 1)]);
addUnsavedChanges('relays') addUnsavedChanges("relays");
} }
function addNewRelay() { function addNewRelay() {
if (newRelayURL.trim() === '') return if (newRelayURL.trim() === "") return;
if (!newRelayURL.startsWith('wss://')) return if (!newRelayURL.startsWith("wss://")) return;
relays.push({ relays.push({
url: newRelayURL, url: newRelayURL,
policy: {read: true, write: true} policy: { read: true, write: true },
}) });
setRelays(relays) setRelays(relays);
addUnsavedChanges('relays') addUnsavedChanges("relays");
setNewRelayURL('') setNewRelayURL("");
} }
async function handleRevoke(e) { async function handleRevoke(e) {
let {host, accept, type} = e.target.dataset const { host, accept, type } = e.target.dataset;
if ( if (
window.confirm( window.confirm(
`revoke all ${ `revoke all ${
accept === 'true' ? 'accept' : 'deny' accept === "true" ? "accept" : "deny"
} ${type} policies from ${host}?` } ${type} policies from ${host}?`,
) )
) { ) {
await removePermissions(host, accept, type) await removePermissions(host, accept, type);
showMessage('removed policies') showMessage("removed policies");
loadPermissions() loadPermissions();
} }
} }
function handleNotifications() { function handleNotifications() {
setNotifications(!showNotifications) setNotifications(!showNotifications);
addUnsavedChanges('notifications') addUnsavedChanges("notifications");
if (!showNotifications) requestBrowserNotificationPermissions() if (!showNotifications) requestBrowserNotificationPermissions();
} }
async function requestBrowserNotificationPermissions() { async function requestBrowserNotificationPermissions() {
let granted = await browser.permissions.request({ const granted = await browser.permissions.request({
permissions: ['notifications'] permissions: ["notifications"],
}) });
if (!granted) setNotifications(false) if (!granted) setNotifications(false);
} }
async function saveNotifications() { async function saveNotifications() {
await browser.storage.local.set({notifications: showNotifications}) await browser.storage.local.set({ notifications: showNotifications });
showMessage('saved notifications!') showMessage("saved notifications!");
} }
async function saveRelays() { async function saveRelays() {
await browser.storage.local.set({ await browser.storage.local.set({
relays: Object.fromEntries( relays: Object.fromEntries(
relays relays
.filter(({url}) => url.trim() !== '') .filter(({ url }) => url.trim() !== "")
.map(({url, policy}) => [url.trim(), policy]) .map(({ url, policy }) => [url.trim(), policy]),
) ),
}) });
showMessage('saved relays!') showMessage("saved relays!");
} }
function changeShowProtocolHandlerHelp() { function changeShowProtocolHandlerHelp() {
setShowProtocolHandlerHelp(true) setShowProtocolHandlerHelp(true);
} }
function changeHandleNostrLinks() { function changeHandleNostrLinks() {
if (handleNostrLinks) { if (handleNostrLinks) {
setProtocolHandler('') setProtocolHandler("");
addUnsavedChanges('protocol_handler') addUnsavedChanges("protocol_handler");
} else setShowProtocolHandlerHelp(true) } else setShowProtocolHandlerHelp(true);
setHandleNostrLinks(!handleNostrLinks) setHandleNostrLinks(!handleNostrLinks);
} }
function handleChangeProtocolHandler(e) { function handleChangeProtocolHandler(e) {
setProtocolHandler(e.target.value) setProtocolHandler(e.target.value);
addUnsavedChanges('protocol_handler') addUnsavedChanges("protocol_handler");
} }
async function saveNostrProtocolHandlerSettings() { async function saveNostrProtocolHandlerSettings() {
await browser.storage.local.set({protocol_handler: protocolHandler}) await browser.storage.local.set({ protocol_handler: protocolHandler });
showMessage('saved protocol handler!') showMessage("saved protocol handler!");
} }
function addUnsavedChanges(section) { function addUnsavedChanges(section) {
if (!unsavedChanges.find(s => s === section)) { if (!unsavedChanges.find((s) => s === section)) {
unsavedChanges.push(section) unsavedChanges.push(section);
setUnsavedChanges(unsavedChanges) setUnsavedChanges(unsavedChanges);
} }
} }
async function saveChanges() { async function saveChanges() {
for (let section of unsavedChanges) { for (const section of unsavedChanges) {
switch (section) { switch (section) {
case 'private_key': case "private_key":
await saveKey() await saveKey();
break break;
case 'relays': case "relays":
await saveRelays() await saveRelays();
break break;
case 'protocol_handler': case "protocol_handler":
await saveNostrProtocolHandlerSettings() await saveNostrProtocolHandlerSettings();
break break;
case 'notifications': case "notifications":
await saveNotifications() await saveNotifications();
break break;
} }
} }
setUnsavedChanges([]) setUnsavedChanges([]);
} }
} }
render(<Options />, document.getElementById('main')) const container = document.getElementById("main");
const root = createRoot(container);
root.render(<Options />);

File diff suppressed because it is too large Load Diff

View File

@@ -1,116 +1,118 @@
import browser from 'webextension-polyfill' import browser from "webextension-polyfill";
export const NO_PERMISSIONS_REQUIRED = { export const NO_PERMISSIONS_REQUIRED = {
replaceURL: true replaceURL: true,
} };
export const PERMISSION_NAMES = Object.fromEntries([ export const PERMISSION_NAMES = Object.fromEntries([
['getPublicKey', 'read your public key'], ["getPublicKey", "read your public key"],
['getRelays', 'read your list of preferred relays'], ["getRelays", "read your list of preferred relays"],
['signEvent', 'sign events using your private key'], ["signEvent", "sign events using your private key"],
['nip04.encrypt', 'encrypt messages to peers'], ["nip04.encrypt", "encrypt messages to peers"],
['nip04.decrypt', 'decrypt messages from peers'] ["nip04.decrypt", "decrypt messages from peers"],
]) ]);
function matchConditions(conditions, event) { function matchConditions(conditions, event) {
if (conditions?.kinds) { if (conditions?.kinds) {
if (event.kind in conditions.kinds) return true if (event.kind in conditions.kinds) return true;
else return false else return false;
} }
return true return true;
} }
export async function getPermissionStatus(host, type, event) { export async function getPermissionStatus(host, type, event) {
let {policies} = await browser.storage.local.get('policies') const { policies } = await browser.storage.local.get("policies");
let answers = [true, false] const answers = [true, false];
for (let i = 0; i < answers.length; i++) { for (let i = 0; i < answers.length; i++) {
let accept = answers[i] const accept = answers[i];
let {conditions} = policies?.[host]?.[accept]?.[type] || {} const { conditions } = policies?.[host]?.[accept]?.[type] || {};
if (conditions) { if (conditions) {
if (type === 'signEvent') { if (type === "signEvent") {
if (matchConditions(conditions, event)) { if (matchConditions(conditions, event)) {
return accept // may be true or false return accept; // may be true or false
} else { } else {
// if this doesn't match we just continue so it will either match for the opposite answer (reject) // if this doesn't match we just continue so it will either match for the opposite answer (reject)
// or it will end up returning undefined at the end // or it will end up returning undefined at the end
continue // biome-ignore lint/correctness/noUnnecessaryContinue: <explanation>
continue;
} }
} else { } else {
return accept // may be true or false return accept; // may be true or false
} }
} }
} }
return undefined return undefined;
} }
export async function updatePermission(host, type, accept, conditions) { export async function updatePermission(host, type, accept, conditions) {
let {policies = {}} = await browser.storage.local.get('policies') const { policies = {} } = await browser.storage.local.get("policies");
// if the new conditions is "match everything", override the previous // if the new conditions is "match everything", override the previous
if (Object.keys(conditions).length === 0) { if (Object.keys(conditions).length === 0) {
conditions = {} conditions = {};
} else { } else {
// if we already had a policy for this, merge the conditions // if we already had a policy for this, merge the conditions
let existingConditions = policies[host]?.[accept]?.[type]?.conditions const existingConditions = policies[host]?.[accept]?.[type]?.conditions;
if (existingConditions) { if (existingConditions) {
if (existingConditions.kinds && conditions.kinds) { if (existingConditions.kinds && conditions.kinds) {
Object.keys(existingConditions.kinds).forEach(kind => { Object.keys(existingConditions.kinds).forEach((kind) => {
conditions.kinds[kind] = true conditions.kinds[kind] = true;
}) });
} }
} }
} }
// if we have a reverse policy (accept / reject) that is exactly equal to this, remove it // if we have a reverse policy (accept / reject) that is exactly equal to this, remove it
let other = !accept const other = !accept;
let reverse = policies?.[host]?.[other]?.[type] const reverse = policies?.[host]?.[other]?.[type];
if ( if (
reverse && reverse &&
JSON.stringify(reverse.conditions) === JSON.stringify(conditions) JSON.stringify(reverse.conditions) === JSON.stringify(conditions)
) { ) {
delete policies[host][other][type] delete policies[host][other][type];
} }
// insert our new policy // insert our new policy
policies[host] = policies[host] || {} policies[host] = policies[host] || {};
policies[host][accept] = policies[host][accept] || {} policies[host][accept] = policies[host][accept] || {};
policies[host][accept][type] = { policies[host][accept][type] = {
conditions, // filter that must match the event (in case of signEvent) conditions, // filter that must match the event (in case of signEvent)
created_at: Math.round(Date.now() / 1000) created_at: Math.round(Date.now() / 1000),
} };
browser.storage.local.set({policies}) browser.storage.local.set({ policies });
} }
export async function removePermissions(host, accept, type) { export async function removePermissions(host, accept, type) {
let {policies = {}} = await browser.storage.local.get('policies') const { policies = {} } = await browser.storage.local.get("policies");
delete policies[host]?.[accept]?.[type] delete policies[host]?.[accept]?.[type];
browser.storage.local.set({policies}) browser.storage.local.set({ policies });
} }
export async function showNotification(host, answer, type, params) { export async function showNotification(host, answer, type, params) {
let ok = await browser.storage.local.get('notifications') const ok = await browser.storage.local.get("notifications");
if (ok) { if (ok) {
let action = answer ? 'allowed' : 'denied' const action = answer ? "allowed" : "denied";
browser.notifications.create(undefined, { browser.notifications.create(undefined, {
type: 'basic', type: "basic",
title: `${type} ${action} for ${host}`, title: `${type} ${action} for ${host}`,
message: JSON.stringify( message: JSON.stringify(
params?.event params?.event
? { ? {
kind: params.event.kind, kind: params.event.kind,
content: params.event.content, content: params.event.content,
tags: params.event.tags tags: params.event.tags,
} }
: params, : params,
null, null,
2 2,
), ),
iconUrl: 'icons/48x48.png' iconUrl: "icons/48x48.png",
}) });
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -3,12 +3,7 @@
"description": "Nostr Signer Extension", "description": "Nostr Signer Extension",
"version": "0.1.2", "version": "0.1.2",
"homepage_url": "https://github.com/reyamir/nostr-connect", "homepage_url": "https://github.com/reyamir/nostr-connect",
"manifest_version": 2, "manifest_version": 3,
"browser_specific_settings": {
"gecko": {
"id": "{e665d138-0e5b-4b7a-ab91-7af834eda7a2}"
}
},
"icons": { "icons": {
"16": "icons/icon16.png", "16": "icons/icon16.png",
"32": "icons/icon32.png", "32": "icons/icon32.png",
@@ -17,19 +12,25 @@
}, },
"options_page": "options.html", "options_page": "options.html",
"background": { "background": {
"scripts": ["background.build.js"] "service_worker": "background.build.js"
}, },
"browser_action": { "action": {
"default_title": "Nostr Connect", "default_title": "Nostr Connect",
"default_popup": "popup.html" "default_popup": "popup.html"
}, },
"content_scripts": [ "content_scripts": [
{ {
"matches": ["<all_urls>"], "matches": ["<all_urls>"],
"js": ["content-script.build.js"] "js": ["content-script.build.js"],
"all_frames": true
} }
], ],
"permissions": ["storage"], "permissions": ["storage"],
"optional_permissions": ["notifications"], "optional_permissions": ["notifications"],
"web_accessible_resources": ["nostr-provider.js"] "web_accessible_resources": [
{
"resources": ["nostr-provider.js"],
"matches": ["https://*/*", "http://localhost:*/*"]
}
]
} }

View File

@@ -1,66 +1,61 @@
const EXTENSION = 'nostrconnect' const EXTENSION = "nostrconnect";
window.nostr = { window.nostr = {
_requests: {}, _requests: {},
_pubkey: null, _pubkey: null,
async getPublicKey() { async getPublicKey() {
if (this._pubkey) return this._pubkey if (this._pubkey) return this._pubkey;
this._pubkey = await this._call('getPublicKey', {}) this._pubkey = await this._call("getPublicKey", {});
return this._pubkey return this._pubkey;
}, },
async signEvent(event) { async signEvent(event) {
return this._call('signEvent', {event}) return this._call("signEvent", { event });
}, },
async getRelays() { async getRelays() {
return this._call('getRelays', {}) return this._call("getRelays", {});
}, },
nip04: { nip04: {
async encrypt(peer, plaintext) { async encrypt(peer, plaintext) {
return window.nostr._call('nip04.encrypt', {peer, plaintext}) return window.nostr._call("nip04.encrypt", { peer, plaintext });
}, },
async decrypt(peer, ciphertext) { async decrypt(peer, ciphertext) {
return window.nostr._call('nip04.decrypt', {peer, ciphertext}) return window.nostr._call("nip04.decrypt", { peer, ciphertext });
} },
}, },
_call(type, params) { _call(type, params) {
let id = Math.random().toString().slice(-4) const id = Math.random().toString().slice(-4);
console.log( console.log(
'%c[nostrconnect:%c' + `%c[nostrconnect:%c${id}%c]%c calling %c${type}%c with %c${JSON.stringify(params || {})}`,
id + "background-color:#f1b912;font-weight:bold;color:white",
'%c]%c calling %c' + "background-color:#f1b912;font-weight:bold;color:#a92727",
type + "background-color:#f1b912;color:white;font-weight:bold",
'%c with %c' + "color:auto",
JSON.stringify(params || {}), "font-weight:bold;color:#08589d;font-family:monospace",
'background-color:#f1b912;font-weight:bold;color:white', "color:auto",
'background-color:#f1b912;font-weight:bold;color:#a92727', "font-weight:bold;color:#90b12d;font-family:monospace",
'background-color:#f1b912;color:white;font-weight:bold', );
'color:auto',
'font-weight:bold;color:#08589d;font-family:monospace',
'color:auto',
'font-weight:bold;color:#90b12d;font-family:monospace'
)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this._requests[id] = {resolve, reject} this._requests[id] = { resolve, reject };
window.postMessage( window.postMessage(
{ {
id, id,
ext: EXTENSION, ext: EXTENSION,
type, type,
params params,
}, },
'*' "*",
) );
}) });
} },
} };
window.addEventListener('message', message => { window.addEventListener("message", (message) => {
if ( if (
!message.data || !message.data ||
message.data.response === null || message.data.response === null ||
@@ -68,47 +63,46 @@ window.addEventListener('message', message => {
message.data.ext !== EXTENSION || message.data.ext !== EXTENSION ||
!window.nostr._requests[message.data.id] !window.nostr._requests[message.data.id]
) )
return return;
if (message.data.response.error) { if (message.data.response.error) {
let error = new Error( const error = new Error(
`${EXTENSION}: ` + message.data.response.error.message `${EXTENSION}: ${message.data.response.error.message}`,
) );
error.stack = message.data.response.error.stack error.stack = message.data.response.error.stack;
window.nostr._requests[message.data.id].reject(error) window.nostr._requests[message.data.id].reject(error);
} else { } else {
window.nostr._requests[message.data.id].resolve(message.data.response) window.nostr._requests[message.data.id].resolve(message.data.response);
} }
console.log( console.log(
'%c[nostrconnect:%c' + `%c[nostrconnect:%c${message.data.id}%c]%c result: %c${JSON.stringify(
message.data.id + message?.data?.response || message?.data?.response?.error?.message || {},
'%c]%c result: %c' + )}`,
JSON.stringify( "background-color:#f1b912;font-weight:bold;color:white",
message?.data?.response || message?.data?.response?.error?.message || {} "background-color:#f1b912;font-weight:bold;color:#a92727",
), "background-color:#f1b912;color:white;font-weight:bold",
'background-color:#f1b912;font-weight:bold;color:white', "color:auto",
'background-color:#f1b912;font-weight:bold;color:#a92727', "font-weight:bold;color:#08589d",
'background-color:#f1b912;color:white;font-weight:bold', );
'color:auto',
'font-weight:bold;color:#08589d'
)
delete window.nostr._requests[message.data.id] delete window.nostr._requests[message.data.id];
}) });
// hack to replace nostr:nprofile.../etc links with something else // hack to replace nostr:nprofile.../etc links with something else
let replacing = null let replacing = null;
document.addEventListener('mousedown', replaceNostrSchemeLink) document.addEventListener("mousedown", replaceNostrSchemeLink);
async function replaceNostrSchemeLink(e) { async function replaceNostrSchemeLink(e) {
if (e.target.tagName !== 'A' || !e.target.href.startsWith('nostr:')) return if (e.target.tagName !== "A" || !e.target.href.startsWith("nostr:")) return;
if (replacing === false) return if (replacing === false) return;
let response = await window.nostr._call('replaceURL', {url: e.target.href}) const response = await window.nostr._call("replaceURL", {
url: e.target.href,
});
if (response === false) { if (response === false) {
replacing = false replacing = false;
return return;
} }
e.target.href = response e.target.href = response;
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -1,58 +1,56 @@
import browser from 'webextension-polyfill' import * as Tabs from "@radix-ui/react-tabs";
import {render} from 'react-dom' import { minidenticon } from "minidenticons";
import {getPublicKey, nip19} from 'nostr-tools' import { getPublicKey, nip19 } from "nostr-tools";
import React, {useState, useMemo, useEffect} from 'react' import React, { useState, useMemo, useEffect } from "react";
import QRCode from 'react-qr-code' import QRCode from "react-qr-code";
import {SettingsIcon} from './icons' import browser from "webextension-polyfill";
import {minidenticon} from 'minidenticons' import { SettingsIcon } from "./icons";
import * as Tabs from '@radix-ui/react-tabs'
function Popup() { function Popup() {
let [keys, setKeys] = useState(null) const [keys, setKeys] = useState(null);
let avatarURI = useMemo( const avatarURI = useMemo(
() => () =>
keys keys
? 'data:image/svg+xml;utf8,' + ? `data:image/svg+xml;utf8,${encodeURIComponent(minidenticon(keys.npub, 90, 30))}`
encodeURIComponent(minidenticon(keys.npub, 90, 30))
: null, : null,
[keys] [keys],
) );
const gotoSettings = () => { const gotoSettings = () => {
browser.tabs.create({ browser.tabs.create({
url: browser.runtime.getURL('/options.html') url: browser.runtime.getURL("/options.html"),
}) });
} };
useEffect(() => { useEffect(() => {
browser.storage.local.get(['private_key', 'relays']).then(results => { browser.storage.local.get(["private_key", "relays"]).then((results) => {
if (results.private_key) { if (results.private_key) {
let hexKey = getPublicKey(results.private_key) const hexKey = getPublicKey(results.private_key);
let npubKey = nip19.npubEncode(hexKey) const npubKey = nip19.npubEncode(hexKey);
setKeys({npub: npubKey, hex: hexKey}) setKeys({ npub: npubKey, hex: hexKey });
if (results.relays) { if (results.relays) {
let relaysList = [] const relaysList = [];
for (let url in results.relays) { for (const url in results.relays) {
if (results.relays[url].write) { if (results.relays[url].write) {
relaysList.push(url) relaysList.push(url);
if (relaysList.length >= 3) break if (relaysList.length >= 3) break;
} }
} }
if (relaysList.length) { if (relaysList.length) {
let nprofileKey = nip19.nprofileEncode({ const nprofileKey = nip19.nprofileEncode({
pubkey: hexKey, pubkey: hexKey,
relays: relaysList relays: relaysList,
}) });
setKeys(prev => ({...prev, nprofile: nprofileKey})) setKeys((prev) => ({ ...prev, nprofile: nprofileKey }));
} }
} }
} else { } else {
setKeys(null) setKeys(null);
} }
}) });
}, []) }, []);
return ( return (
<div className="w-[320px] p-6"> <div className="w-[320px] p-6">
@@ -94,6 +92,7 @@ function Popup() {
{avatarURI ? ( {avatarURI ? (
<img <img
src={avatarURI} src={avatarURI}
alt="Avatar"
className="w-9 h-9 rounded-full bg-muted" className="w-9 h-9 rounded-full bg-muted"
/> />
) : ( ) : (
@@ -176,7 +175,10 @@ function Popup() {
</div> </div>
)} )}
</div> </div>
) );
} }
render(<Popup />, document.getElementById('main')) const container = document.getElementById("main");
const root = createRoot(container);
root.render(<Popup />);

View File

@@ -1,41 +1,41 @@
import browser from 'webextension-polyfill' import React, { useState } from "react";
import {render} from 'react-dom' import browser from "webextension-polyfill";
import React, {useState} from 'react' import * as Checkbox from "@radix-ui/react-checkbox";
import { PERMISSION_NAMES } from "./common";
import {PERMISSION_NAMES} from './common' import { LogoIcon } from "./icons";
import {LogoIcon} from './icons'
import * as Checkbox from '@radix-ui/react-checkbox'
function Prompt() { function Prompt() {
const [isRemember, setIsRemember] = useState(false) const [isRemember, setIsRemember] = useState(false);
let qs = new URLSearchParams(location.search) const qs = new URLSearchParams(location.search);
let id = qs.get('id') const id = qs.get("id");
let host = qs.get('host') const host = qs.get("host");
let type = qs.get('type') const type = qs.get("type");
let params, event
let params;
let event;
try { try {
params = JSON.parse(qs.get('params')) params = JSON.parse(qs.get("params"));
if (Object.keys(params).length === 0) params = null if (Object.keys(params).length === 0) params = null;
else if (params.event) event = params.event else if (params.event) event = params.event;
} catch (err) { } catch (err) {
params = null params = null;
} }
function authorizeHandler(accept) { function authorizeHandler(accept) {
const conditions = isRemember ? {} : null const conditions = isRemember ? {} : null;
return function (ev) { return (ev) => {
ev.preventDefault() ev.preventDefault();
browser.runtime.sendMessage({ browser.runtime.sendMessage({
prompt: true, prompt: true,
id, id,
host, host,
type, type,
accept, accept,
conditions conditions,
}) });
} };
} }
return ( return (
@@ -88,12 +88,14 @@ function Prompt() {
</div> </div>
<div className="flex gap-3"> <div className="flex gap-3">
<button <button
type="button"
onClick={authorizeHandler(false)} onClick={authorizeHandler(false)}
className="flex-1 h-10 rounded-lg shadow-sm border border-primary inline-flex items-center justify-center font-semibold" className="flex-1 h-10 rounded-lg shadow-sm border border-primary inline-flex items-center justify-center font-semibold"
> >
Reject Reject
</button> </button>
<button <button
type="button"
onClick={authorizeHandler(true)} onClick={authorizeHandler(true)}
className="flex-1 h-10 rounded-lg shadow-sm border border-secondary bg-primary text-white inline-flex items-center justify-center font-semibold" className="flex-1 h-10 rounded-lg shadow-sm border border-secondary bg-primary text-white inline-flex items-center justify-center font-semibold"
> >
@@ -101,65 +103,12 @@ function Prompt() {
</button> </button>
</div> </div>
</div> </div>
{/*
<div
style={{
display: 'flex',
flexWrap: 'wrap',
justifyContent: 'space-around'
}}
>
<button
style={{marginTop: '5px'}}
onClick={authorizeHandler(
true,
{} // store this and answer true forever
)}
>
authorize forever
</button>
{event?.kind !== undefined && (
<button
style={{marginTop: '5px'}}
onClick={authorizeHandler(
true,
{kinds: {[event.kind]: true}} // store and always answer true for all events that match this condition
)}
>
authorize kind {event.kind} forever
</button>
)}
<button style={{marginTop: '5px'}} onClick={authorizeHandler(true)}>
authorize just this
</button>
{event?.kind !== undefined ? (
<button
style={{marginTop: '5px'}}
onClick={authorizeHandler(
false,
{kinds: {[event.kind]: true}} // idem
)}
>
reject kind {event.kind} forever
</button>
) : (
<button
style={{marginTop: '5px'}}
onClick={authorizeHandler(
false,
{} // idem
)}
>
reject forever
</button>
)}
<button style={{marginTop: '5px'}} onClick={authorizeHandler(false)}>
reject
</button>
</div>*/}
</div> </div>
</div> </div>
) );
} }
render(<Prompt />, document.getElementById('main')) const container = document.getElementById("main");
const root = createRoot(container);
root.render(<Prompt />);

View File

@@ -2,6 +2,6 @@
@tailwind components; @tailwind components;
@tailwind utilities; @tailwind utilities;
.data-\[state\=active\]\:text-primary[data-state=active] > .bg-muted { .data-\[state\=active\]\:text-primary[data-state="active"] > .bg-muted {
@apply bg-secondary @apply bg-secondary;
} }

View File

@@ -5,20 +5,16 @@
"@radix-ui/react-tabs": "^1.1.2", "@radix-ui/react-tabs": "^1.1.2",
"async-mutex": "^0.3.2", "async-mutex": "^0.3.2",
"esbuild": "^0.14.54", "esbuild": "^0.14.54",
"eslint": "^8.57.1",
"eslint-plugin-babel": "^5.3.1",
"eslint-plugin-react": "^7.37.2",
"events": "^3.3.0", "events": "^3.3.0",
"minidenticons": "^4.2.1", "minidenticons": "^4.2.1",
"nostr-tools": "^1.17.0", "nostr-tools": "^2.10.4",
"prettier": "^2.8.8", "react": "^19.0.0",
"react": "^17.0.2", "react-dom": "^19.0.0",
"react-dom": "^17.0.2",
"react-native-svg": "^13.14.1", "react-native-svg": "^13.14.1",
"react-qr-code": "^2.0.15", "react-qr-code": "^2.0.15",
"use-boolean-state": "^1.0.2", "use-boolean-state": "^1.0.2",
"use-debounce": "^7.0.1", "use-debounce": "^7.0.1",
"webextension-polyfill": "^0.8.0" "webextension-polyfill": "^0.12.0"
}, },
"scripts": { "scripts": {
"dev": "./build.js; pnpm exec tailwindcss -i ./extension/style.css -o ./extension/build/style.css --watch", "dev": "./build.js; pnpm exec tailwindcss -i ./extension/style.css -o ./extension/build/style.css --watch",
@@ -27,6 +23,8 @@
"package:firefox": "pnpm exec tailwindcss -i ./extension/style.css -o ./extension/output/style.css --minify; ./build.js prod firefox; cd extension/output; zip -r archive *; cd ../../; mv extension/output/archive.zip extension/releases/nostrconnect_firefox.xpi" "package:firefox": "pnpm exec tailwindcss -i ./extension/style.css -o ./extension/output/style.css --minify; ./build.js prod firefox; cd extension/output; zip -r archive *; cd ../../; mv extension/output/archive.zip extension/releases/nostrconnect_firefox.xpi"
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "1.9.4",
"@types/webextension-polyfill": "^0.12.1",
"esbuild-plugin-copy": "^2.1.1", "esbuild-plugin-copy": "^2.1.1",
"tailwindcss": "^3.4.17" "tailwindcss": "^3.4.17"
} }

1847
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff