Merge pull request #729 from shocknet/addr-meta

ln addr meta
This commit is contained in:
Justin (shocknet) 2024-09-01 14:34:24 -04:00 committed by GitHub
commit 42d272c751
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 11 deletions

View file

@ -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

View file

@ -226,7 +226,7 @@ export default class {
async GetAppUserLNURLInfo(appId: string, req: Types.GetAppUserLNURLInfoRequest): Promise<Types.LnurlPayInfoResponse> {
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<Types.RequestNPubLinkingTokenResponse> {
const app = await this.storage.applicationStorage.GetApplication(appId);

View file

@ -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<Types.LnurlPayInfoResponse> {
async GetLnurlPayInfoFromUser(userId: string, linkedApplication: Application, opts: { baseUrl?: string, metadata?: string } = {}): Promise<Types.LnurlPayInfoResponse> {
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<Types.OpenChannelResponse> { throw new Error("WIP") }

View file

@ -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
}
}