diff --git a/directory.ts b/directory.ts index c133f6c..8d5ded4 100644 --- a/directory.ts +++ b/directory.ts @@ -2,7 +2,7 @@ import config from "./config.ts"; import { lookupUsernameByPubkey as ldapLookupUsername } from "./ldap.ts"; import { lookupPubkeyByUsername as ldapLookupPubkey } from "./ldap.ts"; -export function lookupUsernameByPubkey(pubkey: string) { +export async function lookupUsernameByPubkey(pubkey: string): Promise { let username; for (const [key, value] of Object.entries(config.staticUsers)) { if (value === pubkey) { @@ -20,7 +20,7 @@ export function lookupUsernameByPubkey(pubkey: string) { } } -export function lookupPubkeyByUsername(username: string) { +export async function lookupPubkeyByUsername(username: string): Promise { const pubkey = config.staticUsers[username]; if (pubkey) { diff --git a/ldap.ts b/ldap.ts index ec3d973..ef17d13 100644 --- a/ldap.ts +++ b/ldap.ts @@ -8,8 +8,8 @@ if (ldapEnabled) { client = new Client({ url: ldap.url as string }); } -export async function lookupPubkeyByUsername(username: string) { - let pubkey; +export async function lookupPubkeyByUsername(username: string): Promise { + let pubkey: string | undefined; try { await client.bind(ldap.bindDN as string, ldap.password as string); @@ -23,7 +23,7 @@ export async function lookupPubkeyByUsername(username: string) { searchEntries.length > 0 && typeof searchEntries[0].nostrKey === "string" ) { - pubkey = searchEntries[0].nostrKey; + pubkey = searchEntries[0].nostrKey.toString(); } await client.unbind(); @@ -35,8 +35,8 @@ export async function lookupPubkeyByUsername(username: string) { return pubkey; } -export async function lookupUsernameByPubkey(pubkey: string) { - let username; +export async function lookupUsernameByPubkey(pubkey: string): Promise { + let username: string | undefined; try { await client.bind(ldap.bindDN as string, ldap.password as string); @@ -47,7 +47,7 @@ export async function lookupUsernameByPubkey(pubkey: string) { }); if (searchEntries.length > 0) { - username = searchEntries[0].cn; + username = searchEntries[0].cn.toString(); } } catch (e) { await client.unbind();