Hierarchy

  • BN
    • BN

Implements

  • BNInputOverrides
  • BNHiddenTypes
  • BNHelper
  • BNOverrides

Constructors

  • Parameters

    • Optionalvalue: null | BNInput
    • Optionalbase: number | "hex"
    • Optionalendian: Endianness

    Returns BN

Properties

MAX_U64: string = '0xFFFFFFFFFFFFFFFF'
BN: typeof BN
wordSize: 26

Methods

  • Returns BN

    absolute value

  • Parameters

    Returns BN

    addition

  • Parameters

    • b: number

    Returns BN

    addition

  • Parameters

    • b: BN

    Returns BN

    and

  • Parameters

    • b: number

    Returns BN

    and (NOTE: andln is going to be replaced with andn in future)

  • Parameters

    • b: number

    Returns BN

    add 1 << b to the number

  • Returns number

    get number of bits occupied

  • Returns number

    return number of bytes occupied

  • Parameters

    • v: BNInput
    • methodName: keyof BNInputOverrides

    Returns boolean | BN | CompareResult

  • Returns BN

    clone number

  • Parameters

    Returns CompareResult

    compare numbers and return -1 (a < b), 0 (a == b), or 1 (a > b) depending on the comparison result

  • Parameters

    • b: number

    Returns -1 | 0 | 1

    compare numbers and return -1 (a < b), 0 (a == b), or 1 (a > b) depending on the comparison result

  • Parameters

    • dest: BN

    Returns void

    Copy to dest number

  • Parameters

    Returns BN

    divide

  • Parameters

    Returns BN

    rounded division

  • Parameters

    • num: BNInput
    • Optionalmode: string
    • Optionalpositive: boolean

    Returns {
        div: BN;
        mod: BN;
    }

    division with remainder

  • Parameters

    • b: number

    Returns BN

    divide

  • Parameters

    • p: BN

    Returns {
        a: BN;
        b: BN;
        gcd: BN;
    }

    Extended GCD results ({ a: ..., b: ..., gcd: ... })

  • Parameters

    Returns boolean

    a equals b

  • Parameters

    • b: number

    Returns boolean

    a equals b

  • Parameters

    Returns string

  • Parameters

    • units: number = DEFAULT_DECIMAL_UNITS

    Returns string

  • Parameters

    • width: number

    Returns BN

    convert from two's complement representation, where width is the bit width

  • Parameters

    • b: BN

    Returns BN

    GCD

  • Parameters

    Returns boolean

    a greater than b

  • Parameters

    Returns boolean

    a greater than or equals b

  • Parameters

    • b: number

    Returns boolean

    a greater than or equals b

  • Parameters

    • b: number

    Returns boolean

    a greater than b

  • Returns BN

    absolute value

  • Parameters

    • b: BN

    Returns BN

    addition

  • Parameters

    • b: number

    Returns BN

    addition

  • Parameters

    • b: BN

    Returns BN

    and

  • Parameters

    • b: number

    Returns BN

    divide

  • Parameters

    • b: number

    Returns BN

    clear bits with indexes higher or equal to b

  • Parameters

    • b: BN

    Returns BN

    multiply

  • Parameters

    • b: number

    Returns BN

    multiply

  • Returns BN

    negate sign

  • Parameters

    • w: number

    Returns BN

    not (for the width specified by w)

  • Parameters

    • b: BN

    Returns BN

    inverse a modulo b

  • Parameters

    • b: BN

    Returns BN

    or

  • Returns boolean

    check if value is even

  • Returns boolean

    true if the number is negative

  • Returns boolean

    check if value is odd

  • Returns boolean

    check if value is zero

  • Parameters

    • b: number

    Returns BN

    shift left

  • Returns BN

    square

  • Parameters

    • b: BN

    Returns BN

    subtraction

  • Parameters

    • b: number

    Returns BN

    subtraction

  • Parameters

    • b: BN

    Returns BN

    and

  • Parameters

    • b: BN

    Returns BN

    or

  • Parameters

    • b: number

    Returns BN

    shift left

  • Parameters

    • b: number

    Returns BN

    shift right

  • Parameters

    • b: BN

    Returns BN

    xor

  • Parameters

    • b: BN

    Returns BN

    xor

  • Parameters

    Returns boolean

    a less than b

  • Parameters

    Returns boolean

    a less than or equals b

  • Parameters

    • b: number

    Returns boolean

    a less than or equals b

  • Parameters

    • b: number

    Returns boolean

    a less than b

  • Parameters

    • b: number

    Returns BN

    clear bits with indexes higher or equal to b

  • Parameters

    Returns BN

  • Returns BN

  • Parameters

    Returns BN

    reduct

  • Parameters

    • b: number

    Returns number

    reduct

  • Parameters

    • b: number

    Returns number

    reduct

  • Parameters

    Returns BN

    multiply

  • Parameters

    Returns BN

  • Parameters

    • b: number

    Returns BN

    multiply

  • Returns BN

    negate sign

  • Returns BN

  • Parameters

    • w: number

    Returns BN

    not (for the width specified by w)

  • Parameters

    • b: BN

    Returns BN

    or

  • Parameters

    Returns BN

    raise a to the power of b

  • Parameters

    • b: number
    • value: boolean | 0 | 1

    Returns BN

    set specified bit to value

  • Parameters

    • b: number

    Returns BN

    shift left

  • Parameters

    • b: number

    Returns BN

    shift right

  • Returns BN

    square

  • Parameters

    Returns BN

    subtraction

  • Parameters

    • b: number

    Returns BN

    subtraction

  • Parameters

    • b: number

    Returns boolean

    test if specified bit is set

  • Parameters

    • Optionalendian: Endianness
    • Optionallength: number

    Returns number[]

    convert to byte Array, and optionally zero pad to length, throwing if already exceeding

  • Parameters

    • ArrayType: BufferConstructor
    • Optionalendian: Endianness
    • Optionallength: number

    Returns Buffer<ArrayBufferLike>

    convert to an instance of type, which must behave like an Array

  • Parameters

    • ArrayType: any[]
    • Optionalendian: Endianness
    • Optionallength: number

    Returns any[]

  • Parameters

    • Optionalendian: Endianness
    • Optionallength: number

    Returns Buffer<ArrayBufferLike>

    convert to Node.js Buffer (if available). For compatibility with browserify and similar tools, use this instead: a.toArrayLike(Buffer, endian, length)

  • Parameters

    • OptionalbytesPadding: number

    Returns Uint8Array<ArrayBufferLike>

  • Parameters

    • OptionalbytesPadding: number

    Returns string

  • Returns string

    convert to JSON compatible hex string (alias of toString(16))

  • Returns number

    convert to Javascript Number (limited to 53 bits)

  • Parameters

    • reductionContext: ReductionContext

    Returns RedBN

    Convert number to red

  • Parameters

    • Optionalbase: number | "hex"
    • Optionallength: number

    Returns string

    convert to base-string and pad with zeroes

  • Parameters

    • width: number

    Returns BN

    convert to two's complement representation, where width is bit width

  • Parameters

    • b: BN

    Returns BN

    and

  • Parameters

    • b: BN

    Returns -1 | 0 | 1

    compare numbers and return -1 (a < b), 0 (a == b), or 1 (a > b) depending on the comparison result

  • Parameters

    • b: BN

    Returns BN

    reduct

  • Parameters

    • b: BN

    Returns BN

    or

  • Parameters

    • b: number

    Returns BN

    shift left

  • Parameters

    • b: number

    Returns BN

    shift right

  • Parameters

    • b: BN

    Returns BN

    xor

  • Returns the primitive value of the specified object.

    Returns string

  • Parameters

    • b: BN

    Returns BN

    xor

  • Returns number

    return number of less-significant consequent zero bits (example: 1010000 has 4 zero bits)

  • Parameters

    • b: any

    Returns b is BN

    returns true if the supplied object is a BN.js instance

  • Parameters

    • left: BN
    • right: BN

    Returns BN

    returns the maximum of 2 BN instances.

  • Parameters

    • left: BN
    • right: BN

    Returns BN

    returns the minimum of 2 BN instances.

  • Parameters

    • num: BN

    Returns ReductionContext

    create a reduction context with the Montgomery trick.

  • Parameters

    • reductionContext: BN | IPrimeName

    Returns ReductionContext

    create a reduction context