import { getPublicKey, nip19 } from 'nostr-tools' const HEX64 = /^[0-9a-f]{64}$/ function toBytes(secretHex: string): Uint8Array { return Uint8Array.from(Buffer.from(secretHex.trim().toLowerCase(), 'hex')) } export function isValidSecretHex(hex: string): boolean { return HEX64.test(hex.trim().toLowerCase()) } // Deterministic secp256k1 x-only public key derivation (no randomness). Throws // if the secret is not a valid curve scalar. export function secretHexToPublicHex(secretHex: string): string { return getPublicKey(toBytes(secretHex)) } export function encodeNpub(publicHex: string): string { return nip19.npubEncode(publicHex) } export function encodeNsec(secretHex: string): string { return nip19.nsecEncode(toBytes(secretHex)) }