import { PoolErrorException, PoolErrorType } from '../error/pool.error'; import { Address, NETWORK, OutScript } from '@scure/btc-signer'; import { hex } from '@scure/base'; export const getScriptPubkeyFromAddress = ( address: string, network: typeof NETWORK, ): string => { try { const decoded = Address(network).decode(address); if (decoded.type === 'unknown') { throw new Error('Unknown address type'); } // Convert the decoded address information back into a script pubkey. const script = OutScript.encode(decoded); return hex.encode(script); } catch { throw new PoolErrorException({ message: `Invalid address provided: ${address}`, type: PoolErrorType.InvalidAddress, }); } };