text: "use strict";
  
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
  
  exports.__esModule = true;
  exports.getFeedTopic = exports.createFeedDigest = exports.bytesToHexValue = void 0;
  
  var _hex = _interopRequireWildcard(require("@erebos/hex"));
  
  var _keccak = require("@erebos/keccak256");
  
  var FEED_TOPIC_LENGTH = 32;
  var FEED_USER_LENGTH = 20;
  var FEED_TIME_LENGTH = 7;
  var FEED_LEVEL_LENGTH = 1;
  var FEED_HEADER_LENGTH = 8;
  
  var bytesToHexValue = function bytesToHexValue(bytes) {
    return (0, _hex.hexValueType)('0x' + Buffer.from(bytes).toString('hex'));
  };
  
  exports.bytesToHexValue = bytesToHexValue;
  
  var createFeedDigest = function createFeedDigest(meta, data) {
    var topicBuffer = (0, _hex.default)(meta.feed.topic).toBuffer();
  
    if (topicBuffer.length !== FEED_TOPIC_LENGTH) {
      throw new Error('Invalid topic length');
    }
  
    var userBuffer = (0, _hex.default)(meta.feed.user).toBuffer();
  
    if (userBuffer.length !== FEED_USER_LENGTH) {
      throw new Error('Invalid user length');
    }
  
    var headerBuffer = Buffer.alloc(FEED_HEADER_LENGTH, 0);
    headerBuffer.writeInt8(meta.protocolVersion, 0);
    var timeBuffer = Buffer.alloc(FEED_TIME_LENGTH, 0);
    timeBuffer.writeUInt32LE(meta.epoch.time, 0);
    var levelBuffer = Buffer.alloc(FEED_LEVEL_LENGTH, 0);
    levelBuffer.writeUInt8(meta.epoch.level, 0);
    var payload = Buffer.concat([headerBuffer, topicBuffer, userBuffer, timeBuffer, levelBuffer, (0, _hex.default)(data).toBuffer()]);
    return (0, _keccak.hash)(payload);
  };
  
  exports.createFeedDigest = createFeedDigest;
  
  var getFeedTopic = function getFeedTopic(params) {
    var topicHex = (0, _hex.default)(params.topic || Buffer.alloc(FEED_TOPIC_LENGTH));
  
    if (params.name == null) {
      return topicHex.value;
    }
  
    var name = Buffer.from(params.name);
    var topic = topicHex.toBuffer();
    var bytes = Array(FEED_TOPIC_LENGTH).fill().map(function (_, i) {
      return topic[i] ^ name[i];
    });
    return bytesToHexValue(bytes);
  };
  
  exports.getFeedTopic = getFeedTopic;