mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
lookupPubkey: check the bech32 first
This commit is contained in:
parent
2010483089
commit
2140b3fbb2
2 changed files with 10 additions and 4 deletions
BIN
..env.swp
Normal file
BIN
..env.swp
Normal file
Binary file not shown.
|
|
@ -1,8 +1,9 @@
|
||||||
import { NIP05, NostrEvent } from '@nostrify/nostrify';
|
import { NIP05, NostrEvent, NSchema as n } from '@nostrify/nostrify';
|
||||||
|
|
||||||
import { getAuthor } from '@/queries.ts';
|
import { getAuthor } from '@/queries.ts';
|
||||||
import { bech32ToPubkey } from '@/utils.ts';
|
import { bech32ToPubkey } from '@/utils.ts';
|
||||||
import { nip05Cache } from '@/utils/nip05.ts';
|
import { nip05Cache } from '@/utils/nip05.ts';
|
||||||
|
import { Stickynotes } from '@soapbox/stickynotes';
|
||||||
|
|
||||||
/** Resolve a bech32 or NIP-05 identifier to an account. */
|
/** Resolve a bech32 or NIP-05 identifier to an account. */
|
||||||
export async function lookupAccount(
|
export async function lookupAccount(
|
||||||
|
|
@ -18,14 +19,19 @@ export async function lookupAccount(
|
||||||
|
|
||||||
/** Resolve a bech32 or NIP-05 identifier to a pubkey. */
|
/** Resolve a bech32 or NIP-05 identifier to a pubkey. */
|
||||||
export async function lookupPubkey(value: string, signal?: AbortSignal): Promise<string | undefined> {
|
export async function lookupPubkey(value: string, signal?: AbortSignal): Promise<string | undefined> {
|
||||||
|
const console = new Stickynotes('ditto:lookup');
|
||||||
|
|
||||||
|
if (n.bech32().safeParse(value).success) {
|
||||||
|
return bech32ToPubkey(value);
|
||||||
|
}
|
||||||
|
|
||||||
if (NIP05.regex().test(value)) {
|
if (NIP05.regex().test(value)) {
|
||||||
try {
|
try {
|
||||||
const { pubkey } = await nip05Cache.fetch(value, { signal });
|
const { pubkey } = await nip05Cache.fetch(value, { signal });
|
||||||
return pubkey;
|
return pubkey;
|
||||||
} catch {
|
} catch (e) {
|
||||||
|
console.debug(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return bech32ToPubkey(value);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue