UNPKG

@getalby/paidmcp

Version:

Charge for your MCP Server tools using Nostr Wallet Connect

29 lines (28 loc) 871 B
import { LN, nwc } from "@getalby/sdk"; export class NWCWallet { _nwcUrl; constructor(nwcUrl) { this._nwcUrl = nwcUrl; } async verifyPayment(paymentHash) { const nwcClient = new nwc.NWCClient({ nostrWalletConnectUrl: this._nwcUrl, }); const transaction = await nwcClient.lookupInvoice({ payment_hash: paymentHash, }); nwcClient.close(); return !!transaction.settled_at; } async requestInvoice(args) { const ln = new LN(this._nwcUrl); const paymentRequest = await ln.requestPayment({ satoshi: args.satoshi }, { description: args.description, }); ln.close(); return { payment_hash: paymentRequest.invoice.paymentHash, payment_request: paymentRequest.invoice.paymentRequest, }; } }