@plugnet/util-crypto
Version:
A collection of useful crypto utilities for @plugnet
35 lines (29 loc) • 1.08 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = xxhashAsHex;
var _util = require("@plugnet/util");
var _asU8a = _interopRequireDefault(require("./asU8a"));
// Copyright 2017-2019 @polkadot/util-crypto authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
/**
* @name xxhashAsHex
* @summary Creates a xxhash64 hex from the input.
* @description
* From either a `string`, `Uint8Array` or a `Buffer` input, create the xxhash64 and return the result as a hex string with the specified `bitLength`.
* @example
* <BR>
*
* ```javascript
* import { xxhashAsHex } from '@plugnet/util-crypto';
*
* xxhashAsHex('abc'); // => 0x44bc2cf5ad770999
* ```
*/
function xxhashAsHex(data) {
let bitLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 64;
return (0, _util.u8aToHex)((0, _asU8a.default)(data, bitLength));
}