From 5ebd0d2ef43a929506ecd45033442e9fe96885a7 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Thu, 7 Sep 2023 11:32:40 +0530 Subject: [PATCH 01/12] feat: webln:enabled event --- src/extension/content-script/webln.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/extension/content-script/webln.js b/src/extension/content-script/webln.js index d119c06001..54e048b35a 100644 --- a/src/extension/content-script/webln.js +++ b/src/extension/content-script/webln.js @@ -93,6 +93,8 @@ async function init() { // if it is the enable call we store if webln is enabled for this content script if (ev.data.action === "webln/enable") { isEnabled = response.data?.enabled; + const enabledEvent = new Event("webln:enabled"); + window.dispatchEvent(enabledEvent); if (response.error) { console.error(response.error); console.info("Enable was rejected ignoring further webln calls"); From 2d5008d82c09ef96148a81da6f65697e5df7d84a Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Thu, 7 Sep 2023 14:40:54 +0530 Subject: [PATCH 02/12] feat: onboarding for lnurl-auth --- src/app/router/Prompt/Prompt.tsx | 1 + src/extension/background-script/router.ts | 1 + src/extension/content-script/webln.js | 10 +++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/app/router/Prompt/Prompt.tsx b/src/app/router/Prompt/Prompt.tsx index ca93228fcf..db1433d25d 100644 --- a/src/app/router/Prompt/Prompt.tsx +++ b/src/app/router/Prompt/Prompt.tsx @@ -130,6 +130,7 @@ function Prompt() { } /> } /> } /> + } /> } diff --git a/src/extension/background-script/router.ts b/src/extension/background-script/router.ts index ed63b54de8..0c1ef3dbcf 100644 --- a/src/extension/background-script/router.ts +++ b/src/extension/background-script/router.ts @@ -94,6 +94,7 @@ const routes = { addAccount: accounts.promptAdd, }, webln: { + onboard: onboard.prompt, enable: allowances.enable, getInfo: ln.getInfo, sendPaymentOrPrompt: webln.sendPaymentOrPrompt, diff --git a/src/extension/content-script/webln.js b/src/extension/content-script/webln.js index d119c06001..baf70496d7 100644 --- a/src/extension/content-script/webln.js +++ b/src/extension/content-script/webln.js @@ -1,5 +1,6 @@ import browser from "webextension-polyfill"; +import api from "~/common/lib/api"; import extractLightningData from "./batteries"; import getOriginData from "./originData"; import shouldInject from "./shouldInject"; @@ -49,7 +50,7 @@ async function init() { // message listener to listen to inpage webln/webbtc calls // those calls get passed on to the background script // (the inpage script can not do that directly, but only the inpage script can make webln available to the page) - window.addEventListener("message", (ev) => { + window.addEventListener("message", async (ev) => { // Only accept messages from the current window if ( ev.source !== window || @@ -89,6 +90,13 @@ async function init() { origin: getOriginData(), }; + // Overrides the enable action so the user can go through onboarding to setup their keys + + const account = await api.getAccount(); + if (ev.data.action === "webln/lnurl" && !account.hasMnemonic) { + messageWithOrigin.action = ev.data.action = `public/webln/onboard`; + } + const replyFunction = (response) => { // if it is the enable call we store if webln is enabled for this content script if (ev.data.action === "webln/enable") { From 6779b4a257f93995b0f1757188efd9e92f100fe1 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Fri, 8 Sep 2023 17:26:07 +0700 Subject: [PATCH 03/12] fix: show nsec format in nostr settings page --- .../screens/Accounts/NostrSettings/index.tsx | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/app/screens/Accounts/NostrSettings/index.tsx b/src/app/screens/Accounts/NostrSettings/index.tsx index 7e09f54b6f..8b0be95a51 100644 --- a/src/app/screens/Accounts/NostrSettings/index.tsx +++ b/src/app/screens/Accounts/NostrSettings/index.tsx @@ -11,7 +11,7 @@ import PasswordViewAdornment from "~/app/components/PasswordViewAdornment"; import toast from "~/app/components/Toast"; import TextField from "~/app/components/form/TextField"; import api, { GetAccountRes } from "~/common/lib/api"; -import { default as nostr, default as nostrlib } from "~/common/lib/nostr"; +import { default as nostr } from "~/common/lib/nostr"; function NostrSettings() { const { t: tCommon } = useTranslation("common"); @@ -21,6 +21,7 @@ function NostrSettings() { const navigate = useNavigate(); const [hasMnemonic, setHasMnemonic] = useState(false); const [currentPrivateKey, setCurrentPrivateKey] = useState(""); + const [currentNsec, setCurrentNsec] = useState(""); const [nostrPrivateKey, setNostrPrivateKey] = useState(""); const [nostrPrivateKeyVisible, setNostrPrivateKeyVisible] = useState(false); const [nostrPublicKey, setNostrPublicKey] = useState(""); @@ -33,7 +34,9 @@ function NostrSettings() { const priv = await api.nostr.getPrivateKey(id); if (priv) { setCurrentPrivateKey(priv); - setNostrPrivateKey(priv); + const nsec = nostr.hexToNip19(priv); + setCurrentNsec(nsec); + setNostrPrivateKey(nsec); } const accountResponse = await api.getAccount(id); setHasMnemonic(accountResponse.hasMnemonic); @@ -82,12 +85,15 @@ function NostrSettings() { } const derivedNostrPrivateKey = await api.nostr.generatePrivateKey(id); - setNostrPrivateKey(derivedNostrPrivateKey); + setNostrPrivateKey(nostr.hexToNip19(derivedNostrPrivateKey)); } + const keyUnchanged = + nostrPrivateKey === currentPrivateKey || nostrPrivateKey === currentNsec; + // TODO: simplify this method - would be good to have a dedicated "remove nostr key" button async function handleSaveNostrPrivateKey() { - if (nostrPrivateKey === currentPrivateKey) { + if (keyUnchanged) { throw new Error("private key hasn't changed"); } @@ -165,9 +171,7 @@ function NostrSettings() { )} - {hasMnemonic && - currentPrivateKey && - nostrPrivateKey === currentPrivateKey ? ( + {hasMnemonic && currentPrivateKey && keyUnchanged ? ( hasImportedNostrKey ? ( {t("nostr.settings.imported_key_warning")} @@ -216,15 +220,13 @@ function NostrSettings() { onClick={handleDeleteKeys} /> )} - {hasImportedNostrKey && - nostrPrivateKey === currentPrivateKey && - hasMnemonic && ( -