@tetcoin/util
Version:
A collection of useful utilities for @tetcoin
42 lines (36 loc) • 1.29 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = u8aToBn;
var _toBn = _interopRequireDefault(require("../hex/toBn"));
var _toHex = _interopRequireDefault(require("./toHex"));
// Copyright 2017-2019 @polkadot/util 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 u8aToBn
* @summary Creates a BN from a Uint8Array object.
* @description
* `UInt8Array` input values return the actual BN. `null` or `undefined` values returns an `0x0` value.
* @param value The value to convert
* @param options Options to pass while converting
* @param options.isLe Convert using Little Endian
* @param options.isNegative Convert using two's complement
* @example
* <BR>
*
* ```javascript
* import { u8aToBn } from '@tetcoin/util';
*
* u8aToHex(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0xf])); // 0x68656c0f
* ```
*/
function u8aToBn(value) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
isLe: true,
isNegative: false
};
return (0, _toBn.default)((0, _toHex.default)(value), options);
}