chore: remove lnc / cashu wallets

This commit is contained in:
2025-05-06 12:50:04 +01:00
parent 75324e4862
commit 07474a836e
10 changed files with 3 additions and 550 deletions

View File

@ -2,10 +2,8 @@ import { ReactNode } from "react";
import { FormattedMessage } from "react-intl";
import { useNavigate } from "react-router-dom";
import LndLogo from "@/assets/img/lnd-logo.png";
import AlbyIcon from "@/Components/Icons/Alby";
import BlueWallet from "@/Components/Icons/BlueWallet";
//import CashuIcon from "@/Components/Icons/Cashu";
import Icon from "@/Components/Icons/Icon";
import NWCIcon from "@/Components/Icons/NWC";
import { getAlbyOAuth } from "@/Pages/settings/wallet/utils";
@ -57,24 +55,12 @@ const WalletSettings = () => {
url="/settings/wallet/nwc"
desc={<FormattedMessage defaultMessage="Native nostr wallet connection" />}
/>
<WalletRow
logo={<img src={LndLogo} />}
name="LND via LNC"
url="/settings/wallet/lnc"
desc={<FormattedMessage defaultMessage="Connect to your own LND node with Lightning Node Connect" />}
/>
<WalletRow
logo={<BlueWallet width={64} height={64} />}
name="LNDHub"
url="/settings/wallet/lndhub"
desc={<FormattedMessage defaultMessage="Generic LNDHub wallet (BTCPayServer / Alby / LNBits)" />}
/>
{/*<WalletRow
logo={<CashuIcon size={64} />}
name="Cashu"
url="/settings/wallet/cashu"
desc={<FormattedMessage defaultMessage="Cashu mint wallet" />}
/>*/}
{CONFIG.alby && (
<WalletRow
logo={<AlbyIcon size={64} />}

View File

@ -1,78 +0,0 @@
import { CashuWallet, WalletKind } from "@snort/wallet";
import { useState } from "react";
import { FormattedMessage, useIntl } from "react-intl";
import { useNavigate } from "react-router-dom";
import { v4 as uuid } from "uuid";
import AsyncButton from "@/Components/Button/AsyncButton";
import { unwrap } from "@/Utils";
import { WalletConfig, Wallets } from "@/Wallet";
const ConnectCashu = () => {
const navigate = useNavigate();
const { formatMessage } = useIntl();
const [mintUrl, setMintUrl] = useState<string>("https://8333.space:3338");
const [error, setError] = useState<string>();
async function tryConnect(config: string) {
try {
if (!mintUrl) {
throw new Error("Mint URL is required");
}
const connection = new CashuWallet({
url: config,
keys: {},
proofs: [],
keysets: [],
});
await connection.login();
const info = await connection.getInfo();
const newWallet = {
id: uuid(),
kind: WalletKind.Cashu,
active: true,
info,
data: JSON.stringify(connection.getConfig()),
} as WalletConfig;
Wallets.add(newWallet);
navigate("/settings/wallet");
} catch (e) {
if (e instanceof Error) {
setError((e as Error).message);
} else {
setError(
formatMessage({
defaultMessage: "Unknown error",
id: "qDwvZ4",
}),
);
}
}
}
return (
<>
<h4>
<FormattedMessage defaultMessage="Enter mint URL" id="KoFlZg" />
</h4>
<div className="flex">
<div className="grow mr10">
<input
type="text"
placeholder="Mint URL"
className="w-max"
value={mintUrl}
onChange={e => setMintUrl(e.target.value)}
/>
</div>
<AsyncButton onClick={() => tryConnect(unwrap(mintUrl))} disabled={!mintUrl}>
<FormattedMessage defaultMessage="Connect" id="+vVZ/G" />
</AsyncButton>
</div>
{error && <b className="error p10">{error}</b>}
</>
);
};
export default ConnectCashu;

View File

@ -1,123 +0,0 @@
import { LNCWallet, LNWallet, WalletInfo, WalletKind } from "@snort/wallet";
import { useState } from "react";
import { FormattedMessage, useIntl } from "react-intl";
import { useNavigate } from "react-router-dom";
import { v4 as uuid } from "uuid";
import AsyncButton from "@/Components/Button/AsyncButton";
import { unwrap } from "@/Utils";
import { Wallets } from "@/Wallet";
const ConnectLNC = () => {
const { formatMessage } = useIntl();
const navigate = useNavigate();
const [pairingPhrase, setPairingPhrase] = useState<string>();
const [error, setError] = useState<string>();
const [connectedLNC, setConnectedLNC] = useState<LNWallet & { setPassword(pw: string): void }>();
const [walletInfo, setWalletInfo] = useState<WalletInfo>();
const [walletPassword, setWalletPassword] = useState<string>();
async function tryConnect(cfg: string) {
try {
const lnc = await LNCWallet.Initialize(cfg);
const info = await lnc.getInfo();
// prompt password
setConnectedLNC(lnc);
setWalletInfo(info as WalletInfo);
} catch (e) {
if (e instanceof Error) {
setError(e.message);
} else {
setError(
formatMessage({
defaultMessage: "Unknown error",
id: "qDwvZ4",
}),
);
}
}
}
function setLNCPassword(pw: string) {
connectedLNC?.setPassword(pw);
Wallets.add({
id: uuid(),
kind: WalletKind.LNC,
active: true,
info: unwrap(walletInfo),
});
navigate("/settings/wallet");
}
function flowConnect() {
if (connectedLNC) return null;
return (
<>
<h4>
<FormattedMessage defaultMessage="Enter pairing phrase" />
</h4>
<div className="flex">
<div className="grow mr10">
<input
type="text"
placeholder={formatMessage({ defaultMessage: "Pairing phrase", id: "8v1NN+" })}
className="w-max"
value={pairingPhrase}
onChange={e => setPairingPhrase(e.target.value)}
/>
</div>
<AsyncButton onClick={() => tryConnect(unwrap(pairingPhrase))} disabled={!pairingPhrase}>
<FormattedMessage defaultMessage="Connect" />
</AsyncButton>
</div>
{error && <b className="error p10">{error}</b>}
</>
);
}
function flowSetPassword() {
if (!connectedLNC) return null;
return (
<div className="flex flex-col">
<h3>
<FormattedMessage
defaultMessage="Connected to: {node} 🎉"
id="1c4YST"
values={{
node: walletInfo?.alias,
}}
/>
</h3>
<h4>
<FormattedMessage defaultMessage="Enter password" />
</h4>
<div className="flex w-max">
<div className="grow mr10">
<input
type="password"
placeholder={formatMessage({ defaultMessage: "Wallet password", id: "lTbT3s" })}
className="w-max"
value={walletPassword}
onChange={e => setWalletPassword(e.target.value)}
/>
</div>
<AsyncButton
onClick={() => setLNCPassword(unwrap(walletPassword))}
disabled={(walletPassword?.length ?? 0) < 8}>
<FormattedMessage defaultMessage="Save" />
</AsyncButton>
</div>
</div>
);
}
return (
<>
{flowConnect()}
{flowSetPassword()}
</>
);
};
export default ConnectLNC;

View File

@ -2,8 +2,6 @@ import { RouteObject } from "react-router-dom";
import WalletSettings from "../WalletSettings";
import AlbyOAuth from "./Alby";
//import ConnectCashu from "./Cashu";
import ConnectLNC from "./LNC";
import ConnectLNDHub from "./LNDHub";
import ConnectNostrWallet from "./NWC";
@ -12,10 +10,6 @@ export const WalletSettingsRoutes = [
path: "/settings/wallet",
element: <WalletSettings />,
},
{
path: "/settings/wallet/lnc",
element: <ConnectLNC />,
},
{
path: "/settings/wallet/lndhub",
element: <ConnectLNDHub />,
@ -24,10 +18,6 @@ export const WalletSettingsRoutes = [
path: "/settings/wallet/nwc",
element: <ConnectNostrWallet />,
},
/*{
path: "/settings/wallet/cashu",
element: <ConnectCashu />,
},*/
{
path: "/settings/wallet/alby",
element: <AlbyOAuth />,

View File

@ -129,9 +129,6 @@
"1UWegE": {
"defaultMessage": "Be sure to back up your keys!"
},
"1c4YST": {
"defaultMessage": "Connected to: {node} 🎉"
},
"1nYUGC": {
"defaultMessage": "{n} Following"
},
@ -168,9 +165,6 @@
"2IFGap": {
"defaultMessage": "Donate"
},
"2LbrkB": {
"defaultMessage": "Enter password"
},
"2O2sfp": {
"defaultMessage": "Finish"
},
@ -456,9 +450,6 @@
"8jmwT8": {
"defaultMessage": "bech32-encoded entities"
},
"8v1NN+": {
"defaultMessage": "Pairing phrase"
},
"8xdDLn": {
"defaultMessage": "Follow sets"
},
@ -1512,9 +1503,6 @@
"Z48UEo": {
"defaultMessage": "Channel Metadata"
},
"Z4BMCZ": {
"defaultMessage": "Enter pairing phrase"
},
"Z7kkeJ": {
"defaultMessage": "Delegated Event Signing"
},
@ -1560,9 +1548,6 @@
"aRex7h": {
"defaultMessage": "Paid {amount} sats, fee {fee} sats"
},
"aSGz4J": {
"defaultMessage": "Connect to your own LND node with Lightning Node Connect"
},
"aWpBzj": {
"defaultMessage": "Show more"
},
@ -2008,9 +1993,6 @@
"lPWASz": {
"defaultMessage": "Snort nostr address"
},
"lTbT3s": {
"defaultMessage": "Wallet password"
},
"lbr3Lq": {
"defaultMessage": "Copy link"
},

View File

@ -42,7 +42,6 @@
"1Mo59U": "Are you sure you want to remove this note from bookmarks?",
"1R43+L": "Enter Nostr Wallet Connect config",
"1UWegE": "Be sure to back up your keys!",
"1c4YST": "Connected to: {node} 🎉",
"1nYUGC": "{n} Following",
"1o2BgB": "Check Signatures",
"1ozeyg": "Nature",
@ -55,7 +54,6 @@
"2BBGxX": "Subject tag in text events",
"2HIqeO": "User emoji list",
"2IFGap": "Donate",
"2LbrkB": "Enter password",
"2O2sfp": "Finish",
"2Qsf9/": "Generic lists",
"2YxhJx": "Reserved Cashu Wallet Tokens",
@ -151,7 +149,6 @@
"8Y6bZQ": "Invalid zap split: {input}",
"8g2vyB": "name too long",
"8jmwT8": "bech32-encoded entities",
"8v1NN+": "Pairing phrase",
"8xdDLn": "Follow sets",
"8za9Pq": "Draft Classified Listing",
"9+Ddtu": "Next",
@ -501,7 +498,6 @@
"Yf3DwC": "Connect a wallet to send instant payments",
"YuoEb9": "Try another relay",
"Z48UEo": "Channel Metadata",
"Z4BMCZ": "Enter pairing phrase",
"Z7kkeJ": "Delegated Event Signing",
"ZFe9tl": "Compose a note",
"ZKORll": "Activate Now",
@ -517,7 +513,6 @@
"aHje0o": "Name or nym",
"aMaLBK": "Supported Extensions",
"aRex7h": "Paid {amount} sats, fee {fee} sats",
"aSGz4J": "Connect to your own LND node with Lightning Node Connect",
"aWpBzj": "Show more",
"abbGKq": "{n} km",
"ak3MTf": "Invite Friends",
@ -666,7 +661,6 @@
"lD3+8a": "Pay",
"lEnclp": "My events: {n}",
"lPWASz": "Snort nostr address",
"lTbT3s": "Wallet password",
"lbr3Lq": "Copy link",
"lfOesV": "Non-Zap",
"lgg1KN": "account page",

View File

@ -19,8 +19,6 @@
],
"packageManager": "yarn@4.1.1",
"dependencies": {
"@cashu/cashu-ts": "^1.0.0-rc.3",
"@lightninglabs/lnc-web": "^0.3.1-alpha",
"@scure/base": "^1.1.6",
"@snort/shared": "^1.0.17",
"@snort/system": "^1.6.1",

View File

@ -1,104 +0,0 @@
import { CashuMint, Proof } from "@cashu/cashu-ts";
import { InvoiceRequest, LNWallet, WalletEvents, WalletInfo, WalletInvoice } from ".";
import EventEmitter from "eventemitter3";
export type CashuWalletConfig = {
url: string;
keys: Record<string, string>;
keysets: Array<string>;
proofs: Array<Proof>;
};
export class CashuWallet extends EventEmitter<WalletEvents> implements LNWallet {
#wallet: CashuWalletConfig;
#mint: CashuMint;
constructor(wallet: CashuWalletConfig) {
super();
this.#wallet = wallet;
this.#mint = new CashuMint(this.#wallet.url);
}
getConfig() {
return { ...this.#wallet };
}
canGetInvoices() {
return false;
}
canGetBalance() {
return true;
}
canAutoLogin() {
return true;
}
isReady() {
return true;
}
canCreateInvoice() {
return true;
}
canPayInvoice() {
return true;
}
async getInfo() {
return {
alias: "Cashu mint: " + this.#wallet.url,
} as WalletInfo;
}
async login(): Promise<boolean> {
if (this.#wallet.keysets.length === 0) {
const keys = await this.#mint.getKeys();
this.#wallet.keys = keys;
this.#wallet.keysets = [""];
this.onChange(this.#wallet);
}
await this.#checkProofs();
return true;
}
close(): Promise<boolean> {
return Promise.resolve(true);
}
async getBalance() {
return this.#wallet.proofs.reduce((acc, v) => (acc += v.amount), 0);
}
async createInvoice(req: InvoiceRequest) {
const rsp = await this.#mint.requestMint(req.amount);
return {
pr: rsp.pr,
} as WalletInvoice;
}
payInvoice(): Promise<WalletInvoice> {
throw new Error("Method not implemented.");
}
getInvoices(): Promise<WalletInvoice[]> {
return Promise.resolve([]);
}
async #checkProofs() {
if (this.#wallet.proofs.length == 0) return;
const checks = await this.#mint.check({
proofs: this.#wallet.proofs.map(a => ({ secret: a.secret })),
});
const filteredProofs = this.#wallet.proofs.filter((_, i) => checks.spendable[i]);
this.#wallet.proofs = filteredProofs;
if (filteredProofs.length !== checks.spendable.length) {
this.emit("change", JSON.stringify(this.#wallet));
}
}
}

View File

@ -1,182 +0,0 @@
import LNC from "@lightninglabs/lnc-web";
import debug from "debug";
import {
InvoiceRequest,
LNWallet,
Login,
prToWalletInvoice,
WalletError,
WalletErrorCode,
WalletEvents,
WalletInfo,
WalletInvoice,
WalletInvoiceState,
} from ".";
import { unwrap } from "@snort/shared";
import EventEmitter from "eventemitter3";
enum Payment_PaymentStatus {
UNKNOWN = "UNKNOWN",
IN_FLIGHT = "IN_FLIGHT",
SUCCEEDED = "SUCCEEDED",
FAILED = "FAILED",
UNRECOGNIZED = "UNRECOGNIZED",
}
export class LNCWallet extends EventEmitter<WalletEvents> implements LNWallet {
#lnc: LNC;
readonly #log = debug("LNC");
private constructor(pairingPhrase?: string, password?: string) {
super();
this.#lnc = new LNC({
pairingPhrase,
password,
});
}
canAutoLogin() {
return false;
}
canGetInvoices() {
return true;
}
canGetBalance() {
return true;
}
canCreateInvoice() {
return true;
}
canPayInvoice() {
return true;
}
isReady(): boolean {
return this.#lnc.isReady;
}
static async Initialize(pairingPhrase: string) {
const lnc = new LNCWallet(pairingPhrase);
await lnc.login();
return lnc;
}
static Empty() {
return new LNCWallet();
}
setPassword(pw: string) {
if (this.#lnc.credentials.password && pw !== this.#lnc.credentials.password) {
throw new WalletError(WalletErrorCode.GeneralError, "Password is already set, cannot update password");
}
this.#lnc.credentials.password = pw;
}
createAccount(): Promise<WalletError | Login> {
throw new Error("Not implemented");
}
async getInfo(): Promise<WalletInfo> {
const nodeInfo = await this.#lnc.lnd.lightning.getInfo();
return {
nodePubKey: nodeInfo.identityPubkey,
alias: nodeInfo.alias,
} as WalletInfo;
}
close(): Promise<boolean> {
if (this.#lnc.isConnected) {
this.#lnc.disconnect();
}
return Promise.resolve(true);
}
async login(password?: string): Promise<boolean> {
if (password) {
this.setPassword(password);
this.#lnc.run();
}
await this.#lnc.connect();
while (!this.#lnc.isConnected) {
await new Promise(resolve => {
setTimeout(resolve, 100);
});
}
return true;
}
async getBalance(): Promise<number> {
const rsp = await this.#lnc.lnd.lightning.channelBalance();
this.#log(rsp);
return parseInt(rsp.localBalance?.sat ?? "0");
}
async createInvoice(req: InvoiceRequest): Promise<WalletInvoice> {
const rsp = await this.#lnc.lnd.lightning.addInvoice({
memo: req.memo,
value: req.amount.toString(),
expiry: req.expiry?.toString(),
});
return unwrap(prToWalletInvoice(rsp.paymentRequest));
}
async payInvoice(pr: string): Promise<WalletInvoice> {
return new Promise((resolve, reject) => {
this.#lnc.lnd.router.sendPaymentV2(
{
paymentRequest: pr,
timeoutSeconds: 60,
feeLimitSat: "100",
},
msg => {
this.#log(msg);
if (msg.status === Payment_PaymentStatus.SUCCEEDED) {
resolve({
preimage: msg.paymentPreimage,
state: WalletInvoiceState.Paid,
timestamp: parseInt(msg.creationTimeNs) / 1e9,
} as WalletInvoice);
}
},
err => {
this.#log(err);
reject(err);
},
);
});
}
async getInvoices(): Promise<WalletInvoice[]> {
const invoices = await this.#lnc.lnd.lightning.listPayments({
maxPayments: "10",
reversed: true,
});
this.#log(invoices);
return invoices.payments.map(a => {
const parsedInvoice = prToWalletInvoice(a.paymentRequest);
if (!parsedInvoice) {
throw new WalletError(WalletErrorCode.InvalidInvoice, `Could not parse ${a.paymentRequest}`);
}
return {
...parsedInvoice,
state: (() => {
switch (a.status) {
case Payment_PaymentStatus.SUCCEEDED:
return WalletInvoiceState.Paid;
case Payment_PaymentStatus.FAILED:
return WalletInvoiceState.Failed;
default:
return WalletInvoiceState.Pending;
}
})(),
preimage: a.paymentPreimage,
} as WalletInvoice;
});
}
}

View File

@ -1,7 +1,5 @@
import { decodeInvoice, unwrap } from "@snort/shared";
import AlbyWallet from "./AlbyWallet";
//import { CashuWallet } from "./Cashu";
import { LNCWallet } from "./LNCWallet";
import LNDHubWallet from "./LNDHub";
import { NostrConnectWallet } from "./NostrWalletConnect";
import { WebLNWallet } from "./WebLN";
@ -11,10 +9,10 @@ export * from "./zapper";
export const enum WalletKind {
LNDHub = 1,
LNC = 2,
//LNC = 2,
WebLN = 3,
NWC = 4,
Cashu = 5,
//Cashu = 5,
Alby = 6,
}
@ -135,10 +133,6 @@ export type LNWallet = EventEmitter<WalletEvents> & {
*/
export async function loadWallet(kind: WalletKind, data: string | undefined) {
switch (kind) {
case WalletKind.LNC: {
const { LNCWallet } = await import("./LNCWallet");
return LNCWallet.Empty();
}
case WalletKind.WebLN: {
return new WebLNWallet();
}
@ -151,11 +145,7 @@ export async function loadWallet(kind: WalletKind, data: string | undefined) {
case WalletKind.Alby: {
return new AlbyWallet(JSON.parse(unwrap(data)));
}
case WalletKind.Cashu: {
//const { CashuWallet } = await import("./Cashu");
//return new CashuWallet(JSON.parse(unwrap(data)));
}
}
}
export { LNCWallet, WebLNWallet, LNDHubWallet, NostrConnectWallet, AlbyWallet };
export { WebLNWallet, LNDHubWallet, NostrConnectWallet, AlbyWallet };