diff --git a/src/services/main/paymentManager.ts b/src/services/main/paymentManager.ts index 1e8de448..8d5b6cd8 100644 --- a/src/services/main/paymentManager.ts +++ b/src/services/main/paymentManager.ts @@ -234,10 +234,13 @@ export default class { if (!Number.isInteger(sats)) { throw new Error("millisats amount must be integer sats amount") } + if (!key.linkedApplication) { + throw new Error("cannot handle lnurl for non application user") + } const invoice = await this.NewInvoice(key.user.user_id, { amountSats: sats, memo: defaultLnurlPayMetadata - }) + }, { expiry: defaultInvoiceExpiry, linkedApplication: key.linkedApplication }) return { pr: invoice.invoice, routes: [] diff --git a/src/services/storage/entity/UserEphemeralKey.ts b/src/services/storage/entity/UserEphemeralKey.ts index f81ac131..52c9a706 100644 --- a/src/services/storage/entity/UserEphemeralKey.ts +++ b/src/services/storage/entity/UserEphemeralKey.ts @@ -1,5 +1,6 @@ import { Entity, PrimaryGeneratedColumn, Column, Index, Check, ManyToOne, JoinColumn, CreateDateColumn, UpdateDateColumn } from "typeorm" import { User } from "./User.js" +import { Application } from "./Application.js" export type EphemeralKeyType = 'balanceCheck' | 'payInfo' | 'pay' | 'withdraw' @Entity() export class UserEphemeralKey { @@ -11,6 +12,10 @@ export class UserEphemeralKey { @JoinColumn() user: User + @ManyToOne(type => Application, { eager: true }) + @JoinColumn() + linkedApplication: Application | null + @Column() @Index({ unique: true }) key: string diff --git a/src/services/storage/paymentStorage.ts b/src/services/storage/paymentStorage.ts index eebfa403..ee72d306 100644 --- a/src/services/storage/paymentStorage.ts +++ b/src/services/storage/paymentStorage.ts @@ -163,11 +163,12 @@ export default class { } - async AddUserEphemeralKey(userId: string, keyType: EphemeralKeyType, entityManager = this.DB): Promise { + async AddUserEphemeralKey(userId: string, keyType: EphemeralKeyType, linkedApplication?: Application, entityManager = this.DB): Promise { const newKey = entityManager.getRepository(UserEphemeralKey).create({ user: await this.userStorage.GetUser(userId, entityManager), key: crypto.randomBytes(31).toString('hex'), - type: keyType + type: keyType, + linkedApplication }) return entityManager.getRepository(UserEphemeralKey).save(newKey) }