* Align BigInt functions with BN (option handling) * CHANGELOG * Pass bitLength parameter
20 lines
598 B
TypeScript
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 });
|
|
}
|