"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DcapQuoteVerifyService = void 0;
const { SgxAttestationVerifier } = require("../../bindings/sgx-native/build/Release/sgx_native.node");
const consts_1 = require("./consts");
const errors_1 = require("./errors");
class DcapQuoteVerifyService {
    constructor() {
        this.quoteVerifier = new SgxAttestationVerifier();
    }
    async extractQuoteFromCert(pemOrDerCert) {
        if (!pemOrDerCert?.length) {
            throw new errors_1.AttestationDcapQuoteVerifyEnclaveError("empty certificate");
        }
        return this.quoteVerifier.extractQuoteFromCert(pemOrDerCert);
    }
    async validateQuoteVerifierEnclave(quote, checkSecurity) {
        checkSecurity = checkSecurity ?? false;
        if (!quote?.length) {
            throw new errors_1.AttestationDcapQuoteVerifyEnclaveError("empty quote");
        }
        const verifyResult = this.quoteVerifier.verifyQuoteDcap(quote);
        if (checkSecurity && verifyResult.smtEnabled === consts_1.PckFlag.PCK_FLAG_TRUE) {
            throw new errors_1.QuoteSecurityValidationError(verifyResult);
        }
        if (verifyResult.verificationResult !== 0) {
            throw new errors_1.QuoteValidationError(verifyResult.verificationResult);
        }
    }
    async generateTDXQuote(userData) {
        return this.quoteVerifier.generateTDXQuote(userData);
    }
}
exports.DcapQuoteVerifyService = DcapQuoteVerifyService;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGNhcC1xdW90ZS12ZXJpZnkuc2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zZ3gtbmF0aXZlLW1vZHVsZS9kY2FwLXF1b3RlLXZlcmlmeS5zZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLE1BQU0sRUFBRSxzQkFBc0IsRUFBRSxHQUFHLE9BQU8sQ0FBQyx5REFBeUQsQ0FBQyxDQUFDO0FBQ3RHLHFDQUFnRTtBQUNoRSxxQ0FBc0g7QUFRdEgsTUFBYSxzQkFBc0I7SUFHL0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