diff --git a/env.example b/env.example index 8a36d59e..f4383e14 100644 --- a/env.example +++ b/env.example @@ -70,6 +70,7 @@ LSP_MAX_FEE_BPS=100 # You also need an SSL reverse proxy from the domain to this local host # Read more at https://docs.shock.network #SERVICE_URL=https://yourdomainhere.xyz +#LNURL_META_TEXT=LNURL via Lightning.Pub #SUBSCRIPTION_SERVICES # Opt-in to cloud relays for LNURL and Nostr diff --git a/src/services/main/applicationManager.ts b/src/services/main/applicationManager.ts index 49f1d280..e2ebad2a 100644 --- a/src/services/main/applicationManager.ts +++ b/src/services/main/applicationManager.ts @@ -226,7 +226,7 @@ export default class { async GetAppUserLNURLInfo(appId: string, req: Types.GetAppUserLNURLInfoRequest): Promise { const app = await this.storage.applicationStorage.GetApplication(appId) const user = await this.storage.applicationStorage.GetApplicationUser(app, req.user_identifier) - return this.paymentManager.GetLnurlPayInfoFromUser(user.user.user_id, app, req.base_url_override) + return this.paymentManager.GetLnurlPayInfoFromUser(user.user.user_id, app, { baseUrl: req.base_url_override }) } async RequestNPubLinkingToken(appId: string, req: Types.RequestNPubLinkingTokenRequest, reset: boolean): Promise { const app = await this.storage.applicationStorage.GetApplication(appId); diff --git a/src/services/main/paymentManager.ts b/src/services/main/paymentManager.ts index 9b7dbe60..4e0723c0 100644 --- a/src/services/main/paymentManager.ts +++ b/src/services/main/paymentManager.ts @@ -39,7 +39,8 @@ interface UserOperationInfo { internal?: boolean; } export type PendingTx = { type: 'incoming', tx: AddressReceivingTransaction } | { type: 'outgoing', tx: UserTransactionPayment } -const defaultLnurlPayMetadata = `[["text/plain", "lnurl pay to Lightning.pub"]]` +const defaultLnurlPayMetadata = (text: string) => `[["text/plain", "${text}"]]` +const defaultLnAddressMetadata = (text: string, id: string) => `[["text/plain", "${text}"],["text/identifier", "${id}"]]` const confInOne = 1000 * 1000 const confInTwo = 100 * 1000 * 1000 export default class { @@ -135,7 +136,7 @@ export default class { //}) return } - console.log({p}) + console.log({ p }) const paymentRes = await this.lnd.GetPayment(p.paymentIndex) const payment = paymentRes.payments[0] if (!payment || Number(payment.paymentIndex) !== p.paymentIndex) { @@ -337,7 +338,7 @@ export default class { const pendingPayment = await this.storage.txQueue.PushToQueue({ dbTx: true, description: "payment started", exec: async tx => { await this.storage.userStorage.DecrementUserBalance(userId, totalAmountToDecrement + routingFeeLimit, invoice, tx) - return await this.storage.paymentStorage.AddPendingExternalPayment(userId, invoice, { payAmount, serviceFee, networkFee: routingFeeLimit }, linkedApplication, provider,tx) + return await this.storage.paymentStorage.AddPendingExternalPayment(userId, invoice, { payAmount, serviceFee, networkFee: routingFeeLimit }, linkedApplication, provider, tx) } }) this.log("ready to pay") @@ -513,10 +514,11 @@ export default class { } } - async GetLnurlPayInfoFromUser(userId: string, linkedApplication: Application, baseUrl?: string): Promise { + async GetLnurlPayInfoFromUser(userId: string, linkedApplication: Application, opts: { baseUrl?: string, metadata?: string } = {}): Promise { if (this.isDefaultServiceUrl()) { throw new Error("Lnurl not enabled. Make sure to set SERVICE_URL env variable") } + const { baseUrl, metadata } = opts const payK1 = await this.storage.paymentStorage.AddUserEphemeralKey(userId, 'pay', linkedApplication) const url = baseUrl ? baseUrl : `${this.settings.serviceUrl}/api/guest/lnurl_pay/handle` const { remote } = await this.lnd.ChannelBalance() @@ -525,7 +527,7 @@ export default class { callback: `${url}?k1=${payK1.key}`, maxSendable: remote * 1000, minSendable: 10000, - metadata: defaultLnurlPayMetadata, + metadata: metadata ? metadata : defaultLnurlPayMetadata(this.settings.lnurlMetaText), allowsNostr: !!linkedApplication.nostr_public_key, nostrPubkey: linkedApplication.nostr_public_key || "" } @@ -545,7 +547,7 @@ export default class { callback: `${this.settings.serviceUrl}/api/guest/lnurl_pay/handle?k1=${payInfoK1}`, maxSendable: remote * 1000, minSendable: 10000, - metadata: defaultLnurlPayMetadata, + metadata: defaultLnurlPayMetadata(this.settings.lnurlMetaText), allowsNostr: !!key.linkedApplication.nostr_public_key, nostrPubkey: key.linkedApplication.nostr_public_key || "" } @@ -621,7 +623,7 @@ export default class { } const invoice = await this.NewInvoice(key.user.user_id, { amountSats: sats, - memo: zapInfo ? zapInfo.description : defaultLnurlPayMetadata + memo: zapInfo ? zapInfo.description : defaultLnurlPayMetadata(this.settings.lnurlMetaText) }, { expiry: defaultInvoiceExpiry, linkedApplication: key.linkedApplication, zapInfo }) return { pr: invoice.invoice, @@ -634,7 +636,7 @@ export default class { if (!linkedUser) { throw new Error("this address is not linked to any user") } - return this.GetLnurlPayInfoFromUser(linkedUser.user.user_id, linkedUser.application) + return this.GetLnurlPayInfoFromUser(linkedUser.user.user_id, linkedUser.application, { metadata: defaultLnAddressMetadata(this.settings.lnurlMetaText, addressName) }) } async OpenChannel(userId: string, req: Types.OpenChannelRequest): Promise { throw new Error("WIP") } diff --git a/src/services/main/settings.ts b/src/services/main/settings.ts index 9b50ae67..89aeb512 100644 --- a/src/services/main/settings.ts +++ b/src/services/main/settings.ts @@ -33,6 +33,7 @@ export type MainSettings = { wizard: boolean defaultAppName: string pushBackupsToNostr: boolean + lnurlMetaText: string } export type BitcoinCoreSettings = { @@ -70,7 +71,8 @@ export const LoadMainSettingsFromEnv = (): MainSettings => { disableExternalPayments: process.env.DISABLE_EXTERNAL_PAYMENTS === 'true' || false, wizard: process.env.WIZARD === 'true' || false, defaultAppName: process.env.DEFAULT_APP_NAME || "wallet", - pushBackupsToNostr: process.env.PUSH_BACKUPS_TO_NOSTR === 'true' || false + pushBackupsToNostr: process.env.PUSH_BACKUPS_TO_NOSTR === 'true' || false, + lnurlMetaText: process.env.LNURL_META_TEXT || "LNURL via Lightning.pub" } } @@ -132,4 +134,4 @@ export const loadJwtSecret = (dataDir: string): string => { export const getDataPath = (dataDir: string, dataPath: string) => { return dataDir !== "" ? `${dataDir}/${dataPath}` : dataPath -} \ No newline at end of file +}