Fix missing validation for NWC receive (#2365)

This commit is contained in:
ekzyis 2025-07-30 18:37:25 +02:00 committed by GitHub
parent 6aeffa7aff
commit d175d0e64d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
import { nwcTryRun } from '@/wallets/lib/protocols/nwc' import { nwcTryRun, supportedMethods } from '@/wallets/lib/protocols/nwc'
export const name = 'NWC' export const name = 'NWC'
@ -12,6 +12,20 @@ export async function createInvoice ({ msats, description, expiry }, { url }, {
} }
export async function testCreateInvoice ({ url }, { signal }) { export async function testCreateInvoice ({ url }, { signal }) {
const supported = await supportedMethods(url, { signal })
const supports = (method) => supported.includes(method)
if (!supports('make_invoice')) {
throw new Error('make_invoice not supported')
}
const mustNotSupport = ['pay_invoice', 'multi_pay_invoice', 'pay_keysend', 'multi_pay_keysend']
for (const method of mustNotSupport) {
if (supports(method)) {
throw new Error(`${method} must not be supported`)
}
}
return await createInvoice( return await createInvoice(
{ msats: 1000, description: 'SN test invoice', expiry: 1 }, { msats: 1000, description: 'SN test invoice', expiry: 1 },
{ url }, { url },