"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createLegacySignaturePayload = void 0;
const utils_1 = require("@streamr/utils");
const StreamMessage_1 = require("../protocol/StreamMessage");
const serializeGroupKey = ({ id, data }) => {
    return JSON.stringify([id, (0, utils_1.binaryToHex)(data)]);
};
/**
 * Only to be used for LEGACY_SECP256K1 signature type.
 */
const createLegacySignaturePayload = (opts) => {
    const prev = ((opts.prevMsgRef !== undefined) ? `${opts.prevMsgRef.timestamp}${opts.prevMsgRef.sequenceNumber}` : '');
    const newGroupKey = ((opts.newGroupKey !== undefined) ? serializeGroupKey(opts.newGroupKey) : '');
    // In the legacy signature type, encrypted content was signed as a hex-encoded string
    const contentAsString = (opts.encryptionType === StreamMessage_1.EncryptionType.NONE)
        ? (0, utils_1.binaryToUtf8)(opts.content)
        : (0, utils_1.binaryToHex)(opts.content);
    return Buffer.from(`${opts.messageId.streamId}${opts.messageId.streamPartition}${opts.messageId.timestamp}${opts.messageId.sequenceNumber}`
        + `${opts.messageId.publisherId}${opts.messageId.msgChainId}${prev}${contentAsString}${newGroupKey}`);
};
exports.createLegacySignaturePayload = createLegacySignaturePayload;
//# sourceMappingURL=createLegacySignaturePayload.js.map