From 82bf36f0646e7620e50ac12ebdeb95f2c399db53 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Mon, 17 Jun 2024 14:38:04 -0300 Subject: [PATCH] feat(bolt11): create getAmount function --- src/utils/bolt11.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/utils/bolt11.ts 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 };