import * as plugins from './plugins.js'; import { StorageManager } from './storage/index.js'; /** * ICertManager implementation backed by StorageManager. * Persists SmartAcme certificates under a /certs/ key prefix so they * survive process restarts without re-hitting ACME. */ export class StorageBackedCertManager implements plugins.smartacme.ICertManager { private keyPrefix = '/certs/'; constructor(private storageManager: StorageManager) {} async init(): Promise {} async retrieveCertificate(domainName: string): Promise { const data = await this.storageManager.getJSON(this.keyPrefix + domainName); if (!data) return null; return new plugins.smartacme.Cert(data); } async storeCertificate(cert: plugins.smartacme.Cert): Promise { await this.storageManager.setJSON(this.keyPrefix + cert.domainName, { id: cert.id, domainName: cert.domainName, created: cert.created, privateKey: cert.privateKey, publicKey: cert.publicKey, csr: cert.csr, validUntil: cert.validUntil, }); } async deleteCertificate(domainName: string): Promise { await this.storageManager.delete(this.keyPrefix + domainName); } async close(): Promise {} async wipe(): Promise { const keys = await this.storageManager.list(this.keyPrefix); for (const key of keys) { await this.storageManager.delete(key); } } }