diff options
| author | Adam Soltys <[email protected]> | 2024-11-21 10:47:25 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-11-21 10:47:25 -0800 |
| commit | 3b15d16339c9209f307f8453af91fba15f3d340c (patch) | |
| tree | d9f4ca8879c6a0b29ca8f6ad795c2154387626fd /lib | |
| parent | 5642b90b54084061cdbbf6f1dc70c38245b05d5f (diff) | |
| download | coinos-server-3b15d16339c9209f307f8453af91fba15f3d340c.tar.gz coinos-server-3b15d16339c9209f307f8453af91fba15f3d340c.zip | |
wip
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ecash.ts | 20 | ||||
| -rw-r--r-- | lib/invoices.ts | 8 |
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/ecash.ts b/lib/ecash.ts index 9ea4ec38..05326718 100644 --- a/lib/ecash.ts +++ b/lib/ecash.ts @@ -91,3 +91,23 @@ export async function init(amount = 10000) { } } +export async function payNostr(token) { + const decodedToken = getDecodedToken(token); + if (!decodedToken) { + console.error("could not decode token"); + return; + } + const proofs = token.getProofs(decodedToken); + const mint = token.getMint(decodedToken); + const paymentPayload: PaymentRequestPayload = { + id: request.id, + mint: mint, + unit: request.unit || "", + proofs: proofs, + }; + const paymentPayloadString = JSON.stringify(paymentPayload); + await nostrStore.sendNip17DirectMessageToNprofile( + transport.target, + paymentPayloadString, + ); +} diff --git a/lib/invoices.ts b/lib/invoices.ts index 0a94334c..30ae8402 100644 --- a/lib/invoices.ts +++ b/lib/invoices.ts @@ -13,6 +13,7 @@ const lq = rpc(config.liquid); export const generate = async ({ invoice, user }) => { let { bolt11, + bolt12, aid, currency, expiry, @@ -71,6 +72,13 @@ export const generate = async ({ invoice, user }) => { if (r.payee !== nodeid) fail("invalid invoice"); amount = Math.round(r.amount_msat / 1000); r.bolt11 = bolt11; + } else if (bolt12) { + r = await ln.offer({ + amount_msat: amount ? `${amount + tip}sat` : "any", + label: id, + description: memo || "", + absolute_expiry: expiry, + }); } else { expiry ||= 60 * 60 * 24 * 30; r = await ln.invoice({ |
