From 4e7fd7c804d39c445ec5a2fc1a1c2becb14af85d Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Sep 2024 10:31:51 +0000 Subject: [PATCH 01/32] handle zap request --- src/lib/server/locks/nostr-notifications.ts | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/lib/server/locks/nostr-notifications.ts b/src/lib/server/locks/nostr-notifications.ts index 66130a373..f9debdfd3 100644 --- a/src/lib/server/locks/nostr-notifications.ts +++ b/src/lib/server/locks/nostr-notifications.ts @@ -222,6 +222,34 @@ async function handleNostrNotification(nostrNotification: NostRNotification): Pr sig: '' } satisfies Event; } + + if (nostrNotification.kind === Kind.ZapRequest) { + const npub = nostrNotification.dest; + + if (!npub) { + return; + } + + const receiverPublicKeyHex = nostrToHex(npub); + + return { + id: '', + content: await nip04.encrypt(nostrPrivateKeyHex, receiverPublicKeyHex, content), + created_at: getUnixTime( + max([ + nostrNotification.minCreatedAt ?? nostrNotification.createdAt, + nostrNotification.createdAt + ]) + ), + pubkey: nostrPublicKeyHex, + tags: [ + ['p', receiverPublicKeyHex], + ['bootikVersion', String(NOSTR_PROTOCOL_VERSION)] + ], + kind: Kind.EncryptedDirectMessage, + sig: '' + } satisfies Event; + } })(); if (!event) { From beca9f52cfdc517b590eff4d15c2aaef6a6a0721 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Sep 2024 11:00:44 +0000 Subject: [PATCH 02/32] handle zap request --- src/lib/server/locks/nostr-notifications.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/server/locks/nostr-notifications.ts b/src/lib/server/locks/nostr-notifications.ts index f9debdfd3..8598a9a1d 100644 --- a/src/lib/server/locks/nostr-notifications.ts +++ b/src/lib/server/locks/nostr-notifications.ts @@ -223,7 +223,7 @@ async function handleNostrNotification(nostrNotification: NostRNotification): Pr } satisfies Event; } - if (nostrNotification.kind === Kind.ZapRequest) { + if (nostrNotification.kind === Kind.Zap) { const npub = nostrNotification.dest; if (!npub) { @@ -246,7 +246,7 @@ async function handleNostrNotification(nostrNotification: NostRNotification): Pr ['p', receiverPublicKeyHex], ['bootikVersion', String(NOSTR_PROTOCOL_VERSION)] ], - kind: Kind.EncryptedDirectMessage, + kind: Kind.Zap, sig: '' } satisfies Event; } From 71fc935921808f9d904c9b71b640999ed3078059 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Sep 2024 12:01:11 +0000 Subject: [PATCH 03/32] handle zap request --- src/lib/server/locks/nostr-notifications.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/server/locks/nostr-notifications.ts b/src/lib/server/locks/nostr-notifications.ts index 8598a9a1d..4bca6ee08 100644 --- a/src/lib/server/locks/nostr-notifications.ts +++ b/src/lib/server/locks/nostr-notifications.ts @@ -109,7 +109,7 @@ function initRelayPool() { if (!event.tags.some((tag) => tag[0] === 'p' && tag[1] === nostrPublicKeyHex)) { return; } - if (![Kind.EncryptedDirectMessage, Kind.Text].includes(event.kind)) { + if (![Kind.EncryptedDirectMessage, Kind.Text, Kind.Zap].includes(event.kind)) { return; } From 2b79d39998176e0e2239e90e641daa012ff501a1 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 1 Oct 2024 09:44:46 +0000 Subject: [PATCH 04/32] display zap on /admin/nostr --- .../admin[[hash=admin_hash]]/nostr/+page.svelte | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.svelte b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.svelte index 8100ef9e6..0cf37ef0a 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.svelte +++ b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.svelte @@ -107,6 +107,19 @@ +

Zaps

+ +
    + {#each data.receivedMessages.filter((mes) => mes.kind === 9735) as message} +
  • + {#if message.kind === 4} + '⚡' + {/if} + + | You were zapped | 21 sats +
  • + {/each} +

Received messages

    From 8ddb81e0695e9c7d5c2812d881c9f02b8f445858 Mon Sep 17 00:00:00 2001 From: ithiame Date: Mon, 4 Nov 2024 15:52:38 +0000 Subject: [PATCH 05/32] Bolt 12 address phoenixD --- src/lib/components/CmsDesign.svelte | 6 ++++++ src/lib/server/cms.ts | 17 +++++++++++++++-- src/lib/server/phoenixd.ts | 11 +++++++++++ .../phoenixd/+page.server.ts | 6 ++++-- .../phoenixd/+page.svelte | 8 ++++++++ .../(app)/phoenixd/bolt12/qrcode/+server.ts | 10 ++++++++++ src/routes/+layout.server.ts | 4 +++- 7 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 src/routes/(app)/phoenixd/bolt12/qrcode/+server.ts diff --git a/src/lib/components/CmsDesign.svelte b/src/lib/components/CmsDesign.svelte index 9905a0590..5230df9f9 100644 --- a/src/lib/components/CmsDesign.svelte +++ b/src/lib/components/CmsDesign.svelte @@ -181,6 +181,12 @@ : ''}{token.height ? `height: ${token.height}px;` : ''}" /> + {:else if token.type === 'qrCode'} + {#if token.slug === 'Bolt12'} + + QR code + + {/if} {:else if token.type === 'html'}
    diff --git a/src/lib/server/cms.ts b/src/lib/server/cms.ts index 03e5e1be4..5c2b6df26 100644 --- a/src/lib/server/cms.ts +++ b/src/lib/server/cms.ts @@ -76,7 +76,9 @@ type TokenObject = slug: string; display: string | undefined; raw: string; - }; + } + | { type: 'qrCode'; slug: string; raw: string }; + export async function cmsFromContent( { content, mobileContent }: { content: string; mobileContent?: string }, locals: Partial> @@ -98,6 +100,7 @@ export async function cmsFromContent( /\[TagProducts=(?[\p{L}\d_-]+)(?:[?\s]display=(?[a-z0-9-]+))?\]/giu; const GALLERY_WIDGET_REGEX = /\[Gallery=(?[\p{L}\d_-]+)(?:[?\s]display=(?[a-z0-9-]+))?\]/giu; + const QRCODE_REGEX = /\[QRCode=(?[\p{L}\d_-]+)\]/giu; const productSlugs = new Set(); const challengeSlugs = new Set(); @@ -109,6 +112,7 @@ export async function cmsFromContent( const countdownFormSlugs = new Set(); const tagProductsSlugs = new Set(); const gallerySlugs = new Set(); + const qrCodeSlugs = new Set(); const tokens: { desktop: Array; @@ -138,7 +142,8 @@ export async function cmsFromContent( ...matchAndSort(content, PICTURE_WIDGET_REGEX, 'pictureWidget'), ...matchAndSort(content, COUNTDOWN_WIDGET_REGEX, 'countdownWidget'), ...matchAndSort(content, TAG_PRODUCTS_REGEX, 'tagProducts'), - ...matchAndSort(content, GALLERY_WIDGET_REGEX, 'galleryWidget') + ...matchAndSort(content, GALLERY_WIDGET_REGEX, 'galleryWidget'), + ...matchAndSort(content, QRCODE_REGEX, 'qrCode') ].sort((a, b) => (a.index ?? 0) - (b.index ?? 0)); for (const match of matches) { const html = trimPrefix(trimSuffix(content.slice(index, match.index), '

    '), '

    '); @@ -245,6 +250,14 @@ export async function cmsFromContent( raw: match[0] }); break; + case 'qrCode': + qrCodeSlugs.add(match.groups.slug); + token.push({ + type: 'qrCode', + slug: match.groups.slug, + raw: match[0] + }); + break; } } index = match.index + match[0].length; diff --git a/src/lib/server/phoenixd.ts b/src/lib/server/phoenixd.ts index 47cd7e777..d3ee5efe2 100644 --- a/src/lib/server/phoenixd.ts +++ b/src/lib/server/phoenixd.ts @@ -34,6 +34,17 @@ export async function phoenixdBalance(): Promise<{ balanceSat: number; feeCredit return await res.json(); } +export async function phoenixdGetBolt12(): Promise { + const res = await fetch(`${runtimeConfig.phoenixd.url}/getoffer`, { + headers: { + Authorization: `Basic ${Buffer.from(`:${runtimeConfig.phoenixd.password}`).toString( + 'base64' + )}` + } + }); + + return await res.text(); +} export async function phoenixdDetected(url?: string): Promise { return await Promise.race([ fetch(`${url || runtimeConfig.phoenixd.url}/getinfo`).then( diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts index 26b7760f7..9f4665b78 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts +++ b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts @@ -5,6 +5,7 @@ import { isPhoenixdConfigured, phoenixdBalance, phoenixdDetected, + phoenixdGetBolt12, phoenixdInfo, phoenixdPayInvoice, phoenixdSendOnChain @@ -29,11 +30,12 @@ export const load = async () => { try { const nodeInfo = await phoenixdInfo(); const balance = await phoenixdBalance(); - + const bolt12Address = await phoenixdGetBolt12(); return { phoenixd: runtimeConfig.phoenixd, nodeInfo, - balance + balance, + bolt12Address }; } catch (err) { return { diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.svelte b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.svelte index 2691a1073..33f677ed0 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.svelte +++ b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.svelte @@ -22,6 +22,7 @@ let withdrawMode = 'bolt11' as 'bolt11' | 'bitcoin'; let defaultUrl = data.phoenixd.url || 'http://localhost:9740'; + let showBolt12 = false;

    PhoenixD

    @@ -92,6 +93,9 @@
    + {#if data.nodeInfo}
    + {#if showBolt12} +

    Bolt12 address: {data.bolt12Address}

    +

    To use it on page CMS, use this code : [QRCode=Bolt12]

    + {/if}
    diff --git a/src/routes/(app)/phoenixd/bolt12/qrcode/+server.ts b/src/routes/(app)/phoenixd/bolt12/qrcode/+server.ts new file mode 100644 index 000000000..cf19d108d --- /dev/null +++ b/src/routes/(app)/phoenixd/bolt12/qrcode/+server.ts @@ -0,0 +1,10 @@ +import { phoenixdGetBolt12 } from '$lib/server/phoenixd'; +import qrcode from 'qrcode'; + +export async function GET({}) { + const bolt12Address = await phoenixdGetBolt12(); + return new Response(await qrcode.toString('lightning:' + bolt12Address, { type: 'svg' }), { + headers: { 'content-type': 'image/svg+xml' }, + status: 200 + }); +} diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index 2d269b889..6e9e4551b 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -1,3 +1,4 @@ +import { phoenixdGetBolt12 } from '$lib/server/phoenixd'; import { runtimeConfig, runtimeConfigUpdatedAt } from '$lib/server/runtime-config'; import { CUSTOMER_ROLE_ID } from '$lib/types/User'; @@ -38,6 +39,7 @@ export async function load(event) { viewportWidth, contactModes: runtimeConfig.contactModes, hideFromSearchEngines: runtimeConfig.hideFromSearchEngines, - ageRestriction: runtimeConfig.ageRestriction + ageRestriction: runtimeConfig.ageRestriction, + bolt12Address: phoenixdGetBolt12() }; } From 2b57198b3bab095e7629d2e22d3899baebdb5637 Mon Sep 17 00:00:00 2001 From: ithiame Date: Mon, 4 Nov 2024 16:20:57 +0000 Subject: [PATCH 06/32] Bolt 12 address phoenixD --- .../phoenixd/+page.server.ts | 3 ++- .../(app)/phoenixd/bolt12/qrcode/+server.ts | 22 ++++++++++++++----- src/routes/+layout.server.ts | 9 +++++++- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts index 9f4665b78..83aa91cb4 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts +++ b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts @@ -41,7 +41,8 @@ export const load = async () => { return { phoenixd: runtimeConfig.phoenixd, nodeInfo: null, - balance: null + balance: null, + bolt12Address: null }; } }; diff --git a/src/routes/(app)/phoenixd/bolt12/qrcode/+server.ts b/src/routes/(app)/phoenixd/bolt12/qrcode/+server.ts index cf19d108d..2702390a9 100644 --- a/src/routes/(app)/phoenixd/bolt12/qrcode/+server.ts +++ b/src/routes/(app)/phoenixd/bolt12/qrcode/+server.ts @@ -2,9 +2,21 @@ import { phoenixdGetBolt12 } from '$lib/server/phoenixd'; import qrcode from 'qrcode'; export async function GET({}) { - const bolt12Address = await phoenixdGetBolt12(); - return new Response(await qrcode.toString('lightning:' + bolt12Address, { type: 'svg' }), { - headers: { 'content-type': 'image/svg+xml' }, - status: 200 - }); + try { + const bolt12Address = await phoenixdGetBolt12(); + + const svgQRCode = await qrcode.toString('lightning:' + bolt12Address, { type: 'svg' }); + + return new Response(svgQRCode, { + headers: { 'content-type': 'image/svg+xml' }, + status: 200 + }); + } catch (error) { + console.error('Error on phoenixdGetBolt12:', error); + + return new Response("Erreur lors de la génération de l'adresse Bolt12", { + headers: { 'content-type': 'text/plain' }, + status: 500 + }); + } } diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index 6e9e4551b..dc70385ce 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -21,6 +21,13 @@ export async function load(event) { return `width=${runtimeConfig.viewportContentWidth}`; } })(); + let bolt12Address = ''; + + try { + bolt12Address = await phoenixdGetBolt12(); + } catch (error) { + bolt12Address = 'Bolt12'; + } return { plausibleScriptUrl: runtimeConfig.plausibleScriptUrl, @@ -40,6 +47,6 @@ export async function load(event) { contactModes: runtimeConfig.contactModes, hideFromSearchEngines: runtimeConfig.hideFromSearchEngines, ageRestriction: runtimeConfig.ageRestriction, - bolt12Address: phoenixdGetBolt12() + bolt12Address }; } From af880211a4da0609fa25f18fb7351d5ee3f9762e Mon Sep 17 00:00:00 2001 From: ithiame Date: Mon, 4 Nov 2024 16:32:13 +0000 Subject: [PATCH 07/32] lightning payment qr code clickable --- src/lib/utils/lightningPaymentQr.ts | 12 ++++++++++++ src/routes/(app)/order/[id]/+page.svelte | 19 ++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 src/lib/utils/lightningPaymentQr.ts diff --git a/src/lib/utils/lightningPaymentQr.ts b/src/lib/utils/lightningPaymentQr.ts new file mode 100644 index 000000000..fe5e7ed81 --- /dev/null +++ b/src/lib/utils/lightningPaymentQr.ts @@ -0,0 +1,12 @@ +import type { Currency } from '$lib/types/Currency'; +import { toBitcoins } from './toBitcoins'; + +export function lightningPaymentQrCodeString( + paymentAddress: string, + paymentAmount: number, + paymentCurrency: Currency +) { + return `lightning:${paymentAddress}?amount=${toBitcoins(paymentAmount, paymentCurrency) + .toLocaleString('en-US', { maximumFractionDigits: 8 }) + .replaceAll(',', '')}`; +} diff --git a/src/routes/(app)/order/[id]/+page.svelte b/src/routes/(app)/order/[id]/+page.svelte index 7bb17ca0e..665066bb6 100644 --- a/src/routes/(app)/order/[id]/+page.svelte +++ b/src/routes/(app)/order/[id]/+page.svelte @@ -17,6 +17,7 @@ import { bitcoinPaymentQrCodeString } from '$lib/utils/bitcoinPaymentQr.js'; import Picture from '$lib/components/Picture.svelte'; import IconStripe from '$lib/components/icons/IconStripe.svelte'; + import { lightningPaymentQrCodeString } from '$lib/utils/lightningPaymentQr'; let currentDate = new Date(); export let data; @@ -276,11 +277,19 @@ {#if payment.status === 'pending'} {#if payment.method === 'lightning' || payment.method === 'card'} - QR code + + QR code {/if} {#if payment.method === 'bitcoin' && payment.address} {t('order.clickQR')} From c77e0ab8416cabef153f56bea3feb894ba0fc9a7 Mon Sep 17 00:00:00 2001 From: ithiame Date: Tue, 5 Nov 2024 12:52:31 +0000 Subject: [PATCH 08/32] =?UTF-8?q?=20=E2=9A=A1=20Manage=20nostr-bot=20certi?= =?UTF-8?q?fy=20with=20lightning=20address=20via=20phoenixd=20getlnaddress?= =?UTF-8?q?=20#1580?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/server/phoenixd.ts | 12 ++++++++++++ src/lib/server/runtime-config.ts | 3 ++- .../admin[[hash=admin_hash]]/nostr/+page.server.ts | 2 ++ .../phoenixd/+page.server.ts | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/lib/server/phoenixd.ts b/src/lib/server/phoenixd.ts index 47cd7e777..2c43a0620 100644 --- a/src/lib/server/phoenixd.ts +++ b/src/lib/server/phoenixd.ts @@ -34,6 +34,18 @@ export async function phoenixdBalance(): Promise<{ balanceSat: number; feeCredit return await res.json(); } +export async function phoenixdLndAddress(): Promise { + const res = await fetch(`${runtimeConfig.phoenixd.url}/getlnaddress`, { + headers: { + Authorization: `Basic ${Buffer.from(`:${runtimeConfig.phoenixd.password}`).toString( + 'base64' + )}` + } + }); + + return await res.text(); +} + export async function phoenixdDetected(url?: string): Promise { return await Promise.race([ fetch(`${url || runtimeConfig.phoenixd.url}/getinfo`).then( diff --git a/src/lib/server/runtime-config.ts b/src/lib/server/runtime-config.ts index d6eed6249..6dfc5da16 100644 --- a/src/lib/server/runtime-config.ts +++ b/src/lib/server/runtime-config.ts @@ -123,7 +123,8 @@ const baseConfig = { phoenixd: { url: 'http://localhost:9740', enabled: false, - password: '' + password: '', + lndAddress: '' }, productActionSettings: { eShop: { diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts index 4b6c2a9ba..43bb494d2 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts +++ b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts @@ -56,6 +56,8 @@ export const actions = { display_name: runtimeConfig.brandName, website: ORIGIN, ...(lnAddress && { lud16: `ln@${domainName}` }), + ...(!lnAddress && + runtimeConfig.phoenixd.lndAddress && { lud16: runtimeConfig.phoenixd.lndAddress }), // about: '', ...(runtimeConfig.logo && { picture: pictureUrl }), nip05: `_@${domainName}`, diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts index 26b7760f7..7f4abbb71 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts +++ b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts @@ -6,6 +6,7 @@ import { phoenixdBalance, phoenixdDetected, phoenixdInfo, + phoenixdLndAddress, phoenixdPayInvoice, phoenixdSendOnChain } from '$lib/server/phoenixd.js'; @@ -76,6 +77,7 @@ export const actions = { .parse(Object.fromEntries(await event.request.formData())); runtimeConfig.phoenixd.password = parsed.password; + runtimeConfig.phoenixd.lndAddress = await phoenixdLndAddress(); await collections.runtimeConfig.updateOne( { _id: 'phoenixd' }, From 37ea850cbaf1b462e5dc172dad99559523460077 Mon Sep 17 00:00:00 2001 From: ithiame Date: Wed, 6 Nov 2024 14:02:16 +0000 Subject: [PATCH 09/32] update --- src/lib/server/phoenixd.ts | 2 +- src/lib/server/runtime-config.ts | 2 +- .../(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts | 2 +- .../(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lib/server/phoenixd.ts b/src/lib/server/phoenixd.ts index 45ed60f73..d48df777d 100644 --- a/src/lib/server/phoenixd.ts +++ b/src/lib/server/phoenixd.ts @@ -46,7 +46,7 @@ export async function phoenixdGetBolt12(): Promise { return await res.text(); } -export async function phoenixdLndAddress(): Promise { +export async function phoenixdLnAddress(): Promise { const res = await fetch(`${runtimeConfig.phoenixd.url}/getlnaddress`, { headers: { Authorization: `Basic ${Buffer.from(`:${runtimeConfig.phoenixd.password}`).toString( diff --git a/src/lib/server/runtime-config.ts b/src/lib/server/runtime-config.ts index 6dfc5da16..cfa415f2d 100644 --- a/src/lib/server/runtime-config.ts +++ b/src/lib/server/runtime-config.ts @@ -124,7 +124,7 @@ const baseConfig = { url: 'http://localhost:9740', enabled: false, password: '', - lndAddress: '' + lnAddress: '' }, productActionSettings: { eShop: { diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts index 43bb494d2..d07e22e07 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts +++ b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts @@ -57,7 +57,7 @@ export const actions = { website: ORIGIN, ...(lnAddress && { lud16: `ln@${domainName}` }), ...(!lnAddress && - runtimeConfig.phoenixd.lndAddress && { lud16: runtimeConfig.phoenixd.lndAddress }), + runtimeConfig.phoenixd.lnAddress && { lud16: runtimeConfig.phoenixd.lnAddress }), // about: '', ...(runtimeConfig.logo && { picture: pictureUrl }), nip05: `_@${domainName}`, diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts index 38093ed3f..9a7e9f90b 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts +++ b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts @@ -7,7 +7,7 @@ import { phoenixdDetected, phoenixdGetBolt12, phoenixdInfo, - phoenixdLndAddress, + phoenixdLnAddress, phoenixdPayInvoice, phoenixdSendOnChain } from '$lib/server/phoenixd.js'; @@ -80,7 +80,6 @@ export const actions = { .parse(Object.fromEntries(await event.request.formData())); runtimeConfig.phoenixd.password = parsed.password; - runtimeConfig.phoenixd.lndAddress = await phoenixdLndAddress(); await collections.runtimeConfig.updateOne( { _id: 'phoenixd' }, From 406fa8b9ec6ad117123cad1159ac979bee97c30c Mon Sep 17 00:00:00 2001 From: ithiame Date: Wed, 6 Nov 2024 14:18:48 +0000 Subject: [PATCH 10/32] update --- .../(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts index 9a7e9f90b..83aa91cb4 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts +++ b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts @@ -7,7 +7,6 @@ import { phoenixdDetected, phoenixdGetBolt12, phoenixdInfo, - phoenixdLnAddress, phoenixdPayInvoice, phoenixdSendOnChain } from '$lib/server/phoenixd.js'; From 8111c87f0df8f98e059e2a46290980cfd9c0766c Mon Sep 17 00:00:00 2001 From: ithiame Date: Wed, 6 Nov 2024 14:26:45 +0000 Subject: [PATCH 11/32] update --- .../(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts index 83aa91cb4..92aa48b8e 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts +++ b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts @@ -7,6 +7,7 @@ import { phoenixdDetected, phoenixdGetBolt12, phoenixdInfo, + phoenixdLnAddress, phoenixdPayInvoice, phoenixdSendOnChain } from '$lib/server/phoenixd.js'; @@ -79,6 +80,7 @@ export const actions = { .parse(Object.fromEntries(await event.request.formData())); runtimeConfig.phoenixd.password = parsed.password; + runtimeConfig.phoenixd.lnAddress = await phoenixdLnAddress(); await collections.runtimeConfig.updateOne( { _id: 'phoenixd' }, From 9138b5c2cda3190c0c11755744fd16cdf22006fc Mon Sep 17 00:00:00 2001 From: ithiame Date: Fri, 8 Nov 2024 09:09:55 +0000 Subject: [PATCH 12/32] update --- .../admin[[hash=admin_hash]]/nostr/+page.server.ts | 4 +++- src/routes/.well-known/lnurlp/[id]/+server.ts | 11 ++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts index d07e22e07..3a65d4d1f 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts +++ b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts @@ -57,7 +57,9 @@ export const actions = { website: ORIGIN, ...(lnAddress && { lud16: `ln@${domainName}` }), ...(!lnAddress && - runtimeConfig.phoenixd.lnAddress && { lud16: runtimeConfig.phoenixd.lnAddress }), + runtimeConfig.phoenixd.lnAddress && { + lud16: runtimeConfig.phoenixd.lnAddress + }), // about: '', ...(runtimeConfig.logo && { picture: pictureUrl }), nip05: `_@${domainName}`, diff --git a/src/routes/.well-known/lnurlp/[id]/+server.ts b/src/routes/.well-known/lnurlp/[id]/+server.ts index 137a18f7d..0665d8142 100644 --- a/src/routes/.well-known/lnurlp/[id]/+server.ts +++ b/src/routes/.well-known/lnurlp/[id]/+server.ts @@ -18,14 +18,15 @@ export const OPTIONS = () => { }; export const GET = async ({ params, url }) => { - if (!isLightningConfigured) { + if (!isLightningConfigured && !runtimeConfig.phoenixd.lnAddress) { throw error(400, 'Lighting is not configured'); } + if (isLightningConfigured) { + const info = await lndGetInfo(); - const info = await lndGetInfo(); - - if (!info.uris.length) { - throw error(400, 'No public Lightning URI'); + if (!info.uris.length) { + throw error(400, 'No public Lightning URI'); + } } let picture: Buffer | null = null; From 0d5eb4fbf9383d31041cecd0102bdbb14b29d04e Mon Sep 17 00:00:00 2001 From: ithiame Date: Fri, 8 Nov 2024 10:04:06 +0000 Subject: [PATCH 13/32] update --- src/lib/server/orders.ts | 4 ++-- src/lib/server/phoenixd.ts | 7 ++++--- .../admin[[hash=admin_hash]]/nostr/+page.server.ts | 2 +- src/routes/lightning/pay/+server.ts | 14 +++++++++----- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/lib/server/orders.ts b/src/lib/server/orders.ts index 0f2e5ee7f..0025543cc 100644 --- a/src/lib/server/orders.ts +++ b/src/lib/server/orders.ts @@ -1070,8 +1070,8 @@ async function generatePaymentInfo(params: { const invoice = await phoenixdCreateInvoice(satoshis, label, params.orderId); return { - address: invoice.paymentAddress, - invoiceId: invoice.paymentHash, + address: invoice.payment_address, + invoiceId: invoice.r_hash, processor: 'phoenixd' }; } else { diff --git a/src/lib/server/phoenixd.ts b/src/lib/server/phoenixd.ts index d48df777d..576e71767 100644 --- a/src/lib/server/phoenixd.ts +++ b/src/lib/server/phoenixd.ts @@ -72,7 +72,7 @@ export async function phoenixdCreateInvoice( satoshis: number, description: string, externalId: string -): Promise<{ paymentHash: string; paymentAddress: string }> { +): Promise<{ payment_request: string; r_hash: string; payment_address: string }> { const res = await fetch(`${runtimeConfig.phoenixd.url}/createinvoice`, { method: 'POST', headers: { @@ -102,8 +102,9 @@ export async function phoenixdCreateInvoice( .parse(await res.json()); return { - paymentHash: json.paymentHash, - paymentAddress: json.serialized + payment_request: json.serialized, + r_hash: json.paymentHash, + payment_address: json.serialized }; } diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts index 3a65d4d1f..f00d7fda0 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts +++ b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts @@ -58,7 +58,7 @@ export const actions = { ...(lnAddress && { lud16: `ln@${domainName}` }), ...(!lnAddress && runtimeConfig.phoenixd.lnAddress && { - lud16: runtimeConfig.phoenixd.lnAddress + lud16: runtimeConfig.phoenixd.lnAddress.split('@')[0] + '@' + domainName }), // about: '', ...(runtimeConfig.logo && { picture: pictureUrl }), diff --git a/src/routes/lightning/pay/+server.ts b/src/routes/lightning/pay/+server.ts index 8de3c4ca7..3bcaf9352 100644 --- a/src/routes/lightning/pay/+server.ts +++ b/src/routes/lightning/pay/+server.ts @@ -1,8 +1,10 @@ import { isLightningConfigured, lndCreateInvoice } from '$lib/server/lnd'; +import { phoenixdCreateInvoice } from '$lib/server/phoenixd'; import { runtimeConfig } from '$lib/server/runtime-config'; import { SATOSHIS_PER_BTC } from '$lib/types/Currency'; import { error } from '@sveltejs/kit'; import { jwtVerify } from 'jose'; +import { ObjectId } from 'mongodb'; import { z } from 'zod'; export const OPTIONS = () => { @@ -16,7 +18,7 @@ export const OPTIONS = () => { }; export const GET = async ({ url }) => { - if (!isLightningConfigured) { + if (!isLightningConfigured && !runtimeConfig.phoenixd.lnAddress) { throw error(400, 'Lightning is not configured'); } @@ -42,10 +44,12 @@ export const GET = async ({ url }) => { }) .parse(result.payload); - const invoice = await lndCreateInvoice(amount, { - descriptionHash: await crypto.subtle.digest('SHA-256', new TextEncoder().encode(metadata)), - milliSatoshis: true - }); + const invoice = isLightningConfigured + ? await lndCreateInvoice(amount, { + descriptionHash: await crypto.subtle.digest('SHA-256', new TextEncoder().encode(metadata)), + milliSatoshis: true + }) + : await phoenixdCreateInvoice(amount, 'invoice', new ObjectId().toString()); return new Response( JSON.stringify({ From df15c01edd2f95fc20b2275c14d494ce773f46fa Mon Sep 17 00:00:00 2001 From: ithiame Date: Fri, 8 Nov 2024 10:24:49 +0000 Subject: [PATCH 14/32] update --- src/routes/lightning/pay/+server.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/routes/lightning/pay/+server.ts b/src/routes/lightning/pay/+server.ts index 3bcaf9352..16a9bcc9e 100644 --- a/src/routes/lightning/pay/+server.ts +++ b/src/routes/lightning/pay/+server.ts @@ -2,6 +2,7 @@ import { isLightningConfigured, lndCreateInvoice } from '$lib/server/lnd'; import { phoenixdCreateInvoice } from '$lib/server/phoenixd'; import { runtimeConfig } from '$lib/server/runtime-config'; import { SATOSHIS_PER_BTC } from '$lib/types/Currency'; +import { toSatoshis } from '$lib/utils/toSatoshis'; import { error } from '@sveltejs/kit'; import { jwtVerify } from 'jose'; import { ObjectId } from 'mongodb'; @@ -49,7 +50,11 @@ export const GET = async ({ url }) => { descriptionHash: await crypto.subtle.digest('SHA-256', new TextEncoder().encode(metadata)), milliSatoshis: true }) - : await phoenixdCreateInvoice(amount, 'invoice', new ObjectId().toString()); + : await phoenixdCreateInvoice( + toSatoshis({ amount, currency: 'SAT' }), + 'invoice', + new ObjectId().toString() + ); return new Response( JSON.stringify({ From fe0d8da08f66fa55040ada8ea61bae023bec5e73 Mon Sep 17 00:00:00 2001 From: ithiame Date: Fri, 8 Nov 2024 10:43:22 +0000 Subject: [PATCH 15/32] update --- src/routes/lightning/pay/+server.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/routes/lightning/pay/+server.ts b/src/routes/lightning/pay/+server.ts index 16a9bcc9e..1f8c6fdf2 100644 --- a/src/routes/lightning/pay/+server.ts +++ b/src/routes/lightning/pay/+server.ts @@ -50,11 +50,7 @@ export const GET = async ({ url }) => { descriptionHash: await crypto.subtle.digest('SHA-256', new TextEncoder().encode(metadata)), milliSatoshis: true }) - : await phoenixdCreateInvoice( - toSatoshis({ amount, currency: 'SAT' }), - 'invoice', - new ObjectId().toString() - ); + : await phoenixdCreateInvoice(100, 'invoice', new ObjectId().toString()); return new Response( JSON.stringify({ From 9d358dd22c1eb6a429f9a18078d2a638820edfe9 Mon Sep 17 00:00:00 2001 From: ithiame Date: Fri, 8 Nov 2024 10:50:41 +0000 Subject: [PATCH 16/32] update --- src/routes/lightning/pay/+server.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/routes/lightning/pay/+server.ts b/src/routes/lightning/pay/+server.ts index 1f8c6fdf2..166284ad9 100644 --- a/src/routes/lightning/pay/+server.ts +++ b/src/routes/lightning/pay/+server.ts @@ -50,7 +50,11 @@ export const GET = async ({ url }) => { descriptionHash: await crypto.subtle.digest('SHA-256', new TextEncoder().encode(metadata)), milliSatoshis: true }) - : await phoenixdCreateInvoice(100, 'invoice', new ObjectId().toString()); + : await phoenixdCreateInvoice( + toSatoshis({ amount, currency: 'BTC' }), + 'invoice', + new ObjectId().toString() + ); return new Response( JSON.stringify({ From ae889fbdd61d46038dd8bd06956841492460db1c Mon Sep 17 00:00:00 2001 From: ithiame Date: Fri, 8 Nov 2024 11:04:47 +0000 Subject: [PATCH 17/32] update --- src/routes/lightning/pay/+server.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/routes/lightning/pay/+server.ts b/src/routes/lightning/pay/+server.ts index 166284ad9..3e0772492 100644 --- a/src/routes/lightning/pay/+server.ts +++ b/src/routes/lightning/pay/+server.ts @@ -2,7 +2,6 @@ import { isLightningConfigured, lndCreateInvoice } from '$lib/server/lnd'; import { phoenixdCreateInvoice } from '$lib/server/phoenixd'; import { runtimeConfig } from '$lib/server/runtime-config'; import { SATOSHIS_PER_BTC } from '$lib/types/Currency'; -import { toSatoshis } from '$lib/utils/toSatoshis'; import { error } from '@sveltejs/kit'; import { jwtVerify } from 'jose'; import { ObjectId } from 'mongodb'; @@ -44,17 +43,13 @@ export const GET = async ({ url }) => { metadata: z.string() }) .parse(result.payload); - + console.log('FROOOOOOOOOOOOOOOOOOM ZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP ! ' + amount); const invoice = isLightningConfigured ? await lndCreateInvoice(amount, { descriptionHash: await crypto.subtle.digest('SHA-256', new TextEncoder().encode(metadata)), milliSatoshis: true }) - : await phoenixdCreateInvoice( - toSatoshis({ amount, currency: 'BTC' }), - 'invoice', - new ObjectId().toString() - ); + : await phoenixdCreateInvoice(amount, 'invoice zap phoenixd !', new ObjectId().toString()); return new Response( JSON.stringify({ From 52e2e2e39fd196545d0bd70568bbe3e3b9df0884 Mon Sep 17 00:00:00 2001 From: ithiame Date: Fri, 8 Nov 2024 11:11:24 +0000 Subject: [PATCH 18/32] update --- src/routes/lightning/pay/+server.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/routes/lightning/pay/+server.ts b/src/routes/lightning/pay/+server.ts index 3e0772492..c87ace9c4 100644 --- a/src/routes/lightning/pay/+server.ts +++ b/src/routes/lightning/pay/+server.ts @@ -43,13 +43,16 @@ export const GET = async ({ url }) => { metadata: z.string() }) .parse(result.payload); - console.log('FROOOOOOOOOOOOOOOOOOM ZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP ! ' + amount); const invoice = isLightningConfigured ? await lndCreateInvoice(amount, { descriptionHash: await crypto.subtle.digest('SHA-256', new TextEncoder().encode(metadata)), milliSatoshis: true }) - : await phoenixdCreateInvoice(amount, 'invoice zap phoenixd !', new ObjectId().toString()); + : await phoenixdCreateInvoice( + amount / 1000, + 'invoice zap phoenixd !', + new ObjectId().toString() + ); return new Response( JSON.stringify({ From f6ca63cdd7fe72e19025914c56cdecee03765034 Mon Sep 17 00:00:00 2001 From: ithiame Date: Fri, 8 Nov 2024 12:36:11 +0000 Subject: [PATCH 19/32] update --- src/routes/lightning/pay/+server.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/routes/lightning/pay/+server.ts b/src/routes/lightning/pay/+server.ts index c87ace9c4..d6230a9d5 100644 --- a/src/routes/lightning/pay/+server.ts +++ b/src/routes/lightning/pay/+server.ts @@ -50,7 +50,9 @@ export const GET = async ({ url }) => { }) : await phoenixdCreateInvoice( amount / 1000, - 'invoice zap phoenixd !', + Buffer.from( + await crypto.subtle.digest('SHA-256', new TextEncoder().encode(metadata)) + ).toString('base64'), new ObjectId().toString() ); From aa5cea67f4205e5e33bbf7b69845c6f628c9af33 Mon Sep 17 00:00:00 2001 From: ithiame Date: Fri, 8 Nov 2024 12:44:51 +0000 Subject: [PATCH 20/32] update --- src/routes/lightning/pay/+server.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/routes/lightning/pay/+server.ts b/src/routes/lightning/pay/+server.ts index d6230a9d5..12c0d98b3 100644 --- a/src/routes/lightning/pay/+server.ts +++ b/src/routes/lightning/pay/+server.ts @@ -22,14 +22,19 @@ export const GET = async ({ url }) => { throw error(400, 'Lightning is not configured'); } - const { amount, metadata: metadataJwt } = z + const { + amount, + metadata: metadataJwt, + description + } = z .object({ amount: z .number({ coerce: true }) .int() .min(1) .max(SATOSHIS_PER_BTC * 1000), - metadata: z.string() + metadata: z.string(), + description: z.string() }) .parse(Object.fromEntries(url.searchParams)); @@ -48,13 +53,7 @@ export const GET = async ({ url }) => { descriptionHash: await crypto.subtle.digest('SHA-256', new TextEncoder().encode(metadata)), milliSatoshis: true }) - : await phoenixdCreateInvoice( - amount / 1000, - Buffer.from( - await crypto.subtle.digest('SHA-256', new TextEncoder().encode(metadata)) - ).toString('base64'), - new ObjectId().toString() - ); + : await phoenixdCreateInvoice(amount / 1000, description, new ObjectId().toString()); return new Response( JSON.stringify({ From 2f1ac66988d77b224de38fb2ca0c6ec4336a4519 Mon Sep 17 00:00:00 2001 From: ithiame Date: Fri, 8 Nov 2024 12:52:14 +0000 Subject: [PATCH 21/32] update --- src/routes/lightning/pay/+server.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/routes/lightning/pay/+server.ts b/src/routes/lightning/pay/+server.ts index 12c0d98b3..f6836a534 100644 --- a/src/routes/lightning/pay/+server.ts +++ b/src/routes/lightning/pay/+server.ts @@ -22,22 +22,17 @@ export const GET = async ({ url }) => { throw error(400, 'Lightning is not configured'); } - const { - amount, - metadata: metadataJwt, - description - } = z + const { amount, metadata: metadataJwt } = z .object({ amount: z .number({ coerce: true }) .int() .min(1) .max(SATOSHIS_PER_BTC * 1000), - metadata: z.string(), - description: z.string() + metadata: z.string() }) .parse(Object.fromEntries(url.searchParams)); - + console.log('OBJEEEEEEEEEEEEEEEEEECT LOG ' + Object.fromEntries(url.searchParams)); const result = await jwtVerify( metadataJwt, Buffer.from(runtimeConfig.lnurlPayMetadataJwtSigningKey) @@ -53,7 +48,7 @@ export const GET = async ({ url }) => { descriptionHash: await crypto.subtle.digest('SHA-256', new TextEncoder().encode(metadata)), milliSatoshis: true }) - : await phoenixdCreateInvoice(amount / 1000, description, new ObjectId().toString()); + : await phoenixdCreateInvoice(amount / 1000, 'Zap !', new ObjectId().toString()); return new Response( JSON.stringify({ From 50423479c4b68997e7f98c4da0b6bd0cd1fe23f9 Mon Sep 17 00:00:00 2001 From: ithiame Date: Fri, 8 Nov 2024 12:59:29 +0000 Subject: [PATCH 22/32] update --- src/routes/lightning/pay/+server.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/routes/lightning/pay/+server.ts b/src/routes/lightning/pay/+server.ts index f6836a534..bece321c7 100644 --- a/src/routes/lightning/pay/+server.ts +++ b/src/routes/lightning/pay/+server.ts @@ -32,7 +32,9 @@ export const GET = async ({ url }) => { metadata: z.string() }) .parse(Object.fromEntries(url.searchParams)); - console.log('OBJEEEEEEEEEEEEEEEEEECT LOG ' + Object.fromEntries(url.searchParams)); + console.log( + 'OBJEEEEEEEEEEEEEEEEEECT LOG ' + JSON.stringify(Object.fromEntries(url.searchParams)) + ); const result = await jwtVerify( metadataJwt, Buffer.from(runtimeConfig.lnurlPayMetadataJwtSigningKey) From 8032344b6a8d13aed43570e2aae890c843952901 Mon Sep 17 00:00:00 2001 From: ithiame Date: Fri, 8 Nov 2024 13:07:32 +0000 Subject: [PATCH 23/32] update --- src/routes/lightning/pay/+server.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/routes/lightning/pay/+server.ts b/src/routes/lightning/pay/+server.ts index bece321c7..e18de8864 100644 --- a/src/routes/lightning/pay/+server.ts +++ b/src/routes/lightning/pay/+server.ts @@ -22,19 +22,21 @@ export const GET = async ({ url }) => { throw error(400, 'Lightning is not configured'); } - const { amount, metadata: metadataJwt } = z + const { + amount, + metadata: metadataJwt, + comment + } = z .object({ amount: z .number({ coerce: true }) .int() .min(1) .max(SATOSHIS_PER_BTC * 1000), - metadata: z.string() + metadata: z.string(), + comment: z.string().default('Zap !') }) .parse(Object.fromEntries(url.searchParams)); - console.log( - 'OBJEEEEEEEEEEEEEEEEEECT LOG ' + JSON.stringify(Object.fromEntries(url.searchParams)) - ); const result = await jwtVerify( metadataJwt, Buffer.from(runtimeConfig.lnurlPayMetadataJwtSigningKey) @@ -50,7 +52,7 @@ export const GET = async ({ url }) => { descriptionHash: await crypto.subtle.digest('SHA-256', new TextEncoder().encode(metadata)), milliSatoshis: true }) - : await phoenixdCreateInvoice(amount / 1000, 'Zap !', new ObjectId().toString()); + : await phoenixdCreateInvoice(amount / 1000, comment, new ObjectId().toString()); return new Response( JSON.stringify({ From 4cba907e209cc53d009145a4e734627e72b0f2b8 Mon Sep 17 00:00:00 2001 From: ithiame Date: Mon, 11 Nov 2024 09:21:46 +0000 Subject: [PATCH 24/32] update --- src/lib/server/locks/nostr-notifications.ts | 2 +- src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.svelte | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/server/locks/nostr-notifications.ts b/src/lib/server/locks/nostr-notifications.ts index 4bca6ee08..f2ff05e97 100644 --- a/src/lib/server/locks/nostr-notifications.ts +++ b/src/lib/server/locks/nostr-notifications.ts @@ -95,7 +95,7 @@ function initRelayPool() { [ // Messages sent to us { - kinds: [Kind.EncryptedDirectMessage, Kind.Text], + kinds: [Kind.EncryptedDirectMessage, Kind.Text, Kind.Zap], '#p': [nostrPublicKeyHex] } ], diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.svelte b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.svelte index c058dca0c..88f6d6164 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.svelte +++ b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.svelte @@ -134,7 +134,7 @@ '⚡' {/if} - | You were zapped | 21 sats + | {JSON.stringify(message)} {/each}
From ddee47e5f1e0b23cd96a2532716bca3c4c7dceff Mon Sep 17 00:00:00 2001 From: ithiame Date: Mon, 18 Nov 2024 10:07:59 +0000 Subject: [PATCH 25/32] fix phoenixd bolt12 : save value in phoenixd runtimeConfig --- src/lib/server/runtime-config.ts | 3 ++- .../admin[[hash=admin_hash]]/phoenixd/+page.server.ts | 2 +- src/routes/+layout.server.ts | 10 +--------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/lib/server/runtime-config.ts b/src/lib/server/runtime-config.ts index d6eed6249..26cd4a637 100644 --- a/src/lib/server/runtime-config.ts +++ b/src/lib/server/runtime-config.ts @@ -123,7 +123,8 @@ const baseConfig = { phoenixd: { url: 'http://localhost:9740', enabled: false, - password: '' + password: '', + bolt12Address: '' }, productActionSettings: { eShop: { diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts index 83aa91cb4..7651fd2fd 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts +++ b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts @@ -79,7 +79,7 @@ export const actions = { .parse(Object.fromEntries(await event.request.formData())); runtimeConfig.phoenixd.password = parsed.password; - + runtimeConfig.phoenixd.bolt12Address = await phoenixdGetBolt12(); await collections.runtimeConfig.updateOne( { _id: 'phoenixd' }, { diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index dc70385ce..fa823f43b 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -1,4 +1,3 @@ -import { phoenixdGetBolt12 } from '$lib/server/phoenixd'; import { runtimeConfig, runtimeConfigUpdatedAt } from '$lib/server/runtime-config'; import { CUSTOMER_ROLE_ID } from '$lib/types/User'; @@ -21,13 +20,6 @@ export async function load(event) { return `width=${runtimeConfig.viewportContentWidth}`; } })(); - let bolt12Address = ''; - - try { - bolt12Address = await phoenixdGetBolt12(); - } catch (error) { - bolt12Address = 'Bolt12'; - } return { plausibleScriptUrl: runtimeConfig.plausibleScriptUrl, @@ -47,6 +39,6 @@ export async function load(event) { contactModes: runtimeConfig.contactModes, hideFromSearchEngines: runtimeConfig.hideFromSearchEngines, ageRestriction: runtimeConfig.ageRestriction, - bolt12Address + bolt12Address: runtimeConfig.phoenixd.bolt12Address }; } From e5a0e6b1f32f1002b40195c3fe84b1f9cbfb0111 Mon Sep 17 00:00:00 2001 From: ithiame Date: Mon, 18 Nov 2024 14:39:23 +0000 Subject: [PATCH 26/32] fix suggested changes --- src/lib/components/CmsDesign.svelte | 10 ++++++++++ src/lib/server/phoenixd.ts | 4 ++++ src/routes/(app)/phoenixd/bolt12/qrcode/+server.ts | 4 ++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/lib/components/CmsDesign.svelte b/src/lib/components/CmsDesign.svelte index 5230df9f9..743e97108 100644 --- a/src/lib/components/CmsDesign.svelte +++ b/src/lib/components/CmsDesign.svelte @@ -261,6 +261,16 @@ /> {:else if token.type === 'pictureWidget'} + {:else if token.type === 'qrCode'} + {#if token.slug === 'Bolt12'} + + QR code + + {/if} {:else if token.type === 'html'}
diff --git a/src/lib/server/phoenixd.ts b/src/lib/server/phoenixd.ts index d3ee5efe2..aa67103d3 100644 --- a/src/lib/server/phoenixd.ts +++ b/src/lib/server/phoenixd.ts @@ -43,6 +43,10 @@ export async function phoenixdGetBolt12(): Promise { } }); + if (!res.ok) { + throw error(500, `Error fetching Bolt12 offer: ${res.status} ${res.statusText}`); + } + return await res.text(); } export async function phoenixdDetected(url?: string): Promise { diff --git a/src/routes/(app)/phoenixd/bolt12/qrcode/+server.ts b/src/routes/(app)/phoenixd/bolt12/qrcode/+server.ts index 2702390a9..ce4e47030 100644 --- a/src/routes/(app)/phoenixd/bolt12/qrcode/+server.ts +++ b/src/routes/(app)/phoenixd/bolt12/qrcode/+server.ts @@ -1,9 +1,9 @@ -import { phoenixdGetBolt12 } from '$lib/server/phoenixd'; +import { runtimeConfig } from '$lib/server/runtime-config'; import qrcode from 'qrcode'; export async function GET({}) { try { - const bolt12Address = await phoenixdGetBolt12(); + const bolt12Address = runtimeConfig.phoenixd.bolt12Address; const svgQRCode = await qrcode.toString('lightning:' + bolt12Address, { type: 'svg' }); From 0f0cd6cbdc8b5cf92a2bd5293f4f8a0a8d7b9475 Mon Sep 17 00:00:00 2001 From: ithiame Date: Mon, 18 Nov 2024 14:47:11 +0000 Subject: [PATCH 27/32] fix suggested changes --- src/lib/server/phoenixd.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib/server/phoenixd.ts b/src/lib/server/phoenixd.ts index 2c43a0620..25a4b4923 100644 --- a/src/lib/server/phoenixd.ts +++ b/src/lib/server/phoenixd.ts @@ -42,6 +42,9 @@ export async function phoenixdLndAddress(): Promise { )}` } }); + if (!res.ok) { + throw error(500, `Could not get lnaddress: ${res.status} ${await res.text()}`); + } return await res.text(); } From 1dc8c6b538adb197d12233e1ca924aa3ac0c86b6 Mon Sep 17 00:00:00 2001 From: ithiame Date: Mon, 18 Nov 2024 16:44:28 +0000 Subject: [PATCH 28/32] fix suggested changes7 --- .../(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts | 5 ++--- .../(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts index 43bb494d2..55ad2683a 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts +++ b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts @@ -17,6 +17,7 @@ import { setTimeout } from 'node:timers/promises'; import type { Event } from 'nostr-tools'; import { uniqBy } from '$lib/utils/uniqBy'; import { NOSTR_PROTOCOL_VERSION } from '$lib/server/locks/handle-messages'; +import { phoenixdLndAddress } from '$lib/server/phoenixd'; export function load() { return { @@ -47,7 +48,7 @@ export const actions = { : null; const lndInfo = isLightningConfigured ? await lndGetInfo() : null; - const lnAddress = lndInfo?.uris?.[0]; + const lnAddress = lndInfo?.uris?.[0] ?? (await phoenixdLndAddress()); await collections.nostrNotifications.insertOne({ _id: new ObjectId(), @@ -56,8 +57,6 @@ export const actions = { display_name: runtimeConfig.brandName, website: ORIGIN, ...(lnAddress && { lud16: `ln@${domainName}` }), - ...(!lnAddress && - runtimeConfig.phoenixd.lndAddress && { lud16: runtimeConfig.phoenixd.lndAddress }), // about: '', ...(runtimeConfig.logo && { picture: pictureUrl }), nip05: `_@${domainName}`, diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts index 7f4abbb71..085aa25a3 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts +++ b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts @@ -77,7 +77,6 @@ export const actions = { .parse(Object.fromEntries(await event.request.formData())); runtimeConfig.phoenixd.password = parsed.password; - runtimeConfig.phoenixd.lndAddress = await phoenixdLndAddress(); await collections.runtimeConfig.updateOne( { _id: 'phoenixd' }, From 2a981e0cc0b1811c2befca2f1c30a817565188c8 Mon Sep 17 00:00:00 2001 From: ithiame Date: Mon, 18 Nov 2024 16:50:38 +0000 Subject: [PATCH 29/32] fix suggested changes7 --- .../(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts index 085aa25a3..26b7760f7 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts +++ b/src/routes/(app)/admin[[hash=admin_hash]]/phoenixd/+page.server.ts @@ -6,7 +6,6 @@ import { phoenixdBalance, phoenixdDetected, phoenixdInfo, - phoenixdLndAddress, phoenixdPayInvoice, phoenixdSendOnChain } from '$lib/server/phoenixd.js'; From a93522ffd18799b61b11ff7cec76d28590235d6c Mon Sep 17 00:00:00 2001 From: ithiame Date: Tue, 19 Nov 2024 08:38:36 +0000 Subject: [PATCH 30/32] fix suggested changes7 --- .../(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts index 55ad2683a..97a4d8fcc 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts +++ b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts @@ -17,7 +17,7 @@ import { setTimeout } from 'node:timers/promises'; import type { Event } from 'nostr-tools'; import { uniqBy } from '$lib/utils/uniqBy'; import { NOSTR_PROTOCOL_VERSION } from '$lib/server/locks/handle-messages'; -import { phoenixdLndAddress } from '$lib/server/phoenixd'; +import { isPhoenixdConfigured, phoenixdLndAddress } from '$lib/server/phoenixd'; export function load() { return { @@ -48,7 +48,9 @@ export const actions = { : null; const lndInfo = isLightningConfigured ? await lndGetInfo() : null; - const lnAddress = lndInfo?.uris?.[0] ?? (await phoenixdLndAddress()); + const lnAddress = + lndInfo?.uris?.[0] ?? + (isPhoenixdConfigured() ? await phoenixdLndAddress().catch(() => null) : null); await collections.nostrNotifications.insertOne({ _id: new ObjectId(), From 5281a9c0cf7d611fab2bb0d0136c4e97f986e400 Mon Sep 17 00:00:00 2001 From: ithiame Date: Mon, 2 Dec 2024 12:53:38 +0000 Subject: [PATCH 31/32] merge --- src/routes/(app)/order/[id]/+page.svelte | 1 - 1 file changed, 1 deletion(-) diff --git a/src/routes/(app)/order/[id]/+page.svelte b/src/routes/(app)/order/[id]/+page.svelte index ee8bba7cf..b65ae0b12 100644 --- a/src/routes/(app)/order/[id]/+page.svelte +++ b/src/routes/(app)/order/[id]/+page.svelte @@ -21,7 +21,6 @@ import CmsDesign from '$lib/components/CmsDesign.svelte'; import Picture from '$lib/components/Picture.svelte'; import IconStripe from '$lib/components/icons/IconStripe.svelte'; - import { lightningPaymentQrCodeString } from '$lib/utils/lightningPaymentQr'; let currentDate = new Date(); export let data; From 07d1f7e3b0fd6531487e9bc6651a2979161d6fa8 Mon Sep 17 00:00:00 2001 From: ithiame Date: Mon, 2 Dec 2024 12:58:14 +0000 Subject: [PATCH 32/32] merge --- .../(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts index 97a4d8fcc..b75cc3fbe 100644 --- a/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts +++ b/src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.server.ts @@ -17,7 +17,7 @@ import { setTimeout } from 'node:timers/promises'; import type { Event } from 'nostr-tools'; import { uniqBy } from '$lib/utils/uniqBy'; import { NOSTR_PROTOCOL_VERSION } from '$lib/server/locks/handle-messages'; -import { isPhoenixdConfigured, phoenixdLndAddress } from '$lib/server/phoenixd'; +import { isPhoenixdConfigured, phoenixdLnAddress } from '$lib/server/phoenixd'; export function load() { return { @@ -50,7 +50,7 @@ export const actions = { const lndInfo = isLightningConfigured ? await lndGetInfo() : null; const lnAddress = lndInfo?.uris?.[0] ?? - (isPhoenixdConfigured() ? await phoenixdLndAddress().catch(() => null) : null); + (isPhoenixdConfigured() ? await phoenixdLnAddress().catch(() => null) : null); await collections.nostrNotifications.insertOne({ _id: new ObjectId(),