aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bip353.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-03-03 21:40:58 -0800
committerAdam Soltys <[email protected]>2026-03-03 21:40:58 -0800
commit55ae58daf23028fa0f647f7bb2b4b0f8cd751de7 (patch)
tree49f4031b81352bea5c963d4201250f24ee8bd2dd /lib/bip353.ts
parent9507e040a03834f7d603c5c13a1f69ae6ef48b3a (diff)
downloadcoinos-server-55ae58daf23028fa0f647f7bb2b4b0f8cd751de7.tar.gz
coinos-server-55ae58daf23028fa0f647f7bb2b4b0f8cd751de7.zip
sync vault
Diffstat (limited to 'lib/bip353.ts')
-rw-r--r--lib/bip353.ts36
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/bip353.ts b/lib/bip353.ts
index 4e37c46e..8b00635b 100644
--- a/lib/bip353.ts
+++ b/lib/bip353.ts
@@ -5,56 +5,58 @@ import { l, warn } from "$lib/logging";
import { v4 } from "uuid";
import { PaymentType } from "$lib/types";
-const { CF_EMAIL, CF_API_KEY, CF_ZONE_ID } = process.env;
const cfApi = "https://api.cloudflare.com/client/v4";
-const cfHeaders = {
- "X-Auth-Email": CF_EMAIL,
- "X-Auth-Key": CF_API_KEY,
+const cfHeaders = () => ({
+ Authorization: `Bearer ${config.cloudflare?.apiToken}`,
"Content-Type": "application/json",
-};
+});
const createDnsRecord = async (username: string, bolt12: string) => {
- if (!CF_API_KEY || !CF_ZONE_ID) return;
+ const { apiToken, zoneId } = config.cloudflare || {};
+ if (!apiToken || !zoneId) return;
const name = `${username}.user._bitcoin-payment.${config.hostname}`;
const content = `bitcoin:?lno=${bolt12}`;
+ const { zoneId } = config.cloudflare;
+
const listRes = await fetch(
- `${cfApi}/zones/${CF_ZONE_ID}/dns_records?type=TXT&name=${name}`,
- { headers: cfHeaders },
+ `${cfApi}/zones/${zoneId}/dns_records?type=TXT&name=${name}`,
+ { headers: cfHeaders() },
);
const listData = (await listRes.json()) as any;
if (listData.result?.length) {
const recordId = listData.result[0].id;
- await fetch(`${cfApi}/zones/${CF_ZONE_ID}/dns_records/${recordId}`, {
+ await fetch(`${cfApi}/zones/${zoneId}/dns_records/${recordId}`, {
method: "PUT",
- headers: cfHeaders,
+ headers: cfHeaders(),
body: JSON.stringify({ type: "TXT", name, content, ttl: 3600 }),
});
} else {
- await fetch(`${cfApi}/zones/${CF_ZONE_ID}/dns_records`, {
+ await fetch(`${cfApi}/zones/${zoneId}/dns_records`, {
method: "POST",
- headers: cfHeaders,
+ headers: cfHeaders(),
body: JSON.stringify({ type: "TXT", name, content, ttl: 3600 }),
});
}
};
const deleteDnsRecord = async (username: string) => {
- if (!CF_API_KEY || !CF_ZONE_ID) return;
+ const { apiToken, zoneId } = config.cloudflare || {};
+ if (!apiToken || !zoneId) return;
const name = `${username}.user._bitcoin-payment.${config.hostname}`;
const listRes = await fetch(
- `${cfApi}/zones/${CF_ZONE_ID}/dns_records?type=TXT&name=${name}`,
- { headers: cfHeaders },
+ `${cfApi}/zones/${zoneId}/dns_records?type=TXT&name=${name}`,
+ { headers: cfHeaders() },
);
const listData = (await listRes.json()) as any;
for (const record of listData.result || []) {
- await fetch(`${cfApi}/zones/${CF_ZONE_ID}/dns_records/${record.id}`, {
+ await fetch(`${cfApi}/zones/${zoneId}/dns_records/${record.id}`, {
method: "DELETE",
- headers: cfHeaders,
+ headers: cfHeaders(),
});
}
};