mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-15 23:26:46 +00:00
31 lines
835 B
TypeScript
31 lines
835 B
TypeScript
import { TldParser } from "@onsol/tldparser";
|
|
import { SolanaAgentKit } from "../index";
|
|
import { PublicKey } from "@solana/web3.js";
|
|
|
|
/**
|
|
* Resolve all domains for a given agent and domain
|
|
* @param agent SolanaAgentKit instance
|
|
* @param domain Domain name to resolve
|
|
* @returns Promise resolving to the domain or undefined if not found
|
|
*/
|
|
export async function resolveAllDomains(
|
|
agent: SolanaAgentKit,
|
|
domain: string,
|
|
): Promise<PublicKey | undefined> {
|
|
try {
|
|
const tld = await new TldParser(agent.connection).getOwnerFromDomainTld(
|
|
domain,
|
|
);
|
|
return tld;
|
|
} catch (error: any) {
|
|
if (
|
|
error.message.includes(
|
|
"Cannot read properties of undefined (reading 'owner')",
|
|
)
|
|
) {
|
|
return undefined;
|
|
}
|
|
throw new Error(`Domain resolution failed: ${error.message}`);
|
|
}
|
|
}
|