import { execSync } from 'node:child_process';
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
export class SshKeygenAdapter {
    async generateKeyPair(comment) {
        const tempDir = mkdtempSync(join(tmpdir(), 'deploy-key-'));
        const keyPath = join(tempDir, 'id_ed25519');
        try {
            execSync(`ssh-keygen -t ed25519 -C "${comment}" -f "${keyPath}" -N ""`, {
                stdio: 'pipe',
            });
            return {
                privateKey: readFileSync(keyPath, 'utf8'),
                publicKey: readFileSync(`${keyPath}.pub`, 'utf8'),
            };
        }
        finally {
            rmSync(tempDir, { force: true, recursive: true });
        }
    }
}
