"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertStreamMessageToMessage = void 0;
const trackerless_network_1 = require("@streamr/trackerless-network");
const IdentityMapping_1 = require("./identity/IdentityMapping");
const stringVersionsOfSignatureTypes = {
    // Read key pair SignatureTypes from IdentityMapping
    ...Object.fromEntries(Object.entries(IdentityMapping_1.IdentityMapping).map(([keyType, config]) => [config.signatureType, keyType])),
    // These special ones need to be added manually
    [trackerless_network_1.SignatureType.ECDSA_SECP256K1_LEGACY]: 'ECDSA_SECP256K1_LEGACY',
    [trackerless_network_1.SignatureType.ERC_1271]: 'ERC_1271',
};
function signatureTypeToString(signatureType) {
    const result = stringVersionsOfSignatureTypes[signatureType];
    if (!result) {
        throw new Error(`Unknown signature type: ${signatureType}`);
    }
    return result;
}
const convertStreamMessageToMessage = (msg) => {
    return {
        content: msg.getParsedContent(),
        streamId: msg.getStreamId(),
        streamPartition: msg.getStreamPartition(),
        timestamp: msg.getTimestamp(),
        sequenceNumber: msg.getSequenceNumber(),
        signature: msg.signature,
        signatureType: signatureTypeToString(msg.signatureType),
        publisherId: msg.getPublisherId(),
        msgChainId: msg.getMsgChainId(),
        groupKeyId: msg.groupKeyId,
        streamMessage: msg
        // TODO add other relevant fields (could update some test assertions to
        // use those keys instead of getting the fields via from streamMessage property)
    };
};
exports.convertStreamMessageToMessage = convertStreamMessageToMessage;
//# sourceMappingURL=Message.js.map