diff --git a/src/utils/bolt11.ts b/src/utils/bolt11.ts new file mode 100644 index 00000000..3e7db690 --- /dev/null +++ b/src/utils/bolt11.ts @@ -0,0 +1,15 @@ +import bolt11 from 'bolt11'; + +/** Decodes the invoice and returns the amount in millisatoshis */ +function getAmount(invoice: string | undefined): string | undefined { + if (!invoice) return; + + try { + const decoded = bolt11.decode(invoice); + return decoded?.millisatoshis ?? undefined; + } catch { + return; + } +} + +export { getAmount };