diff options
| author | Adam Soltys <[email protected]> | 2025-02-11 13:40:05 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-02-11 13:40:05 -0800 |
| commit | de7435e34580e1a9b4b8d95b2a5013112414098f (patch) | |
| tree | 97074cadf3a63512c2c5f554a3083924fd046b74 /lib | |
| parent | 8add46c0975686ce0967c2c38514a31aad6ee8cb (diff) | |
| download | coinos-server-de7435e34580e1a9b4b8d95b2a5013112414098f.tar.gz coinos-server-de7435e34580e1a9b4b8d95b2a5013112414098f.zip | |
default app on register
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/nostr.ts | 8 | ||||
| -rw-r--r-- | lib/nwc.ts | 3 | ||||
| -rw-r--r-- | lib/register.ts | 13 |
3 files changed, 18 insertions, 6 deletions
diff --git a/lib/nostr.ts b/lib/nostr.ts index 77726f38..9f5a2698 100644 --- a/lib/nostr.ts +++ b/lib/nostr.ts @@ -3,7 +3,7 @@ import { db, g, s } from "$lib/db"; import { l, warn } from "$lib/logging"; import { scan } from "$lib/strfry"; import { fail, fields, getUser, pick } from "$lib/utils"; -import { finalizeEvent, getPublicKey, nip19 } from "nostr-tools"; +import { finalizeEvent, getPublicKey, nip19, verifyEvent } from "nostr-tools"; import type { Event } from "nostr-tools"; import { AbstractSimplePool } from "nostr-tools/abstract-pool"; import { Relay } from "nostr-tools/relay"; @@ -30,8 +30,8 @@ export const anon = (pubkey) => ({ followers: [], }); -export async function send(ev, url = config.nostr) { - if (!ev?.id) return; +export async function publish(ev, url = config.nostr) { + if (!verifyEvent(ev)) fail("Invalid event"); const r = await Relay.connect(url); await r.publish(ev); r.close(); @@ -98,7 +98,7 @@ export async function handleZap(invoice, sender = undefined) { l("sending receipt"); const relays = relays_tag.slice(1).filter((r) => r?.startsWith("ws")); - relays.push(config.nostr); + relays.push(config.nostr); relays.map(async (url) => { try { const r = await Relay.connect(url); @@ -2,7 +2,7 @@ import config from "$config"; import { db, g } from "$lib/db"; import { generate } from "$lib/invoices"; import ln from "$lib/ln"; -import { err } from "$lib/logging"; +import { err, l } from "$lib/logging"; import { handleZap, serverPubkey } from "$lib/nostr"; import { sendInternal, sendKeysend, sendLightning } from "$lib/payments"; import { getInvoice, sleep } from "$lib/utils"; @@ -228,6 +228,7 @@ const handle = (method, params, ev, app, user) => async make_invoice() { const { amount, description, description_hash, expiry } = params; + l("nwc make_invoice", user.username); const invoice = { amount: Math.round(amount / 1000), diff --git a/lib/register.ts b/lib/register.ts index 6bd9df9f..e1a39d15 100644 --- a/lib/register.ts +++ b/lib/register.ts @@ -63,7 +63,6 @@ export default async (user, ip) => { } user.npub = nip19.npubEncode(pubkey); - user.nwc = bytesToHex(randomBytes(32)); const account = JSON.stringify({ id, @@ -71,6 +70,18 @@ export default async (user, ip) => { name: "Spending", }); + const secret = bytesToHex(randomBytes(32)); + const app = { + secret, + pubkey: getPublicKey(secret), + max_amount: 10000, + budget_renewal: "weekly", + name: username, + }; + + await s(app.pubkey, app); + await db.sAdd(`${uid}:apps`, app.pubkey); + db.multi() .set(getPublicKey(user.nwc), user.id) .set(`user:${id}`, JSON.stringify(user)) |
