add feistel encryption

This commit is contained in:
2026-04-11 04:36:14 +04:00
parent 4bb8e394ef
commit b2cc83538b
6 changed files with 62 additions and 8 deletions
+3 -2
View File
@@ -1,5 +1,6 @@
import sql from "./db";
import { COINS } from "../../shared/plans";
import { encodeId } from "../../shared/feistel";
export async function generateReceipt(paymentId: number): Promise<string> {
const [payment] = await sql`SELECT * FROM payments WHERE id = ${paymentId}`;
@@ -40,7 +41,7 @@ export async function generateReceipt(paymentId: number): Promise<string> {
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PingQL Receipt #${payment.id}</title>
<title>PingQL Receipt #${encodeId(payment.id)}</title>
<link rel="icon" href="https://pingql.com/favicon.svg" type="image/svg+xml">
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
@@ -71,7 +72,7 @@ export async function generateReceipt(paymentId: number): Promise<string> {
<div class="header">
<div class="logo">Ping<span>QL</span></div>
<div class="meta">Receipt #${payment.id} · Issued ${paidDate}</div>
<div class="meta">Receipt #${encodeId(payment.id)} · Issued ${paidDate}</div>
</div>
<div class="section">
+7 -4
View File
@@ -6,6 +6,7 @@ import { PLAN_PRICING as PLANS, COINS, planTier } from "../../shared/plans";
import { generateReceipt } from "./receipt";
import { watchPayment } from "./monitor";
import { resolveKey as sharedResolveKey, extractAuthKey } from "../../shared/auth";
import { encodeId, decodeId } from "../../shared/feistel";
function requireAuth(app: Elysia) {
return app
@@ -100,7 +101,7 @@ export const routes = new Elysia()
const uri = `${coinInfo.uri}:${address.replace(/^.*:/, '')}?amount=${amountCrypto}`;
return {
id: payment.id,
id: encodeId(payment.id),
plan: payment.plan,
months: payment.months,
amount_usd: Number(payment.amount_usd),
@@ -126,8 +127,9 @@ export const routes = new Elysia()
})
.get("/checkout/:id", async ({ accountId, params, set }) => {
const dbId = decodeId(params.id);
const [payment] = await sql`
SELECT * FROM payments WHERE id = ${params.id} AND account_id = ${accountId}
SELECT * FROM payments WHERE id = ${dbId} AND account_id = ${accountId}
`;
if (!payment) { set.status = 404; return { error: "Payment not found" }; }
@@ -148,7 +150,7 @@ export const routes = new Elysia()
`;
return {
id: payment.id,
id: encodeId(payment.id),
plan: payment.plan,
months: payment.months,
amount_usd: Number(payment.amount_usd),
@@ -170,8 +172,9 @@ export const routes = new Elysia()
})
.get("/checkout/:id/receipt", async ({ accountId, params, set }) => {
const dbId = decodeId(params.id);
const [payment] = await sql`
SELECT * FROM payments WHERE id = ${params.id} AND account_id = ${accountId}
SELECT * FROM payments WHERE id = ${dbId} AND account_id = ${accountId}
`;
if (!payment) { set.status = 404; return { error: "Payment not found" }; }
if (payment.status !== "paid") { set.status = 400; return { error: "Receipt is only available for paid invoices" }; }