"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = getHasher;

var _util = require("@polkadot/util");

var _utilCrypto = require("@polkadot/util-crypto");

// Copyright 2017-2019 @polkadot/api-metadata authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
const DEFAULT = data => (0, _utilCrypto.xxhashAsU8a)(data, 128);

const map = {
  isBlake2128: data => (0, _utilCrypto.blake2AsU8a)(data, 128),
  isBlake2256: data => (0, _utilCrypto.blake2AsU8a)(data, 256),
  isTwox128: data => (0, _utilCrypto.xxhashAsU8a)(data, 128),
  isTwox256: data => (0, _utilCrypto.xxhashAsU8a)(data, 256),
  isTwox64Concat: data => (0, _util.u8aConcat)((0, _utilCrypto.xxhashAsU8a)(data, 64), (0, _util.u8aToU8a)(data))
};

function getHasher(hasher) {
  const [, fn] = hasher && Object.entries(map).find((_ref) => {
    let [check] = _ref;
    return hasher[check];
  }) || [undefined, DEFAULT];
  return fn;
}