import * as OTPAuth from 'otpauth';
import QRCode from 'qrcode';
export class TotpService {
    issuer;
    constructor(issuer = 'NTerminal') {
        this.issuer = issuer;
    }
    async generateSetup(accountName) {
        const totp = new OTPAuth.TOTP({
            issuer: this.issuer,
            label: accountName,
            algorithm: 'SHA1',
            digits: 6,
            period: 30,
            secret: new OTPAuth.Secret()
        });
        const uri = totp.toString();
        const qrDataUrl = await QRCode.toDataURL(uri, { width: 256, margin: 2 });
        return { secret: totp.secret.base32, qrDataUrl };
    }
    verify(secret, token) {
        try {
            const totp = new OTPAuth.TOTP({
                algorithm: 'SHA1',
                digits: 6,
                period: 30,
                secret: OTPAuth.Secret.fromBase32(secret)
            });
            const delta = totp.validate({ token, window: 1 });
            return delta !== null;
        }
        catch {
            return false;
        }
    }
}
//# sourceMappingURL=totpService.js.map