aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
Diffstat (limited to 'routes')
-rw-r--r--routes/ecash.ts2
-rw-r--r--routes/email.ts4
-rw-r--r--routes/info.ts5
-rw-r--r--routes/invoices.ts2
-rw-r--r--routes/lnurl.ts2
-rw-r--r--routes/nostr.ts15
-rw-r--r--routes/payments.ts18
-rw-r--r--routes/square.ts8
-rw-r--r--routes/users.ts42
9 files changed, 45 insertions, 53 deletions
diff --git a/routes/ecash.ts b/routes/ecash.ts
index fc6a8d3a..632ebd49 100644
--- a/routes/ecash.ts
+++ b/routes/ecash.ts
@@ -103,7 +103,7 @@ export default {
const rates = await g("rates");
const rate = rates[currency];
- if (ourfee.err) fail(ourfee.err);
+ if ((ourfee as any).err) fail((ourfee as any).err);
const id = v4();
const p = {
diff --git a/routes/email.ts b/routes/email.ts
index ff6ffaeb..f6abf991 100644
--- a/routes/email.ts
+++ b/routes/email.ts
@@ -1,7 +1,7 @@
import { bail } from "$lib/utils";
import got from "got";
import config from "$config";
-import { l, warn } from "$lib/logging";
+import { warn } from "$lib/logging";
import { SESClient } from "@aws-sdk/client-ses";
import { SendEmailCommand } from "@aws-sdk/client-ses";
@@ -21,7 +21,7 @@ export default {
response,
},
})
- .json();
+ .json() as any;
if (success || response === config.adminpass) {
body.token = undefined;
diff --git a/routes/info.ts b/routes/info.ts
index adad02c6..f2bcda1a 100644
--- a/routes/info.ts
+++ b/routes/info.ts
@@ -1,5 +1,4 @@
-import { archive } from "$lib/db";
-import { db, g } from "$lib/db";
+import { g } from "$lib/db";
import { getHealthStatus } from "$lib/health";
import ln from "$lib/ln";
import { getDecodedToken } from "@cashu/cashu-ts";
@@ -12,8 +11,6 @@ export default {
},
async balances(c) {
- let total = 0;
-
const funds = await ln.listfunds();
const lnchannel = parseInt(funds.channels.reduce((a, b) => a + b.channel_sat, 0));
const lnwallet = parseInt(funds.outputs.reduce((a, b) => a + b.value, 0));
diff --git a/routes/invoices.ts b/routes/invoices.ts
index 6fc0b67a..b22b8bfe 100644
--- a/routes/invoices.ts
+++ b/routes/invoices.ts
@@ -50,7 +50,7 @@ export default {
try {
const id = c.req.param("id");
const body = await c.req.json();
- const { tip, webhook, secret, received } = body.invoice;
+ const { tip, webhook, secret, received: _received } = body.invoice;
if (tip < 0) fail("Invalid tip");
diff --git a/routes/lnurl.ts b/routes/lnurl.ts
index 9cd6e8d5..99c9adee 100644
--- a/routes/lnurl.ts
+++ b/routes/lnurl.ts
@@ -20,7 +20,7 @@ export default {
const url = `https://${domain}/.well-known/lnurlp/${name.toLowerCase().replace(/\s/g, "")}`;
try {
- const r = await got(url).json();
+ const r = await got(url).json() as any;
if (r.tag !== "payRequest") fail("not an ln address");
} catch (e) {
const m = `failed to lookup lightning address ${address}`;
diff --git a/routes/nostr.ts b/routes/nostr.ts
index 554a230c..de6dac13 100644
--- a/routes/nostr.ts
+++ b/routes/nostr.ts
@@ -1,5 +1,5 @@
import config from "$config";
-import { db, g, s } from "$lib/db";
+import { db, g } from "$lib/db";
import ln from "$lib/ln";
import {
EX,
@@ -18,7 +18,7 @@ import { bail, fail, fields, getUser } from "$lib/utils";
import got from "got";
import type { Event } from "nostr-tools";
import { decode } from "nostr-tools/nip19";
-import type { ProfilePointer } from "nostr-tools/nip19";
+
import { getZapEndpoint, makeZapRequest } from "nostr-tools/nip57";
export default {
@@ -163,7 +163,8 @@ export default {
const filter = { kinds: [9735], "#e": [id] };
let events = await scan(filter);
if (!events.length) {
- await sync("wss://relay.primal.net", filter);
+ // @ts-ignore
+ await (sync as any)("wss://relay.primal.net", filter);
events = await scan(filter);
}
if (!events.length) return c.json([]);
@@ -331,7 +332,7 @@ export default {
} else {
const records = await db.sMembers("nip5");
for (const s of records) {
- const [name, pubkey] = s.split(":");
+ const [name, pubkey] = (s as string).split(":");
names[name] = pubkey;
}
}
@@ -346,8 +347,8 @@ export default {
async profile(c) {
const profile = c.req.param("profile");
const { data } = decode(profile);
- const { pubkey, relays } = data as ProfilePointer;
- const recipient = await getProfile(pubkey, relays);
+ const { pubkey, relays } = data as any;
+ const recipient = await (getProfile as any)(pubkey, relays);
recipient.relays = relays;
return c.json(recipient);
},
@@ -357,7 +358,7 @@ export default {
const body = await c.req.json();
const { amount, id } = body;
const { pubkey } = await get({ ids: [id] });
- const event = await makeZapRequest({
+ const event = await (makeZapRequest as any)({
profile: pubkey,
event: id,
amount: amount * 1000,
diff --git a/routes/payments.ts b/routes/payments.ts
index ab7a6711..0689f57d 100644
--- a/routes/payments.ts
+++ b/routes/payments.ts
@@ -327,7 +327,7 @@ export default {
const body = await c.req.json();
const { id, fiat, currency, amount } = body;
- const managers = await db.sMembers(`fund:${id}:managers`);
+ const managers = [...await db.sMembers(`fund:${id}:managers`)];
if (managers.length && !managers.includes(uid)) fail("Unauthorized");
const authorization = {
@@ -386,7 +386,7 @@ export default {
l("funded fund", id);
}
- const managers = await db.sMembers(`fund:${id}:managers`);
+ const managers = [...await db.sMembers(`fund:${id}:managers`)];
if (managers.length && !managers.includes(user.id)) fail("Unauthorized");
const result: any = await tbFundDebit(id, amount, "Insufficient funds");
@@ -413,7 +413,7 @@ export default {
async managers(c) {
const name = c.req.param("name");
- const ids = await db.sMembers(`fund:${name}:managers`);
+ const ids = [...await db.sMembers(`fund:${name}:managers`)];
const managers = (await Promise.all(ids.map(async (id) => await getUser(id, fields)))).filter(
Boolean,
@@ -429,7 +429,7 @@ export default {
const k = `fund:${id}:managers`;
- let managers = await db.sMembers(k);
+ let managers: any[] = [...await db.sMembers(k)];
if (managers.length) {
if (!managers.includes(user.id)) fail("Unauthorized");
} else {
@@ -442,7 +442,7 @@ export default {
await db.sAdd(k, uid);
- const ids = await db.sMembers(k);
+ const ids = [...await db.sMembers(k)];
if (!managers.length)
managers = await Promise.all(ids.map(async (id) => await getUser(id, fields)));
@@ -457,7 +457,7 @@ export default {
const user = c.get("user");
const k = `fund:${name}:managers`;
- let managers = await db.sMembers(k);
+ let managers: any[] = [...await db.sMembers(k)];
if (managers.length) {
if (!managers.includes(user.id)) fail("Unauthorized");
@@ -465,7 +465,7 @@ export default {
await db.sRem(k, uid);
- const ids = await db.sMembers(k);
+ const ids = [...await db.sMembers(k)];
managers = await Promise.all(ids.map(async (id) => await getUser(id, fields)));
return c.json(managers);
@@ -491,7 +491,7 @@ export default {
const p = await getPayment(`${txid}:${vout}`);
if (!p) {
- const invoice = await getInvoice(address);
+ await getInvoice(address);
if (sats(amount) < 300) continue;
const lockKey = `lock:${txid}:${vout}`;
@@ -1040,7 +1040,7 @@ export default {
currency,
created: Date.now(),
extraHashMappings: [],
- });
+ }) as any;
p.memo = "expired";
await s(`payment:${p.id}`, p);
payments.push(p);
diff --git a/routes/square.ts b/routes/square.ts
index 269cdd0d..dc89fd7d 100644
--- a/routes/square.ts
+++ b/routes/square.ts
@@ -7,9 +7,7 @@ import { sha256 } from "@noble/hashes/sha2.js";
import { utf8ToBytes } from "@noble/hashes/utils.js";
import { base64urlnopad as base64 } from "@scure/base";
import { SquareClient } from "square";
-import { v4 } from "uuid";
-
-const { scopes, url, appId, clientSecret, environment } = config.square;
+const { scopes, url, appId, clientSecret: _clientSecret, environment } = config.square;
export default {
async connect(c) {
@@ -19,12 +17,12 @@ export default {
return c.json("connected");
}
- const codeVerifier = base64.encode(crypto.randomBytes(32));
+ const codeVerifier = base64.encode(crypto.randomBytes(32) as any);
await s(`${user.id}:codeVerifier`, codeVerifier);
const challenge = base64.encode(sha256(utf8ToBytes(codeVerifier)));
- const state = base64.encode(crypto.randomBytes(12));
+ const state = base64.encode(crypto.randomBytes(12) as any);
const scope = scopes.join("+");
return c.json(
diff --git a/routes/users.ts b/routes/users.ts
index f3b747af..1d0f9bcb 100644
--- a/routes/users.ts
+++ b/routes/users.ts
@@ -1,5 +1,4 @@
-import { createReadStream } from "node:fs";
-import { unlink, writeFile } from "node:fs/promises";
+import { writeFile } from "node:fs/promises";
import config from "$config";
import { requirePin } from "$lib/auth";
import { db, g, ga, gf, s, scan } from "$lib/db";
@@ -18,8 +17,6 @@ import upload from "$lib/upload";
import { bail, fail, fields, getUser, pick } from "$lib/utils";
import whitelist from "$lib/whitelist";
import rpc from "@coinos/rpc";
-import { bech32m } from "@scure/base";
-
import { $ } from "bun";
import got from "got";
import jwt from "jsonwebtoken";
@@ -49,7 +46,7 @@ const verifyRecaptcha = async (response, c?, body?) => {
if (typeof ua === "string") {
const prefixes = await db.sMembers("nocaptcha_ua");
const uaLower = ua.toLowerCase();
- if (prefixes.some((p) => uaLower.startsWith(p.toLowerCase()))) {
+ if ([...prefixes].some((p) => uaLower.startsWith(p.toString().toLowerCase()))) {
return true;
}
}
@@ -67,7 +64,7 @@ const verifyRecaptcha = async (response, c?, body?) => {
try {
const ip = c?.req?.header("cf-connecting-ip") || c?.env?.ip;
- const { success } = await got
+ const { success } = (await got
.post("https://www.google.com/recaptcha/api/siteverify", {
form: {
secret,
@@ -75,7 +72,7 @@ const verifyRecaptcha = async (response, c?, body?) => {
remoteip: ip,
},
})
- .json();
+ .json()) as any;
return success || response === config.adminpass;
} catch {
return false;
@@ -153,7 +150,7 @@ export default {
if (key.startsWith("nprofile")) {
try {
- ({ pubkey: key } = nip19.decode(key).data as ProfilePointer);
+ ({ pubkey: key } = nip19.decode(key).data as unknown as ProfilePointer);
} catch (e) {}
}
@@ -374,7 +371,7 @@ export default {
const ipKey = `ip:${ip}:login`;
const ipCount = await db.incr(ipKey);
if (ipCount === 1) await db.expire(ipKey, 10);
- if (ipCount > 30) return c.json({}, 429);
+ if (Number(ipCount) > 30) return c.json({}, 429);
const recaptchaOk = await verifyRecaptcha(recaptcha, c, body);
if (!recaptchaOk) {
@@ -385,10 +382,9 @@ export default {
username = username.split("@")[0];
const fk = `${username}:failures`;
- const failures = await g(fk);
const ipFailKey = `ip:${ip}:login:fail`;
const ipFailures = await g(ipFailKey);
- if (ipFailures > 20) return c.json({}, 429);
+ if (Number(ipFailures) > 20) return c.json({}, 429);
let user = await getUser(username);
@@ -451,7 +447,7 @@ export default {
const ipKey = `ip:${ip}:login`;
const ipCount = await db.incr(ipKey);
if (ipCount === 1) await db.expire(ipKey, 10);
- if (ipCount > 30) return c.json({}, 429);
+ if (Number(ipCount) > 30) return c.json({}, 429);
const recaptchaOk = await verifyRecaptcha(recaptcha, c, body);
if (!recaptchaOk) return c.json("failed captcha", 401);
@@ -495,7 +491,7 @@ export default {
async nostrAuth(c) {
try {
const body = await c.req.json();
- const { event, challenge, twofa, recaptcha } = body;
+ const { event, challenge, twofa: _twofa, recaptcha } = body;
const ip = c.req.header("cf-connecting-ip");
const recaptchaOk = await verifyRecaptcha(recaptcha, c, body);
if (!recaptchaOk) {
@@ -620,12 +616,12 @@ export default {
const limit = c.req.param("limit");
const lastlen = (await g(`${id}:lastlen`)) || 0;
const len = await db.lLen(`${id}:payments`);
- const payments = (await db.lRange(`${id}:payments`, 0, len - lastlen)) || [];
+ const payments = (await db.lRange(`${id}:payments`, 0, Number(len) - Number(lastlen))) || [];
await db.set(`${id}:lastlen`, len);
let contacts = (await g(`${id}:contacts`)) || [];
- const pins = await db.sMembers(`${id}:pins`);
- const trust = await db.sMembers(`${id}:trust`);
+ const pins = [...await db.sMembers(`${id}:pins`)];
+ const trust = [...await db.sMembers(`${id}:trust`)];
for (const { ref } of (
await Promise.all(payments.reverse().map(async (id) => await gf(`payment:${id}`)))
@@ -678,8 +674,8 @@ export default {
const invoices = await db.lRange(`${id}:invoices`, 0, -1);
const payments = await db.lRange(`${id}:payments`, 0, -1);
- for (const { id } of invoices) db.del(`invoice:${id}`);
- for (const { id } of payments) db.del(`payment:${id}`);
+ for (const inv of invoices) db.del(`invoice:${(inv as any).id}`);
+ for (const pay of payments) db.del(`payment:${(pay as any).id}`);
db.del(`user:${username.toLowerCase()}`);
db.del(`user:${id}`);
db.del(`user:${pubkey}`);
@@ -692,7 +688,6 @@ export default {
const { code, username, password } = body;
const u = c.get("user");
try {
- const admin = u?.admin;
let id;
let user;
@@ -856,13 +851,14 @@ export default {
const accounts = [];
for (const id of await db.lRange(`${user.id}:accounts`, 0, -1)) {
- const account = await g(`account:${id}`);
+ const aid = id as string;
+ const account = await g(`account:${aid}`);
if (account) {
if ((account.seed || user.seed) && account.pubkey && !account.importedAt) {
await importAccountHistory(account);
}
- account.balance = await getBalance(id);
- account.pending = await getPending(id);
+ account.balance = await getBalance(aid);
+ account.pending = await getPending(aid);
accounts.push(account);
}
@@ -1079,7 +1075,7 @@ export default {
async apps(c) {
const user = c.get("user");
- const pubkeys = await db.sMembers(`${user.id}:apps`);
+ const pubkeys = [...await db.sMembers(`${user.id}:apps`)];
const apps = await Promise.all(pubkeys.map((p) => g(`app:${p}`)));
const lud16 = `${user.username}@${host}`;