@polkadot/util
Version:
A collection of useful utilities for @polkadot
33 lines (27 loc) • 938 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.u8aToBn = u8aToBn;
var _bn = require("../bn/bn");
var _boolean = require("../is/boolean");
var _spread = require("../object/spread");
// Copyright 2017-2022 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
/** @deprecated Use hexToBn (value?: string | null, options?: ToBnOptions) */
function u8aToBn(value) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
// NOTE: This is the same process as followed in the hexToBn conversion
// For Uint8Array, default to LE
const {
isLe,
isNegative
} = (0, _spread.objectSpread)({
isLe: true,
isNegative: false
}, (0, _boolean.isBoolean)(options) ? {
isLe: options
} : options);
const bn = new _bn.BN(value, isLe ? 'le' : 'be');
return isNegative && value.length ? bn.fromTwos(value.length * 8) : bn;
}