diff --git a/config.ts b/config.ts new file mode 100644 index 0000000..62d0d50 --- /dev/null +++ b/config.ts @@ -0,0 +1,16 @@ +import { load } from "@std/dotenv"; + +const dirname = new URL(".", import.meta.url).pathname; +await load({ envPath: `${dirname}/.env`, export: true }); + +const config = { + home_relay_url: Deno.env.get("HOME_RELAY_URL"), + ldap: { + url: Deno.env.get("LDAP_URL"), + bindDN: Deno.env.get("LDAP_BIND_DN"), + password: Deno.env.get("LDAP_PASSWORD"), + searchDN: Deno.env.get("LDAP_SEARCH_DN"), + } +}; + +export default config; diff --git a/ldap.ts b/ldap.ts index a9db92e..8f59bd9 100644 --- a/ldap.ts +++ b/ldap.ts @@ -1,26 +1,17 @@ -import { load } from "@std/dotenv"; import { Client } from "ldapts"; import { log } from "./log.ts"; +import config from "./config.ts"; -const dirname = new URL(".", import.meta.url).pathname; -await load({ envPath: `${dirname}/.env`, export: true }); - -const config = { - url: Deno.env.get("LDAP_URL"), - bindDN: Deno.env.get("LDAP_BIND_DN"), - password: Deno.env.get("LDAP_PASSWORD"), - searchDN: Deno.env.get("LDAP_SEARCH_DN"), -}; - -const client = new Client({ url: config.url }); +const { ldap } = config; +const client = new Client({ url: ldap.url }); export async function lookupPubkeyByUsername(username: string) { let pubkey; try { - await client.bind(config.bindDN, config.password); + await client.bind(ldap.bindDN, ldap.password); - const { searchEntries } = await client.search(config.searchDN, { + const { searchEntries } = await client.search(ldap.searchDN, { filter: `(cn=${username})`, attributes: ["nostrKey"], }); @@ -39,9 +30,9 @@ export async function lookupUsernameByPubkey(pubkey: string) { let username; try { - await client.bind(config.bindDN, config.password); + await client.bind(ldap.bindDN, ldap.password); - const { searchEntries } = await client.search(config.searchDN, { + const { searchEntries } = await client.search(ldap.searchDN, { filter: `(nostrKey=${pubkey})`, attributes: ["cn"], }); diff --git a/nostr.ts b/nostr.ts index 76ae045..fe60f12 100644 --- a/nostr.ts +++ b/nostr.ts @@ -1,4 +1,5 @@ import { NRelay1 } from "@nostrify/nostrify"; +import config from "./config.ts"; export interface NEvent { content: string; @@ -10,7 +11,7 @@ export interface NEvent { tags: Array<[string, string, string?]>; } -export const relay = new NRelay1("wss://nostr.kosmos.org"); +export const relay = new NRelay1(config.home_relay_url); export async function fetchReplaceableEvent( pubkey: string,