chore: remove lnc / cashu wallets
This commit is contained in:
@ -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",
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
@ -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 };
|
||||
|
Reference in New Issue
Block a user