// Helper function to convert bech32 to hex export function bech32ToHex(bech32Key: string): string { if (bech32Key.startsWith('npub1') || bech32Key.startsWith('nsec1')) { // Import bech32 conversion dynamically to avoid bundling issues const { bech32Decode, convertbits } = require('bech32') const [, data] = bech32Decode(bech32Key) if (!data) { throw new Error(`Invalid bech32 key: ${bech32Key}`) } const converted = convertbits(data, 5, 8, false) if (!converted) { throw new Error(`Failed to convert bech32 key: ${bech32Key}`) } return Buffer.from(converted).toString('hex') } // Already hex format return bech32Key }