UNPKG

902 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.bnToHex = void 0;
4const index_js_1 = require("../u8a/index.js");
5const toU8a_js_1 = require("./toU8a.js");
6/**
7 * @name bnToHex
8 * @summary Creates a hex value from a BN.js bignumber object.
9 * @description
10 * `null` inputs returns a `0x` result, BN values return the actual value as a `0x` prefixed hex value. Anything that is not a BN object throws an error. With `bitLength` set, it fixes the number to the specified length.
11 * @example
12 * <BR>
13 *
14 * ```javascript
15 * import BN from 'bn.js';
16 * import { bnToHex } from '@polkadot/util';
17 *
18 * bnToHex(new BN(0x123456)); // => '0x123456'
19 * ```
20 */
21function bnToHex(value, { bitLength = -1, isLe = false, isNegative = false } = {}) {
22 return (0, index_js_1.u8aToHex)((0, toU8a_js_1.bnToU8a)(value, { bitLength, isLe, isNegative }));
23}
24exports.bnToHex = bnToHex;