aboutsummaryrefslogtreecommitdiffstats
path: root/lib/v3forward.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/v3forward.ts')
-rw-r--r--lib/v3forward.ts9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/v3forward.ts b/lib/v3forward.ts
index 9a263acd..525c1be1 100644
--- a/lib/v3forward.ts
+++ b/lib/v3forward.ts
@@ -19,6 +19,7 @@ import { PaymentType } from "$lib/types";
// account's own session named in a migration grant (`granted`). A name that
// merely exists on v3 is never forwarded to.
+import { holderBlocked } from "$lib/names";
const NAMES_URL = process.env.NAMES_URL || "https://names.coinos.io";
const DOMAIN = "coinos.io";
const TYPES = [PaymentType.lightning, PaymentType.bolt12, PaymentType.bitcoin, PaymentType.liquid];
@@ -34,6 +35,13 @@ async function v3Holder(username: string): Promise<{ pk: string | null; granted:
if (hit && Date.now() - hit.at < (hit.pk ? 60_000 : 600_000)) return hit;
const r = await fetch(`${NAMES_URL}/name/${encodeURIComponent(name)}?domain=${DOMAIN}`,
{ signal: AbortSignal.timeout(2000) });
+ // 404 is the registrar's answer for a name that can't exist on v3 (a legacy
+ // username with spaces, say), so nobody holds it
+ if (r.status === 404) {
+ const none = { at: Date.now(), pk: null, granted: false };
+ holderCache.set(name, none);
+ return none;
+ }
if (!r.ok) throw new Error(`registrar said ${r.status}`);
const body: any = await r.json();
const pk = body?.taken && typeof body.pubkey === "string" ? body.pubkey : null;
@@ -46,6 +54,7 @@ async function v3Holder(username: string): Promise<{ pk: string | null; granted:
export async function v3Destination(user): Promise<string | null> {
if (!user?.username || !user?.pubkey || user.username.length > 64) return null;
const { pk, granted } = await v3Holder(user.username);
+ if (pk && (await holderBlocked(user.username))) return null;
return pk && (granted || pk === user.pubkey) ? user.username.toLowerCase() : null;
}