Files
common/packages/util/src/hex/toBigInt.ts
T
Jaco c96ad1a34e Align BigInt functions with BN (option handling) (#1587)
* Align BigInt functions with BN (option handling)

* CHANGELOG

* Pass bitLength parameter
2022-07-07 10:49:40 +03:00

20 lines
598 B
TypeScript

// Copyright 2017-2022 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ToBnOptions } from '../types';
import { BigInt } from '@polkadot/x-bigint';
import { u8aToBigInt } from '../u8a/toBigInt';
import { hexToU8a } from './toU8a';
/**
* @name hexToBigInt
* @summary Creates a BigInt instance object from a hex string.
*/
export function hexToBigInt (value?: string | null, { isLe = false, isNegative = false }: ToBnOptions = {}): bigint {
return !value || value === '0x'
? BigInt(0)
: u8aToBigInt(hexToU8a(value), { isLe, isNegative });
}