From eb0e11407d51dee2d63e281298ff93c7b27d54ee Mon Sep 17 00:00:00 2001 From: Brandon Lucas <38222767+thebrandonlucas@users.noreply.github.com> Date: Fri, 12 Apr 2024 18:18:31 -0400 Subject: [PATCH 01/14] feat: add ability to decode signet --- src/app/screens/ConfirmPayment/index.tsx | 8 +++++++- src/app/screens/Send/index.tsx | 8 +++++++- src/common/utils/paymentRequest.ts | 8 +++++++- .../background-script/actions/ln/sendPayment.ts | 8 +++++++- .../actions/webln/sendPaymentOrPrompt.ts | 11 ++++++++--- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/app/screens/ConfirmPayment/index.tsx b/src/app/screens/ConfirmPayment/index.tsx index de55ee54cb..7adc597c14 100644 --- a/src/app/screens/ConfirmPayment/index.tsx +++ b/src/app/screens/ConfirmPayment/index.tsx @@ -35,7 +35,13 @@ function ConfirmPayment() { const navState = useNavigationState(); const paymentRequest = navState.args?.paymentRequest as string; - const invoice = lightningPayReq.decode(paymentRequest); + const signet = { + bech32: "tbs", + pubKeyHash: 0x6f, + scriptHash: 0xc4, + validWitnessVersions: [0], + }; + const invoice = lightningPayReq.decode(paymentRequest, signet); const navigate = useNavigate(); const auth = useAccount(); diff --git a/src/app/screens/Send/index.tsx b/src/app/screens/Send/index.tsx index 3cec8c95e2..eb5b9be14b 100644 --- a/src/app/screens/Send/index.tsx +++ b/src/app/screens/Send/index.tsx @@ -96,7 +96,13 @@ function Send() { state: { args: { bitcoinAddress: invoice } }, }); } else { - lightningPayReq.decode(invoice); // throws if invalid. + const signet = { + bech32: "tbs", + pubKeyHash: 0x6f, + scriptHash: 0xc4, + validWitnessVersions: [0], + }; + lightningPayReq.decode(invoice, signet); // throws if invalid. navigate("/confirmPayment", { state: { args: { diff --git a/src/common/utils/paymentRequest.ts b/src/common/utils/paymentRequest.ts index acc5d0c3d3..6be755f6ba 100644 --- a/src/common/utils/paymentRequest.ts +++ b/src/common/utils/paymentRequest.ts @@ -1,7 +1,13 @@ import lightningPayReq from "bolt11"; export function getPaymentRequestDescription(paymentRequest: string): string { - const decodedPaymentRequest = lightningPayReq.decode(paymentRequest); + const signet = { + bech32: "tbs", + pubKeyHash: 0x6f, + scriptHash: 0xc4, + validWitnessVersions: [0], + }; + const decodedPaymentRequest = lightningPayReq.decode(paymentRequest, signet); const descriptionTag = decodedPaymentRequest.tags.find( (tag) => tag.tagName === "description" ); diff --git a/src/extension/background-script/actions/ln/sendPayment.ts b/src/extension/background-script/actions/ln/sendPayment.ts index 0e74892635..0c12922950 100644 --- a/src/extension/background-script/actions/ln/sendPayment.ts +++ b/src/extension/background-script/actions/ln/sendPayment.ts @@ -28,7 +28,13 @@ export default async function sendPayment( let response, paymentRequestDetails; try { - paymentRequestDetails = lightningPayReq.decode(paymentRequest); + const signet = { + bech32: "tbs", + pubKeyHash: 0x6f, + scriptHash: 0xc4, + validWitnessVersions: [0], + }; + paymentRequestDetails = lightningPayReq.decode(paymentRequest, signet); response = await connector.sendPayment({ paymentRequest, diff --git a/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts b/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts index 48a22752e6..a7ee7097c8 100644 --- a/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts +++ b/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts @@ -16,8 +16,13 @@ const sendPaymentOrPrompt = async (message: Message, sender: Sender) => { error: "Payment request missing.", }; } - - const paymentRequestDetails = lightningPayReq.decode(paymentRequest); + const signet = { + bech32: "tbs", + pubKeyHash: 0x6f, + scriptHash: 0xc4, + validWitnessVersions: [0], + }; + const paymentRequestDetails = lightningPayReq.decode(paymentRequest, signet); if (await checkAllowance(host, paymentRequestDetails.satoshis || 0)) { return sendPaymentWithAllowance(message); } else { @@ -61,4 +66,4 @@ async function payWithPrompt(message: Message) { } } -export { sendPaymentOrPrompt, payWithPrompt, checkAllowance }; +export { checkAllowance, payWithPrompt, sendPaymentOrPrompt }; From 3326358777469732bedaed08c8a6a5bf4c669388 Mon Sep 17 00:00:00 2001 From: Brandon Lucas <38222767+thebrandonlucas@users.noreply.github.com> Date: Mon, 22 Apr 2024 16:04:25 -0400 Subject: [PATCH 02/14] feat(mutinynet): use single function for invoice parsing --- .vscode/settings.json | 3 ++- src/app/screens/ConfirmPayment/index.test.tsx | 4 +-- src/app/screens/ConfirmPayment/index.tsx | 11 +++----- src/app/screens/ConfirmPaymentAsync/index.tsx | 4 +-- src/app/screens/Send/index.tsx | 15 +++++------ src/app/utils/index.ts | 27 ++++++++++++++++++- src/common/utils/paymentRequest.ts | 10 ++----- .../actions/ln/sendPayment.ts | 10 ++----- .../actions/webln/sendPaymentOrPrompt.ts | 11 +++----- src/types.ts | 7 +++++ 10 files changed, 55 insertions(+), 47 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 3d4368bcbc..5150ba577b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,6 @@ "source.organizeImports": "explicit" }, "typescript.preferences.importModuleSpecifier": "non-relative", - "editor.defaultFormatter": "esbenp.prettier-vscode" + "editor.defaultFormatter": "esbenp.prettier-vscode", + "i18n-ally.localesPaths": ["src/i18n", "src/i18n/locales"] } diff --git a/src/app/screens/ConfirmPayment/index.test.tsx b/src/app/screens/ConfirmPayment/index.test.tsx index 36c3ca9a68..4a78f66adb 100644 --- a/src/app/screens/ConfirmPayment/index.test.tsx +++ b/src/app/screens/ConfirmPayment/index.test.tsx @@ -1,10 +1,10 @@ import { act, render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import lightningPayReq from "bolt11"; import { MemoryRouter } from "react-router-dom"; import { settingsFixture as mockSettings } from "~/../tests/fixtures/settings"; import type { OriginData } from "~/types"; +import { decodeLightningInvoice } from "~/app/utils"; import ConfirmPayment from "./index"; const mockOrigin: OriginData = { @@ -104,7 +104,7 @@ describe("ConfirmPayment", () => { ); }); - const satoshis = lightningPayReq.decode(paymentRequest).satoshis || 0; + const satoshis = decodeLightningInvoice(paymentRequest).satoshis || 0; expect(await screen.findByText(`${satoshis} sats`)).toBeInTheDocument(); diff --git a/src/app/screens/ConfirmPayment/index.tsx b/src/app/screens/ConfirmPayment/index.tsx index 7adc597c14..086b961fd1 100644 --- a/src/app/screens/ConfirmPayment/index.tsx +++ b/src/app/screens/ConfirmPayment/index.tsx @@ -5,7 +5,6 @@ import Container from "@components/Container"; import PaymentSummary from "@components/PaymentSummary"; import PublisherCard from "@components/PublisherCard"; import ResultCard from "@components/ResultCard"; -import lightningPayReq from "bolt11"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; @@ -14,6 +13,7 @@ import toast from "~/app/components/Toast"; import { useAccount } from "~/app/context/AccountContext"; import { useSettings } from "~/app/context/SettingsContext"; import { useNavigationState } from "~/app/hooks/useNavigationState"; +import { decodeLightningInvoice } from "~/app/utils"; import { USER_REJECTED_ERROR } from "~/common/constants"; import api from "~/common/lib/api"; import msg from "~/common/lib/msg"; @@ -35,13 +35,8 @@ function ConfirmPayment() { const navState = useNavigationState(); const paymentRequest = navState.args?.paymentRequest as string; - const signet = { - bech32: "tbs", - pubKeyHash: 0x6f, - scriptHash: 0xc4, - validWitnessVersions: [0], - }; - const invoice = lightningPayReq.decode(paymentRequest, signet); + + const invoice = decodeLightningInvoice(paymentRequest); const navigate = useNavigate(); const auth = useAccount(); diff --git a/src/app/screens/ConfirmPaymentAsync/index.tsx b/src/app/screens/ConfirmPaymentAsync/index.tsx index a825a24431..3dacb2b6df 100644 --- a/src/app/screens/ConfirmPaymentAsync/index.tsx +++ b/src/app/screens/ConfirmPaymentAsync/index.tsx @@ -2,7 +2,6 @@ import ConfirmOrCancel from "@components/ConfirmOrCancel"; import Container from "@components/Container"; import PaymentSummary from "@components/PaymentSummary"; import PublisherCard from "@components/PublisherCard"; -import lightningPayReq from "bolt11"; import { useEffect, useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; @@ -12,6 +11,7 @@ import ScreenHeader from "~/app/components/ScreenHeader"; import toast from "~/app/components/Toast"; import { useSettings } from "~/app/context/SettingsContext"; import { useNavigationState } from "~/app/hooks/useNavigationState"; +import { decodeLightningInvoice } from "~/app/utils"; import { USER_REJECTED_ERROR } from "~/common/constants"; import api from "~/common/lib/api"; import msg from "~/common/lib/msg"; @@ -31,7 +31,7 @@ function ConfirmPaymentAsync() { const navState = useNavigationState(); const paymentRequest = navState.args?.paymentRequest as string; - const invoice = lightningPayReq.decode(paymentRequest); + const invoice = decodeLightningInvoice(paymentRequest); const navigate = useNavigate(); diff --git a/src/app/screens/Send/index.tsx b/src/app/screens/Send/index.tsx index eb5b9be14b..6a8ebded95 100644 --- a/src/app/screens/Send/index.tsx +++ b/src/app/screens/Send/index.tsx @@ -4,13 +4,16 @@ import Header from "@components/Header"; import IconButton from "@components/IconButton"; import TextField from "@components/form/TextField"; import { PopiconsChevronLeftLine } from "@popicons/react"; -import lightningPayReq from "bolt11"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useLocation, useNavigate } from "react-router-dom"; import QrcodeAdornment from "~/app/components/QrcodeAdornment"; import toast from "~/app/components/Toast"; -import { extractLightningTagData, isBitcoinAddress } from "~/app/utils"; +import { + decodeLightningInvoice, + extractLightningTagData, + isBitcoinAddress, +} from "~/app/utils"; import lnurlLib from "~/common/lib/lnurl"; import { isLNURLDetailsError } from "~/common/utils/typeHelpers"; @@ -96,13 +99,7 @@ function Send() { state: { args: { bitcoinAddress: invoice } }, }); } else { - const signet = { - bech32: "tbs", - pubKeyHash: 0x6f, - scriptHash: 0xc4, - validWitnessVersions: [0], - }; - lightningPayReq.decode(invoice, signet); // throws if invalid. + decodeLightningInvoice(invoice); // throws if invalid. navigate("/confirmPayment", { state: { args: { diff --git a/src/app/utils/index.ts b/src/app/utils/index.ts index f4ef1d2914..e9d04a798c 100644 --- a/src/app/utils/index.ts +++ b/src/app/utils/index.ts @@ -1,7 +1,8 @@ import { GetAccountInformationResponse } from "@getalby/sdk/dist/types"; +import lightningPayReq from "bolt11"; import { useSettings } from "~/app/context/SettingsContext"; import api from "~/common/lib/api"; -import { BrowserType, Theme } from "~/types"; +import { BrowserType, CustomNetwork, Theme } from "~/types"; export function classNames(...classes: (string | boolean)[]) { return classes.filter(Boolean).join(" "); @@ -83,3 +84,27 @@ export function extractLightningTagData(url: string) { return url.replace(/^lightning:/i, ""); } } + +export function decodeLightningInvoice( + invoice: string, + customNetwork?: CustomNetwork +) { + try { + return lightningPayReq.decode(invoice); + } catch (e) { + const err = e as Error; + // NOTE: is there a way to get network for the current account from here? + // This catch-and-rethrow is a workaround for us not having the network + const mutinynet = { + bech32: "tbs", + pubKeyHash: 0x6f, + scriptHash: 0xc4, + validWitnessVersions: [0], + }; + if (err.message === "Unknown coin bech32 prefix") { + return lightningPayReq.decode(invoice, customNetwork ?? mutinynet); + } else { + throw e; + } + } +} diff --git a/src/common/utils/paymentRequest.ts b/src/common/utils/paymentRequest.ts index 6be755f6ba..9a53c1b626 100644 --- a/src/common/utils/paymentRequest.ts +++ b/src/common/utils/paymentRequest.ts @@ -1,13 +1,7 @@ -import lightningPayReq from "bolt11"; +import { decodeLightningInvoice } from "~/app/utils"; export function getPaymentRequestDescription(paymentRequest: string): string { - const signet = { - bech32: "tbs", - pubKeyHash: 0x6f, - scriptHash: 0xc4, - validWitnessVersions: [0], - }; - const decodedPaymentRequest = lightningPayReq.decode(paymentRequest, signet); + const decodedPaymentRequest = decodeLightningInvoice(paymentRequest); const descriptionTag = decodedPaymentRequest.tags.find( (tag) => tag.tagName === "description" ); diff --git a/src/extension/background-script/actions/ln/sendPayment.ts b/src/extension/background-script/actions/ln/sendPayment.ts index 0c12922950..21ea95b7f9 100644 --- a/src/extension/background-script/actions/ln/sendPayment.ts +++ b/src/extension/background-script/actions/ln/sendPayment.ts @@ -1,5 +1,5 @@ -import lightningPayReq from "bolt11"; import PubSub from "pubsub-js"; +import { decodeLightningInvoice } from "~/app/utils"; import pubsub from "~/common/lib/pubsub"; import state from "~/extension/background-script/state"; import { Message, MessageSendPayment } from "~/types"; @@ -28,13 +28,7 @@ export default async function sendPayment( let response, paymentRequestDetails; try { - const signet = { - bech32: "tbs", - pubKeyHash: 0x6f, - scriptHash: 0xc4, - validWitnessVersions: [0], - }; - paymentRequestDetails = lightningPayReq.decode(paymentRequest, signet); + paymentRequestDetails = decodeLightningInvoice(paymentRequest); response = await connector.sendPayment({ paymentRequest, diff --git a/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts b/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts index a7ee7097c8..ba1e6aa4ff 100644 --- a/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts +++ b/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts @@ -1,8 +1,8 @@ -import lightningPayReq from "bolt11"; import utils from "~/common/lib/utils"; import { getHostFromSender } from "~/common/utils/helpers"; import { Message, Sender } from "~/types"; +import { decodeLightningInvoice } from "~/app/utils"; import db from "../../db"; import sendPayment from "../ln/sendPayment"; @@ -16,13 +16,8 @@ const sendPaymentOrPrompt = async (message: Message, sender: Sender) => { error: "Payment request missing.", }; } - const signet = { - bech32: "tbs", - pubKeyHash: 0x6f, - scriptHash: 0xc4, - validWitnessVersions: [0], - }; - const paymentRequestDetails = lightningPayReq.decode(paymentRequest, signet); + + const paymentRequestDetails = decodeLightningInvoice(paymentRequest); if (await checkAllowance(host, paymentRequestDetails.satoshis || 0)) { return sendPaymentWithAllowance(message); } else { diff --git a/src/types.ts b/src/types.ts index 2062a20270..5b2a377a5b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -16,6 +16,13 @@ export type BitcoinNetworkType = "bitcoin" | "testnet" | "regtest"; export type LiquidNetworkType = "liquid" | "testnet" | "regtest"; +export type CustomNetwork = { + bech32: string; + pubKeyHash: number; + scriptHash: number; + validWitnessVersions: number[]; +}; + export interface Account { id: string; connector: ConnectorType; From 8ee3dee39b459ba2eec65152197b0c03cda19e21 Mon Sep 17 00:00:00 2001 From: Brandon Lucas <38222767+thebrandonlucas@users.noreply.github.com> Date: Mon, 22 Apr 2024 16:16:28 -0400 Subject: [PATCH 03/14] feat(mutinynet): cleanup --- src/app/utils/index.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/app/utils/index.ts b/src/app/utils/index.ts index e9d04a798c..184e056c67 100644 --- a/src/app/utils/index.ts +++ b/src/app/utils/index.ts @@ -92,16 +92,13 @@ export function decodeLightningInvoice( try { return lightningPayReq.decode(invoice); } catch (e) { - const err = e as Error; - // NOTE: is there a way to get network for the current account from here? - // This catch-and-rethrow is a workaround for us not having the network const mutinynet = { bech32: "tbs", pubKeyHash: 0x6f, scriptHash: 0xc4, validWitnessVersions: [0], }; - if (err.message === "Unknown coin bech32 prefix") { + if ((e as Error).message === "Unknown coin bech32 prefix") { return lightningPayReq.decode(invoice, customNetwork ?? mutinynet); } else { throw e; From 0eab68a54623abafe84e511a542888fb7425639b Mon Sep 17 00:00:00 2001 From: Brandon Lucas <38222767+thebrandonlucas@users.noreply.github.com> Date: Tue, 23 Apr 2024 07:58:56 -0400 Subject: [PATCH 04/14] feat(mutinynet): remove comment --- src/app/screens/Send/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/screens/Send/index.tsx b/src/app/screens/Send/index.tsx index 6a8ebded95..52d799c487 100644 --- a/src/app/screens/Send/index.tsx +++ b/src/app/screens/Send/index.tsx @@ -99,7 +99,7 @@ function Send() { state: { args: { bitcoinAddress: invoice } }, }); } else { - decodeLightningInvoice(invoice); // throws if invalid. + decodeLightningInvoice(invoice); navigate("/confirmPayment", { state: { args: { From 25adb6b4bedae5365e3147c09ea26e5202a95b0c Mon Sep 17 00:00:00 2001 From: Brandon Lucas <38222767+thebrandonlucas@users.noreply.github.com> Date: Tue, 23 Apr 2024 22:41:06 -0400 Subject: [PATCH 05/14] Revert "feat(mutinynet): remove comment" This reverts commit 0eab68a54623abafe84e511a542888fb7425639b. --- src/app/screens/Send/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/screens/Send/index.tsx b/src/app/screens/Send/index.tsx index 52d799c487..6a8ebded95 100644 --- a/src/app/screens/Send/index.tsx +++ b/src/app/screens/Send/index.tsx @@ -99,7 +99,7 @@ function Send() { state: { args: { bitcoinAddress: invoice } }, }); } else { - decodeLightningInvoice(invoice); + decodeLightningInvoice(invoice); // throws if invalid. navigate("/confirmPayment", { state: { args: { From abf7e881bceb61391179efa1bc9532c7674da25b Mon Sep 17 00:00:00 2001 From: Brandon Lucas <38222767+thebrandonlucas@users.noreply.github.com> Date: Tue, 23 Apr 2024 22:49:33 -0400 Subject: [PATCH 06/14] Revert "feat(mutinynet): cleanup" This reverts commit 8ee3dee39b459ba2eec65152197b0c03cda19e21. --- src/app/utils/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/utils/index.ts b/src/app/utils/index.ts index 184e056c67..e9d04a798c 100644 --- a/src/app/utils/index.ts +++ b/src/app/utils/index.ts @@ -92,13 +92,16 @@ export function decodeLightningInvoice( try { return lightningPayReq.decode(invoice); } catch (e) { + const err = e as Error; + // NOTE: is there a way to get network for the current account from here? + // This catch-and-rethrow is a workaround for us not having the network const mutinynet = { bech32: "tbs", pubKeyHash: 0x6f, scriptHash: 0xc4, validWitnessVersions: [0], }; - if ((e as Error).message === "Unknown coin bech32 prefix") { + if (err.message === "Unknown coin bech32 prefix") { return lightningPayReq.decode(invoice, customNetwork ?? mutinynet); } else { throw e; From 53d1be82ad641be84f735792024ea397346061ed Mon Sep 17 00:00:00 2001 From: Brandon Lucas <38222767+thebrandonlucas@users.noreply.github.com> Date: Tue, 23 Apr 2024 22:49:35 -0400 Subject: [PATCH 07/14] Revert "feat(mutinynet): use single function for invoice parsing" This reverts commit 3326358777469732bedaed08c8a6a5bf4c669388. --- .vscode/settings.json | 3 +-- src/app/screens/ConfirmPayment/index.test.tsx | 4 +-- src/app/screens/ConfirmPayment/index.tsx | 11 +++++--- src/app/screens/ConfirmPaymentAsync/index.tsx | 4 +-- src/app/screens/Send/index.tsx | 15 ++++++----- src/app/utils/index.ts | 27 +------------------ src/common/utils/paymentRequest.ts | 10 +++++-- .../actions/ln/sendPayment.ts | 10 +++++-- .../actions/webln/sendPaymentOrPrompt.ts | 11 +++++--- src/types.ts | 7 ----- 10 files changed, 47 insertions(+), 55 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5150ba577b..3d4368bcbc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,5 @@ "source.organizeImports": "explicit" }, "typescript.preferences.importModuleSpecifier": "non-relative", - "editor.defaultFormatter": "esbenp.prettier-vscode", - "i18n-ally.localesPaths": ["src/i18n", "src/i18n/locales"] + "editor.defaultFormatter": "esbenp.prettier-vscode" } diff --git a/src/app/screens/ConfirmPayment/index.test.tsx b/src/app/screens/ConfirmPayment/index.test.tsx index 4a78f66adb..36c3ca9a68 100644 --- a/src/app/screens/ConfirmPayment/index.test.tsx +++ b/src/app/screens/ConfirmPayment/index.test.tsx @@ -1,10 +1,10 @@ import { act, render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; +import lightningPayReq from "bolt11"; import { MemoryRouter } from "react-router-dom"; import { settingsFixture as mockSettings } from "~/../tests/fixtures/settings"; import type { OriginData } from "~/types"; -import { decodeLightningInvoice } from "~/app/utils"; import ConfirmPayment from "./index"; const mockOrigin: OriginData = { @@ -104,7 +104,7 @@ describe("ConfirmPayment", () => { ); }); - const satoshis = decodeLightningInvoice(paymentRequest).satoshis || 0; + const satoshis = lightningPayReq.decode(paymentRequest).satoshis || 0; expect(await screen.findByText(`${satoshis} sats`)).toBeInTheDocument(); diff --git a/src/app/screens/ConfirmPayment/index.tsx b/src/app/screens/ConfirmPayment/index.tsx index 086b961fd1..7adc597c14 100644 --- a/src/app/screens/ConfirmPayment/index.tsx +++ b/src/app/screens/ConfirmPayment/index.tsx @@ -5,6 +5,7 @@ import Container from "@components/Container"; import PaymentSummary from "@components/PaymentSummary"; import PublisherCard from "@components/PublisherCard"; import ResultCard from "@components/ResultCard"; +import lightningPayReq from "bolt11"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; @@ -13,7 +14,6 @@ import toast from "~/app/components/Toast"; import { useAccount } from "~/app/context/AccountContext"; import { useSettings } from "~/app/context/SettingsContext"; import { useNavigationState } from "~/app/hooks/useNavigationState"; -import { decodeLightningInvoice } from "~/app/utils"; import { USER_REJECTED_ERROR } from "~/common/constants"; import api from "~/common/lib/api"; import msg from "~/common/lib/msg"; @@ -35,8 +35,13 @@ function ConfirmPayment() { const navState = useNavigationState(); const paymentRequest = navState.args?.paymentRequest as string; - - const invoice = decodeLightningInvoice(paymentRequest); + const signet = { + bech32: "tbs", + pubKeyHash: 0x6f, + scriptHash: 0xc4, + validWitnessVersions: [0], + }; + const invoice = lightningPayReq.decode(paymentRequest, signet); const navigate = useNavigate(); const auth = useAccount(); diff --git a/src/app/screens/ConfirmPaymentAsync/index.tsx b/src/app/screens/ConfirmPaymentAsync/index.tsx index 3dacb2b6df..a825a24431 100644 --- a/src/app/screens/ConfirmPaymentAsync/index.tsx +++ b/src/app/screens/ConfirmPaymentAsync/index.tsx @@ -2,6 +2,7 @@ import ConfirmOrCancel from "@components/ConfirmOrCancel"; import Container from "@components/Container"; import PaymentSummary from "@components/PaymentSummary"; import PublisherCard from "@components/PublisherCard"; +import lightningPayReq from "bolt11"; import { useEffect, useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; @@ -11,7 +12,6 @@ import ScreenHeader from "~/app/components/ScreenHeader"; import toast from "~/app/components/Toast"; import { useSettings } from "~/app/context/SettingsContext"; import { useNavigationState } from "~/app/hooks/useNavigationState"; -import { decodeLightningInvoice } from "~/app/utils"; import { USER_REJECTED_ERROR } from "~/common/constants"; import api from "~/common/lib/api"; import msg from "~/common/lib/msg"; @@ -31,7 +31,7 @@ function ConfirmPaymentAsync() { const navState = useNavigationState(); const paymentRequest = navState.args?.paymentRequest as string; - const invoice = decodeLightningInvoice(paymentRequest); + const invoice = lightningPayReq.decode(paymentRequest); const navigate = useNavigate(); diff --git a/src/app/screens/Send/index.tsx b/src/app/screens/Send/index.tsx index 6a8ebded95..eb5b9be14b 100644 --- a/src/app/screens/Send/index.tsx +++ b/src/app/screens/Send/index.tsx @@ -4,16 +4,13 @@ import Header from "@components/Header"; import IconButton from "@components/IconButton"; import TextField from "@components/form/TextField"; import { PopiconsChevronLeftLine } from "@popicons/react"; +import lightningPayReq from "bolt11"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useLocation, useNavigate } from "react-router-dom"; import QrcodeAdornment from "~/app/components/QrcodeAdornment"; import toast from "~/app/components/Toast"; -import { - decodeLightningInvoice, - extractLightningTagData, - isBitcoinAddress, -} from "~/app/utils"; +import { extractLightningTagData, isBitcoinAddress } from "~/app/utils"; import lnurlLib from "~/common/lib/lnurl"; import { isLNURLDetailsError } from "~/common/utils/typeHelpers"; @@ -99,7 +96,13 @@ function Send() { state: { args: { bitcoinAddress: invoice } }, }); } else { - decodeLightningInvoice(invoice); // throws if invalid. + const signet = { + bech32: "tbs", + pubKeyHash: 0x6f, + scriptHash: 0xc4, + validWitnessVersions: [0], + }; + lightningPayReq.decode(invoice, signet); // throws if invalid. navigate("/confirmPayment", { state: { args: { diff --git a/src/app/utils/index.ts b/src/app/utils/index.ts index e9d04a798c..f4ef1d2914 100644 --- a/src/app/utils/index.ts +++ b/src/app/utils/index.ts @@ -1,8 +1,7 @@ import { GetAccountInformationResponse } from "@getalby/sdk/dist/types"; -import lightningPayReq from "bolt11"; import { useSettings } from "~/app/context/SettingsContext"; import api from "~/common/lib/api"; -import { BrowserType, CustomNetwork, Theme } from "~/types"; +import { BrowserType, Theme } from "~/types"; export function classNames(...classes: (string | boolean)[]) { return classes.filter(Boolean).join(" "); @@ -84,27 +83,3 @@ export function extractLightningTagData(url: string) { return url.replace(/^lightning:/i, ""); } } - -export function decodeLightningInvoice( - invoice: string, - customNetwork?: CustomNetwork -) { - try { - return lightningPayReq.decode(invoice); - } catch (e) { - const err = e as Error; - // NOTE: is there a way to get network for the current account from here? - // This catch-and-rethrow is a workaround for us not having the network - const mutinynet = { - bech32: "tbs", - pubKeyHash: 0x6f, - scriptHash: 0xc4, - validWitnessVersions: [0], - }; - if (err.message === "Unknown coin bech32 prefix") { - return lightningPayReq.decode(invoice, customNetwork ?? mutinynet); - } else { - throw e; - } - } -} diff --git a/src/common/utils/paymentRequest.ts b/src/common/utils/paymentRequest.ts index 9a53c1b626..6be755f6ba 100644 --- a/src/common/utils/paymentRequest.ts +++ b/src/common/utils/paymentRequest.ts @@ -1,7 +1,13 @@ -import { decodeLightningInvoice } from "~/app/utils"; +import lightningPayReq from "bolt11"; export function getPaymentRequestDescription(paymentRequest: string): string { - const decodedPaymentRequest = decodeLightningInvoice(paymentRequest); + const signet = { + bech32: "tbs", + pubKeyHash: 0x6f, + scriptHash: 0xc4, + validWitnessVersions: [0], + }; + const decodedPaymentRequest = lightningPayReq.decode(paymentRequest, signet); const descriptionTag = decodedPaymentRequest.tags.find( (tag) => tag.tagName === "description" ); diff --git a/src/extension/background-script/actions/ln/sendPayment.ts b/src/extension/background-script/actions/ln/sendPayment.ts index 21ea95b7f9..0c12922950 100644 --- a/src/extension/background-script/actions/ln/sendPayment.ts +++ b/src/extension/background-script/actions/ln/sendPayment.ts @@ -1,5 +1,5 @@ +import lightningPayReq from "bolt11"; import PubSub from "pubsub-js"; -import { decodeLightningInvoice } from "~/app/utils"; import pubsub from "~/common/lib/pubsub"; import state from "~/extension/background-script/state"; import { Message, MessageSendPayment } from "~/types"; @@ -28,7 +28,13 @@ export default async function sendPayment( let response, paymentRequestDetails; try { - paymentRequestDetails = decodeLightningInvoice(paymentRequest); + const signet = { + bech32: "tbs", + pubKeyHash: 0x6f, + scriptHash: 0xc4, + validWitnessVersions: [0], + }; + paymentRequestDetails = lightningPayReq.decode(paymentRequest, signet); response = await connector.sendPayment({ paymentRequest, diff --git a/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts b/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts index ba1e6aa4ff..a7ee7097c8 100644 --- a/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts +++ b/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts @@ -1,8 +1,8 @@ +import lightningPayReq from "bolt11"; import utils from "~/common/lib/utils"; import { getHostFromSender } from "~/common/utils/helpers"; import { Message, Sender } from "~/types"; -import { decodeLightningInvoice } from "~/app/utils"; import db from "../../db"; import sendPayment from "../ln/sendPayment"; @@ -16,8 +16,13 @@ const sendPaymentOrPrompt = async (message: Message, sender: Sender) => { error: "Payment request missing.", }; } - - const paymentRequestDetails = decodeLightningInvoice(paymentRequest); + const signet = { + bech32: "tbs", + pubKeyHash: 0x6f, + scriptHash: 0xc4, + validWitnessVersions: [0], + }; + const paymentRequestDetails = lightningPayReq.decode(paymentRequest, signet); if (await checkAllowance(host, paymentRequestDetails.satoshis || 0)) { return sendPaymentWithAllowance(message); } else { diff --git a/src/types.ts b/src/types.ts index 5b2a377a5b..2062a20270 100644 --- a/src/types.ts +++ b/src/types.ts @@ -16,13 +16,6 @@ export type BitcoinNetworkType = "bitcoin" | "testnet" | "regtest"; export type LiquidNetworkType = "liquid" | "testnet" | "regtest"; -export type CustomNetwork = { - bech32: string; - pubKeyHash: number; - scriptHash: number; - validWitnessVersions: number[]; -}; - export interface Account { id: string; connector: ConnectorType; From baf439de8782412bc2e8a1f3f4ae80446e6e0c03 Mon Sep 17 00:00:00 2001 From: Brandon Lucas <38222767+thebrandonlucas@users.noreply.github.com> Date: Tue, 23 Apr 2024 22:49:36 -0400 Subject: [PATCH 08/14] Revert "feat: add ability to decode signet" This reverts commit eb0e11407d51dee2d63e281298ff93c7b27d54ee. --- src/app/screens/ConfirmPayment/index.tsx | 8 +------- src/app/screens/Send/index.tsx | 8 +------- src/common/utils/paymentRequest.ts | 8 +------- .../background-script/actions/ln/sendPayment.ts | 8 +------- .../actions/webln/sendPaymentOrPrompt.ts | 11 +++-------- 5 files changed, 7 insertions(+), 36 deletions(-) diff --git a/src/app/screens/ConfirmPayment/index.tsx b/src/app/screens/ConfirmPayment/index.tsx index 7adc597c14..de55ee54cb 100644 --- a/src/app/screens/ConfirmPayment/index.tsx +++ b/src/app/screens/ConfirmPayment/index.tsx @@ -35,13 +35,7 @@ function ConfirmPayment() { const navState = useNavigationState(); const paymentRequest = navState.args?.paymentRequest as string; - const signet = { - bech32: "tbs", - pubKeyHash: 0x6f, - scriptHash: 0xc4, - validWitnessVersions: [0], - }; - const invoice = lightningPayReq.decode(paymentRequest, signet); + const invoice = lightningPayReq.decode(paymentRequest); const navigate = useNavigate(); const auth = useAccount(); diff --git a/src/app/screens/Send/index.tsx b/src/app/screens/Send/index.tsx index eb5b9be14b..3cec8c95e2 100644 --- a/src/app/screens/Send/index.tsx +++ b/src/app/screens/Send/index.tsx @@ -96,13 +96,7 @@ function Send() { state: { args: { bitcoinAddress: invoice } }, }); } else { - const signet = { - bech32: "tbs", - pubKeyHash: 0x6f, - scriptHash: 0xc4, - validWitnessVersions: [0], - }; - lightningPayReq.decode(invoice, signet); // throws if invalid. + lightningPayReq.decode(invoice); // throws if invalid. navigate("/confirmPayment", { state: { args: { diff --git a/src/common/utils/paymentRequest.ts b/src/common/utils/paymentRequest.ts index 6be755f6ba..acc5d0c3d3 100644 --- a/src/common/utils/paymentRequest.ts +++ b/src/common/utils/paymentRequest.ts @@ -1,13 +1,7 @@ import lightningPayReq from "bolt11"; export function getPaymentRequestDescription(paymentRequest: string): string { - const signet = { - bech32: "tbs", - pubKeyHash: 0x6f, - scriptHash: 0xc4, - validWitnessVersions: [0], - }; - const decodedPaymentRequest = lightningPayReq.decode(paymentRequest, signet); + const decodedPaymentRequest = lightningPayReq.decode(paymentRequest); const descriptionTag = decodedPaymentRequest.tags.find( (tag) => tag.tagName === "description" ); diff --git a/src/extension/background-script/actions/ln/sendPayment.ts b/src/extension/background-script/actions/ln/sendPayment.ts index 0c12922950..0e74892635 100644 --- a/src/extension/background-script/actions/ln/sendPayment.ts +++ b/src/extension/background-script/actions/ln/sendPayment.ts @@ -28,13 +28,7 @@ export default async function sendPayment( let response, paymentRequestDetails; try { - const signet = { - bech32: "tbs", - pubKeyHash: 0x6f, - scriptHash: 0xc4, - validWitnessVersions: [0], - }; - paymentRequestDetails = lightningPayReq.decode(paymentRequest, signet); + paymentRequestDetails = lightningPayReq.decode(paymentRequest); response = await connector.sendPayment({ paymentRequest, diff --git a/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts b/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts index a7ee7097c8..48a22752e6 100644 --- a/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts +++ b/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts @@ -16,13 +16,8 @@ const sendPaymentOrPrompt = async (message: Message, sender: Sender) => { error: "Payment request missing.", }; } - const signet = { - bech32: "tbs", - pubKeyHash: 0x6f, - scriptHash: 0xc4, - validWitnessVersions: [0], - }; - const paymentRequestDetails = lightningPayReq.decode(paymentRequest, signet); + + const paymentRequestDetails = lightningPayReq.decode(paymentRequest); if (await checkAllowance(host, paymentRequestDetails.satoshis || 0)) { return sendPaymentWithAllowance(message); } else { @@ -66,4 +61,4 @@ async function payWithPrompt(message: Message) { } } -export { checkAllowance, payWithPrompt, sendPaymentOrPrompt }; +export { sendPaymentOrPrompt, payWithPrompt, checkAllowance }; From 10fc9d2127b233388b48af85c91fc5294b00440e Mon Sep 17 00:00:00 2001 From: Brandon Lucas <38222767+thebrandonlucas@users.noreply.github.com> Date: Tue, 23 Apr 2024 22:49:37 -0400 Subject: [PATCH 09/14] Revert "feat: update js sdk" This reverts commit 587622de6d541877b912270ba7ccc61d0984881c. --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index b1d5a1c676..d2e962c4f3 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ }, "dependencies": { "@bitcoinerlab/secp256k1": "^1.1.1", - "@getalby/sdk": "^3.5.0", + "@getalby/sdk": "^3.4.3", "@headlessui/react": "^1.7.18", "@lightninglabs/lnc-web": "^0.3.1-alpha", "@noble/ciphers": "^0.5.1", diff --git a/yarn.lock b/yarn.lock index f8c595827f..2b858107c7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -668,10 +668,10 @@ resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.52.0.tgz#78fe5f117840f69dc4a353adf9b9cd926353378c" integrity sha512-mjZVbpaeMZludF2fsWLD0Z9gCref1Tk4i9+wddjRvpUNqqcndPkBD09N/Mapey0b3jaXbLm2kICwFv2E64QinA== -"@getalby/sdk@^3.5.0": - version "3.5.0" - resolved "https://registry.yarnpkg.com/@getalby/sdk/-/sdk-3.5.0.tgz#8ef53cda9f22cf31d3e99d3ff4d00366aee0567d" - integrity sha512-gnjILgoXOMjCVD1fHcoS3ghhO0UpvFHXuCBb0hz5iuzRYxbPWHXt0eVd60y+z5kR/+T+/S3S2fRMnbCYma+ppQ== +"@getalby/sdk@^3.4.3": + version "3.4.3" + resolved "https://registry.yarnpkg.com/@getalby/sdk/-/sdk-3.4.3.tgz#6d407ea11b29a79e40118afa3c58796c1e12b556" + integrity sha512-K0F8Sj3aGmsBV87jfYbMBCAYbb8d9JrLA5jUYn+LuE59IF1flw4pQSb7irQBJYmiFHtvHA8+bpg38WRJr7hpeg== dependencies: eventemitter3 "^5.0.1" nostr-tools "^1.17.0" From 7ba28b5a16a0e089a44816203fccb147dbcac90c Mon Sep 17 00:00:00 2001 From: Brandon Lucas <38222767+thebrandonlucas@users.noreply.github.com> Date: Wed, 24 Apr 2024 09:58:45 -0400 Subject: [PATCH 10/14] feat(mutinynet): use bolt11-signet package --- package.json | 2 +- src/app/screens/ConfirmPayment/index.test.tsx | 2 +- src/app/screens/ConfirmPayment/index.tsx | 2 +- src/app/screens/ConfirmPaymentAsync/index.tsx | 2 +- src/app/screens/Send/index.tsx | 2 +- src/common/lib/lnurl.ts | 2 +- src/common/utils/paymentRequest.ts | 2 +- src/extension/background-script/actions/ln/sendPayment.ts | 2 +- .../background-script/actions/webln/sendPaymentOrPrompt.ts | 4 ++-- src/extension/background-script/connectors/galoy.ts | 2 +- src/extension/background-script/connectors/lnbits.ts | 4 ++-- src/extension/background-script/connectors/lndhub.ts | 2 +- src/extension/background-script/connectors/nwc.ts | 2 +- src/types.ts | 2 +- yarn.lock | 6 +++--- 15 files changed, 19 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index d2e962c4f3..fb3bd0bd2a 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "axios": "^0.27.2", "bech32": "^2.0.0", "bitcoinjs-lib": "^6.1.0", - "bolt11": "^1.4.1", + "bolt11-signet": "^1.4.1", "crypto-js": "^4.2.0", "dayjs": "^1.11.10", "dexie": "^3.2.6", diff --git a/src/app/screens/ConfirmPayment/index.test.tsx b/src/app/screens/ConfirmPayment/index.test.tsx index 36c3ca9a68..8933f4221c 100644 --- a/src/app/screens/ConfirmPayment/index.test.tsx +++ b/src/app/screens/ConfirmPayment/index.test.tsx @@ -1,6 +1,6 @@ import { act, render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import lightningPayReq from "bolt11"; +import lightningPayReq from "bolt11-signet"; import { MemoryRouter } from "react-router-dom"; import { settingsFixture as mockSettings } from "~/../tests/fixtures/settings"; import type { OriginData } from "~/types"; diff --git a/src/app/screens/ConfirmPayment/index.tsx b/src/app/screens/ConfirmPayment/index.tsx index de55ee54cb..7481fd4dc7 100644 --- a/src/app/screens/ConfirmPayment/index.tsx +++ b/src/app/screens/ConfirmPayment/index.tsx @@ -5,7 +5,7 @@ import Container from "@components/Container"; import PaymentSummary from "@components/PaymentSummary"; import PublisherCard from "@components/PublisherCard"; import ResultCard from "@components/ResultCard"; -import lightningPayReq from "bolt11"; +import lightningPayReq from "bolt11-signet"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; diff --git a/src/app/screens/ConfirmPaymentAsync/index.tsx b/src/app/screens/ConfirmPaymentAsync/index.tsx index a825a24431..f08963d2c9 100644 --- a/src/app/screens/ConfirmPaymentAsync/index.tsx +++ b/src/app/screens/ConfirmPaymentAsync/index.tsx @@ -2,7 +2,7 @@ import ConfirmOrCancel from "@components/ConfirmOrCancel"; import Container from "@components/Container"; import PaymentSummary from "@components/PaymentSummary"; import PublisherCard from "@components/PublisherCard"; -import lightningPayReq from "bolt11"; +import lightningPayReq from "bolt11-signet"; import { useEffect, useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; diff --git a/src/app/screens/Send/index.tsx b/src/app/screens/Send/index.tsx index 3cec8c95e2..049ba751f7 100644 --- a/src/app/screens/Send/index.tsx +++ b/src/app/screens/Send/index.tsx @@ -4,7 +4,7 @@ import Header from "@components/Header"; import IconButton from "@components/IconButton"; import TextField from "@components/form/TextField"; import { PopiconsChevronLeftLine } from "@popicons/react"; -import lightningPayReq from "bolt11"; +import lightningPayReq from "bolt11-signet"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useLocation, useNavigate } from "react-router-dom"; diff --git a/src/common/lib/lnurl.ts b/src/common/lib/lnurl.ts index 9ac01fe8f4..deeda9b492 100644 --- a/src/common/lib/lnurl.ts +++ b/src/common/lib/lnurl.ts @@ -1,6 +1,6 @@ import fetchAdapter from "@vespaiach/axios-fetch-adapter"; import axios from "axios"; -import lightningPayReq from "bolt11"; +import lightningPayReq from "bolt11-signet"; import { isLNURLDetailsError } from "~/common/utils/typeHelpers"; import { LNURLAuthServiceResponse, diff --git a/src/common/utils/paymentRequest.ts b/src/common/utils/paymentRequest.ts index acc5d0c3d3..b81ebbfadc 100644 --- a/src/common/utils/paymentRequest.ts +++ b/src/common/utils/paymentRequest.ts @@ -1,4 +1,4 @@ -import lightningPayReq from "bolt11"; +import lightningPayReq from "bolt11-signet"; export function getPaymentRequestDescription(paymentRequest: string): string { const decodedPaymentRequest = lightningPayReq.decode(paymentRequest); diff --git a/src/extension/background-script/actions/ln/sendPayment.ts b/src/extension/background-script/actions/ln/sendPayment.ts index 0e74892635..c03a6adcbf 100644 --- a/src/extension/background-script/actions/ln/sendPayment.ts +++ b/src/extension/background-script/actions/ln/sendPayment.ts @@ -1,4 +1,4 @@ -import lightningPayReq from "bolt11"; +import lightningPayReq from "bolt11-signet"; import PubSub from "pubsub-js"; import pubsub from "~/common/lib/pubsub"; import state from "~/extension/background-script/state"; diff --git a/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts b/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts index 48a22752e6..42862e5c4a 100644 --- a/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts +++ b/src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts @@ -1,4 +1,4 @@ -import lightningPayReq from "bolt11"; +import lightningPayReq from "bolt11-signet"; import utils from "~/common/lib/utils"; import { getHostFromSender } from "~/common/utils/helpers"; import { Message, Sender } from "~/types"; @@ -61,4 +61,4 @@ async function payWithPrompt(message: Message) { } } -export { sendPaymentOrPrompt, payWithPrompt, checkAllowance }; +export { checkAllowance, payWithPrompt, sendPaymentOrPrompt }; diff --git a/src/extension/background-script/connectors/galoy.ts b/src/extension/background-script/connectors/galoy.ts index 0f7ff6a79e..4bf71ef0c9 100644 --- a/src/extension/background-script/connectors/galoy.ts +++ b/src/extension/background-script/connectors/galoy.ts @@ -1,6 +1,6 @@ import fetchAdapter from "@vespaiach/axios-fetch-adapter"; import axios, { AxiosRequestConfig } from "axios"; -import lightningPayReq from "bolt11"; +import lightningPayReq from "bolt11-signet"; import { ACCOUNT_CURRENCIES, CURRENCIES } from "~/common/constants"; import { getPaymentRequestDescription } from "~/common/utils/paymentRequest"; import { getCurrencyRateWithCache } from "~/extension/background-script/actions/cache/getCurrencyRate"; diff --git a/src/extension/background-script/connectors/lnbits.ts b/src/extension/background-script/connectors/lnbits.ts index 8c41139abd..c60c56f742 100644 --- a/src/extension/background-script/connectors/lnbits.ts +++ b/src/extension/background-script/connectors/lnbits.ts @@ -1,4 +1,4 @@ -import lightningPayReq from "bolt11"; +import lightningPayReq from "bolt11-signet"; import Hex from "crypto-js/enc-hex"; import sha256 from "crypto-js/sha256"; import utils from "~/common/lib/utils"; @@ -90,7 +90,7 @@ class LnBits implements Connector { "fee": 0, "memo": "LNbits", "time": 1000000000, - "bolt11": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "bolt11-signet": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "preimage": "0000000000000000000000000000000000000000000000000000000000000000", "payment_hash": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "extra": {}, diff --git a/src/extension/background-script/connectors/lndhub.ts b/src/extension/background-script/connectors/lndhub.ts index 9d2da17f9e..6e02cf5dc6 100644 --- a/src/extension/background-script/connectors/lndhub.ts +++ b/src/extension/background-script/connectors/lndhub.ts @@ -1,7 +1,7 @@ import fetchAdapter from "@vespaiach/axios-fetch-adapter"; import type { AxiosResponse } from "axios"; import axios, { AxiosRequestConfig, Method } from "axios"; -import lightningPayReq from "bolt11"; +import lightningPayReq from "bolt11-signet"; import Base64 from "crypto-js/enc-base64"; import Hex from "crypto-js/enc-hex"; import hmacSHA256 from "crypto-js/hmac-sha256"; diff --git a/src/extension/background-script/connectors/nwc.ts b/src/extension/background-script/connectors/nwc.ts index f14c21f8eb..be67fe1024 100644 --- a/src/extension/background-script/connectors/nwc.ts +++ b/src/extension/background-script/connectors/nwc.ts @@ -1,6 +1,6 @@ import { webln } from "@getalby/sdk"; import { NostrWebLNProvider } from "@getalby/sdk/dist/webln"; -import lightningPayReq from "bolt11"; +import lightningPayReq from "bolt11-signet"; import Hex from "crypto-js/enc-hex"; import SHA256 from "crypto-js/sha256"; import { Account } from "~/types"; diff --git a/src/types.ts b/src/types.ts index 2062a20270..1a966138d8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,5 @@ import { CreateSwapParams } from "@getalby/sdk/dist/types"; -import { PaymentRequestObject } from "bolt11"; +import { PaymentRequestObject } from "bolt11-signet"; import { Runtime } from "webextension-polyfill"; import { ACCOUNT_CURRENCIES, CURRENCIES } from "~/common/constants"; import connectors from "~/extension/background-script/connectors"; diff --git a/yarn.lock b/yarn.lock index 2b858107c7..46bb8d0f65 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2865,10 +2865,10 @@ body-parser@1.19.2: raw-body "2.4.3" type-is "~1.6.18" -bolt11@^1.4.1: +bolt11-signet@^1.4.1: version "1.4.1" - resolved "https://registry.npmjs.org/bolt11/-/bolt11-1.4.1.tgz" - integrity sha512-jR0Y+MO+CK2at1Cg5mltLJ+6tdOwNKoTS/DJOBDdzVkQ+R9D6UgZMayTWOsuzY7OgV1gEqlyT5Tzk6t6r4XcNQ== + resolved "https://registry.yarnpkg.com/bolt11-signet/-/bolt11-signet-1.4.1.tgz#22e91ee2c1fe41024824bc1c4a416d4ed3a3091c" + integrity sha512-vkazbwdf4wG5ljvn1qR+epOSn/eSH475ykvI8DJUFInruNPK6pPf0a4FIbx4eTxToyAj0YNrVIZKJBo6HPGqWQ== dependencies: "@types/bn.js" "^4.11.3" bech32 "^1.1.2" From f1b9143003ee3ae5daa867a5afe4feae04ba281f Mon Sep 17 00:00:00 2001 From: Brandon Lucas <38222767+thebrandonlucas@users.noreply.github.com> Date: Wed, 24 Apr 2024 16:17:21 -0400 Subject: [PATCH 11/14] feat(mutinynet): fix package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fb3bd0bd2a..ad58901aff 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ }, "dependencies": { "@bitcoinerlab/secp256k1": "^1.1.1", - "@getalby/sdk": "^3.4.3", + "@getalby/sdk": "^3.5.0", "@headlessui/react": "^1.7.18", "@lightninglabs/lnc-web": "^0.3.1-alpha", "@noble/ciphers": "^0.5.1", From 335c567613c099a9b6ec081241093958028cde8d Mon Sep 17 00:00:00 2001 From: Brandon Lucas <38222767+thebrandonlucas@users.noreply.github.com> Date: Thu, 25 Apr 2024 07:33:08 -0400 Subject: [PATCH 12/14] feat: undo sdk update --- yarn.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yarn.lock b/yarn.lock index 46bb8d0f65..8b734fd990 100644 --- a/yarn.lock +++ b/yarn.lock @@ -668,10 +668,10 @@ resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.52.0.tgz#78fe5f117840f69dc4a353adf9b9cd926353378c" integrity sha512-mjZVbpaeMZludF2fsWLD0Z9gCref1Tk4i9+wddjRvpUNqqcndPkBD09N/Mapey0b3jaXbLm2kICwFv2E64QinA== -"@getalby/sdk@^3.4.3": - version "3.4.3" - resolved "https://registry.yarnpkg.com/@getalby/sdk/-/sdk-3.4.3.tgz#6d407ea11b29a79e40118afa3c58796c1e12b556" - integrity sha512-K0F8Sj3aGmsBV87jfYbMBCAYbb8d9JrLA5jUYn+LuE59IF1flw4pQSb7irQBJYmiFHtvHA8+bpg38WRJr7hpeg== +"@getalby/sdk@^3.5.0": + version "3.5.0" + resolved "https://registry.yarnpkg.com/@getalby/sdk/-/sdk-3.5.0.tgz#8ef53cda9f22cf31d3e99d3ff4d00366aee0567d" + integrity sha512-gnjILgoXOMjCVD1fHcoS3ghhO0UpvFHXuCBb0hz5iuzRYxbPWHXt0eVd60y+z5kR/+T+/S3S2fRMnbCYma+ppQ== dependencies: eventemitter3 "^5.0.1" nostr-tools "^1.17.0" From a7f2f64bb62b032d1e50bbd204504d62e1e6ad67 Mon Sep 17 00:00:00 2001 From: Brandon Lucas Date: Fri, 26 Apr 2024 10:47:10 -0400 Subject: [PATCH 13/14] Update package.json Co-authored-by: Michael Bumann --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ad58901aff..7a59ba00a4 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "axios": "^0.27.2", "bech32": "^2.0.0", "bitcoinjs-lib": "^6.1.0", - "bolt11-signet": "^1.4.1", + "bolt11-signet": "1.4.1", "crypto-js": "^4.2.0", "dayjs": "^1.11.10", "dexie": "^3.2.6", From 939408e21ac1d1776d70d1a65110a77292d9b8f2 Mon Sep 17 00:00:00 2001 From: Brandon Lucas <38222767+thebrandonlucas@users.noreply.github.com> Date: Mon, 6 May 2024 06:50:17 -0400 Subject: [PATCH 14/14] fix: bolt11-signet package version --- package.json | 2 +- yarn.lock | 35 ++++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index ad58901aff..7a59ba00a4 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "axios": "^0.27.2", "bech32": "^2.0.0", "bitcoinjs-lib": "^6.1.0", - "bolt11-signet": "^1.4.1", + "bolt11-signet": "1.4.1", "crypto-js": "^4.2.0", "dayjs": "^1.11.10", "dexie": "^3.2.6", diff --git a/yarn.lock b/yarn.lock index 8b734fd990..478ece15e0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1526,7 +1526,7 @@ "@types/bn.js@^4.11.3": version "4.11.6" - resolved "https://registry.npmjs.org/@types/bn.js/-/bn.js-4.11.6.tgz" + resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-4.11.6.tgz#c306c70d9358aaea33cd4eda092a742b9505967c" integrity sha512-pqr857jrp2kPuO9uRjZ3PwnJTjoQy+fcdxvBTvHm6dkmEL9q+hDD/2j/0ELOBPtPnS8LjCX0gI9nbl8lVkadpg== dependencies: "@types/node" "*" @@ -2767,7 +2767,7 @@ batch@0.6.1: bech32@^1.1.2: version "1.1.4" - resolved "https://registry.npmjs.org/bech32/-/bech32-1.1.4.tgz" + resolved "https://registry.yarnpkg.com/bech32/-/bech32-1.1.4.tgz#e38c9f37bf179b8eb16ae3a772b40c356d4832e9" integrity sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ== bech32@^2.0.0: @@ -2790,6 +2790,11 @@ bip174@^2.1.0: resolved "https://registry.npmjs.org/bip174/-/bip174-2.1.0.tgz" integrity sha512-lkc0XyiX9E9KiVAS1ZiOqK1xfiwvf4FXDDdkDq5crcDzOq+xGytY+14qCsqz7kCiy8rpN1CRNfacRhf9G3JNSA== +bip174@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/bip174/-/bip174-2.1.1.tgz#ef3e968cf76de234a546962bcf572cc150982f9f" + integrity sha512-mdFV5+/v0XyNYXjBS6CQPLo9ekCx4gtKZFnJm5PMto7Fs9hTTDpkkzOB7/FtluRI6JbUUAu+snTYfJRgHLZbZQ== + bip66@^1.1.0: version "1.1.5" resolved "https://registry.npmjs.org/bip66/-/bip66-1.1.5.tgz" @@ -2797,7 +2802,19 @@ bip66@^1.1.0: dependencies: safe-buffer "^5.0.1" -bitcoinjs-lib@^6.0.0, bitcoinjs-lib@^6.0.2: +bitcoinjs-lib@^6.0.0: + version "6.1.5" + resolved "https://registry.yarnpkg.com/bitcoinjs-lib/-/bitcoinjs-lib-6.1.5.tgz#3b03509ae7ddd80a440f10fc38c4a97f0a028d8c" + integrity sha512-yuf6xs9QX/E8LWE2aMJPNd0IxGofwfuVOiYdNUESkc+2bHHVKjhJd8qewqapeoolh9fihzHGoDCB5Vkr57RZCQ== + dependencies: + "@noble/hashes" "^1.2.0" + bech32 "^2.0.0" + bip174 "^2.1.1" + bs58check "^3.0.1" + typeforce "^1.11.3" + varuint-bitcoin "^1.1.2" + +bitcoinjs-lib@^6.0.2: version "6.1.0" resolved "https://registry.yarnpkg.com/bitcoinjs-lib/-/bitcoinjs-lib-6.1.0.tgz#2e3123d63eab5e8e752fd7e2f237314f35ed738f" integrity sha512-eupi1FBTJmPuAZdChnzTXLv2HBqFW2AICpzXZQLniP0V9FWWeeUQSMKES6sP8isy/xO0ijDexbgkdEyFVrsuJw== @@ -2865,7 +2882,7 @@ body-parser@1.19.2: raw-body "2.4.3" type-is "~1.6.18" -bolt11-signet@^1.4.1: +bolt11-signet@1.4.1: version "1.4.1" resolved "https://registry.yarnpkg.com/bolt11-signet/-/bolt11-signet-1.4.1.tgz#22e91ee2c1fe41024824bc1c4a416d4ed3a3091c" integrity sha512-vkazbwdf4wG5ljvn1qR+epOSn/eSH475ykvI8DJUFInruNPK6pPf0a4FIbx4eTxToyAj0YNrVIZKJBo6HPGqWQ== @@ -7185,7 +7202,7 @@ no-case@^3.0.4: node-addon-api@^2.0.0: version "2.0.2" - resolved "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz" + resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-2.0.2.tgz#432cfa82962ce494b132e9d72a15b29f71ff5d32" integrity sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA== node-fetch@^2.6.12, node-fetch@^2.6.7: @@ -7201,9 +7218,9 @@ node-forge@^1: integrity sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA== node-gyp-build@^4.2.0: - version "4.3.0" - resolved "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.3.0.tgz" - integrity sha512-iWjXZvmboq0ja1pUGULQBexmxq8CV4xBhX7VDOTbL7ZR4FOowwY/VOtRxBN/yKxmdGoIp4j5ysNT4u3S2pDQ3Q== + version "4.8.1" + resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.8.1.tgz#976d3ad905e71b76086f4f0b0d3637fe79b6cda5" + integrity sha512-OSs33Z9yWr148JZcbZd5WiAXhh/n9z8TxQcdMhIOlpN9AhWpLfvVFO73+m77bBABQMaY9XSvIa+qk0jlI7Gcaw== node-int64@^0.4.0: version "0.4.0" @@ -8749,7 +8766,7 @@ schema-utils@^4.0.1: secp256k1@^4.0.2: version "4.0.3" - resolved "https://registry.npmjs.org/secp256k1/-/secp256k1-4.0.3.tgz" + resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-4.0.3.tgz#c4559ecd1b8d3c1827ed2d1b94190d69ce267303" integrity sha512-NLZVf+ROMxwtEj3Xa562qgv2BK5e2WNmXPiOdVIPLgs6lyTzMvBq0aWTYMI5XCP9jZMVKOcqZLw/Wc4vDkuxhA== dependencies: elliptic "^6.5.4"