"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cSignAppDataRespVersion = void 0;
exports.serializeSignAppDataResp = serializeSignAppDataResp;
exports.deserializeSignAppDataResp = deserializeSignAppDataResp;
const Helpers_1 = require("./ajv/Helpers");
const AJVSchemaEnum_1 = require("./enum/AJVSchemaEnum");
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
exports.cSignAppDataRespVersion = 1;
function serializeSignAppDataResp(stream, obj, root = false) {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cSignAppDataResp);
    }
    stream.writeUInt8(exports.cSignAppDataRespVersion);
    stream.writeUInt8(obj.success ? 1 : 0);
    stream.writeString(obj.signature.owner);
    stream.writeString(obj.signature.sig);
}
function deserializeSignAppDataResp(stream) {
    const version = stream.readUInt8();
    if (version > exports.cSignAppDataRespVersion) {
        throw new Error(`SignAppDataResp version mismatch, version: ${version}`);
    }
    const result = {
        success: stream.readUInt8() === 1,
        signature: {
            owner: stream.readString(),
            sig: stream.readString(),
        },
    };
    const errors = (0, Helpers_1.verifyPayload)(AJVSchemaEnum_1.AJVSchemaEnum.SignAppDataResp, result);
    if (errors && errors.length > 0) {
        throw new Error('Data validation error');
    }
    return result;
}
//# sourceMappingURL=SignAppDataResp.js.map