Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • BN

Index

Constructors

  • new BN(number: string | number | number[] | Uint8Array | Buffer | BN, base?: number | "hex", endian?: Endianness): BN
  • new BN(number: string | number | number[] | Uint8Array | Buffer | BN, endian?: Endianness): BN
  • Parameters

    • number: string | number | number[] | Uint8Array | Buffer | BN
    • Optional base: number | "hex"
    • Optional endian: Endianness

    Returns BN

  • Parameters

    • number: string | number | number[] | Uint8Array | Buffer | BN
    • Optional endian: Endianness

    Returns BN

Methods

  • description

    absolute value

    Returns BN

  • description

    addition

    Parameters

    Returns BN

  • addn(b: number): BN
  • description

    addition

    Parameters

    • b: number

    Returns BN

  • description

    and

    Parameters

    Returns BN

  • andln(b: number): BN
  • description

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

    Parameters

    • b: number

    Returns BN

  • bincn(b: number): BN
  • description

    add 1 << b to the number

    Parameters

    • b: number

    Returns BN

  • bitLength(): number
  • description

    get number of bits occupied

    Returns number

  • byteLength(): number
  • description

    return number of bytes occupied

    Returns number

  • clone(): BN
  • description

    clone number

    Returns BN

  • cmp(b: BN): 0 | 1 | -1
  • description

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

    Parameters

    Returns 0 | 1 | -1

  • cmpn(b: number): 0 | 1 | -1
  • description

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

    Parameters

    • b: number

    Returns 0 | 1 | -1

  • description

    divide

    Parameters

    Returns BN

  • description

    rounded division

    Parameters

    Returns BN

  • divn(b: number): BN
  • description

    divide

    Parameters

    • b: number

    Returns BN

  • description

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

    Parameters

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

  • eq(b: BN): boolean
  • description

    a equals b

    Parameters

    Returns boolean

  • eqn(b: number): boolean
  • description

    a equals b

    Parameters

    • b: number

    Returns boolean

  • fromTwos(width: number): BN
  • description

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

    Parameters

    • width: number

    Returns BN

  • description

    GCD

    Parameters

    Returns BN

  • gt(b: BN): boolean
  • description

    a greater than b

    Parameters

    Returns boolean

  • gte(b: BN): boolean
  • description

    a greater than or equals b

    Parameters

    Returns boolean

  • gten(b: number): boolean
  • description

    a greater than or equals b

    Parameters

    • b: number

    Returns boolean

  • gtn(b: number): boolean
  • description

    a greater than b

    Parameters

    • b: number

    Returns boolean

  • iabs(): BN
  • description

    absolute value

    Returns BN

  • description

    addition

    Parameters

    Returns BN

  • iaddn(b: number): BN
  • description

    addition

    Parameters

    • b: number

    Returns BN

  • description

    and

    Parameters

    Returns BN

  • idivn(b: number): BN
  • description

    divide

    Parameters

    • b: number

    Returns BN

  • imaskn(b: number): BN
  • description

    clear bits with indexes higher or equal to b

    Parameters

    • b: number

    Returns BN

  • description

    multiply

    Parameters

    Returns BN

  • imuln(b: number): BN
  • description

    multiply

    Parameters

    • b: number

    Returns BN

  • ineg(): BN
  • description

    negate sign

    Returns BN

  • inotn(w: number): BN
  • description

    not (for the width specified by w)

    Parameters

    • w: number

    Returns BN

  • description

    inverse a modulo b

    Parameters

    Returns BN

  • description

    or

    Parameters

    Returns BN

  • isEven(): boolean
  • description

    check if value is even

    Returns boolean

  • isNeg(): boolean
  • description

    true if the number is negative

    Returns boolean

  • isOdd(): boolean
  • description

    check if value is odd

    Returns boolean

  • isZero(): boolean
  • description

    check if value is zero

    Returns boolean

  • ishln(b: number): BN
  • description

    shift left

    Parameters

    • b: number

    Returns BN

  • ishrn(b: number): BN
  • isqr(): BN
  • description

    square

    Returns BN

  • description

    subtraction

    Parameters

    Returns BN

  • isubn(b: number): BN
  • description

    subtraction

    Parameters

    • b: number

    Returns BN

  • description

    and

    Parameters

    Returns BN

  • description

    or

    Parameters

    Returns BN

  • iushln(b: number): BN
  • description

    shift left

    Parameters

    • b: number

    Returns BN

  • iushrn(b: number): BN
  • description

    shift right

    Parameters

    • b: number

    Returns BN

  • description

    xor

    Parameters

    Returns BN

  • description

    xor

    Parameters

    Returns BN

  • lt(b: BN): boolean
  • description

    a less than b

    Parameters

    Returns boolean

  • lte(b: BN): boolean
  • description

    a less than or equals b

    Parameters

    Returns boolean

  • lten(b: number): boolean
  • description

    a less than or equals b

    Parameters

    • b: number

    Returns boolean

  • ltn(b: number): boolean
  • description

    a less than b

    Parameters

    • b: number

    Returns boolean

  • maskn(b: number): BN
  • description

    clear bits with indexes higher or equal to b

    Parameters

    • b: number

    Returns BN

  • description

    reduct

    Parameters

    Returns BN

  • modn(b: number): number
  • description

    multiply

    Parameters

    Returns BN

  • muln(b: number): BN
  • description

    multiply

    Parameters

    • b: number

    Returns BN

  • description

    negate sign

    Returns BN

  • notn(w: number): BN
  • description

    not (for the width specified by w)

    Parameters

    • w: number

    Returns BN

  • description

    or

    Parameters

    Returns BN

  • description

    raise a to the power of b

    Parameters

    Returns BN

  • setn(b: number): BN
  • description

    set specified bit to 1

    Parameters

    • b: number

    Returns BN

  • shln(b: number): BN
  • description

    shift left

    Parameters

    • b: number

    Returns BN

  • shrn(b: number): BN
  • description

    shift right

    Parameters

    • b: number

    Returns BN

  • description

    square

    Returns BN

  • description

    subtraction

    Parameters

    Returns BN

  • subn(b: number): BN
  • description

    subtraction

    Parameters

    • b: number

    Returns BN

  • testn(b: number): boolean
  • description

    test if specified bit is set

    Parameters

    • b: number

    Returns boolean

  • toArray(endian?: Endianness, length?: number): number[]
  • description

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

    Parameters

    • Optional endian: Endianness
    • Optional length: number

    Returns number[]

  • toArrayLike(ArrayType: BufferConstructor, endian?: Endianness, length?: number): Buffer
  • toArrayLike(ArrayType: any[], endian?: Endianness, length?: number): any[]
  • description

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

    Parameters

    • ArrayType: BufferConstructor
    • Optional endian: Endianness
    • Optional length: number

    Returns Buffer

  • Parameters

    • ArrayType: any[]
    • Optional endian: Endianness
    • Optional length: number

    Returns any[]

  • toBuffer(endian?: Endianness, length?: number): Buffer
  • description

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

    Parameters

    • Optional endian: Endianness
    • Optional length: number

    Returns Buffer

  • toJSON(): string
  • description

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

    Returns string

  • toNumber(): number
  • description

    convert to Javascript Number (limited to 53 bits)

    Returns number

  • description

    Convert number to red

    Parameters

    Returns RedBN

  • toString(base?: number | "hex", length?: number): string
  • description

    convert to base-string and pad with zeroes

    Parameters

    • Optional base: number | "hex"
    • Optional length: number

    Returns string

  • toTwos(width: number): BN
  • description

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

    Parameters

    • width: number

    Returns BN

  • description

    and

    Parameters

    Returns BN

  • ucmp(b: BN): 0 | 1 | -1
  • description

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

    Parameters

    Returns 0 | 1 | -1

  • description

    reduct

    Parameters

    Returns BN

  • description

    or

    Parameters

    Returns BN

  • ushln(b: number): BN
  • description

    shift left

    Parameters

    • b: number

    Returns BN

  • ushrn(b: number): BN
  • description

    shift right

    Parameters

    • b: number

    Returns BN

  • description

    xor

    Parameters

    Returns BN

  • description

    xor

    Parameters

    Returns BN

  • zeroBits(): number
  • description

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

    Returns number

  • isBN(b: any): b is BN
  • description

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

    Parameters

    • b: any

    Returns b is BN

  • description

    returns the maximum of 2 BN instances.

    Parameters

    Returns BN

  • description

    returns the minimum of 2 BN instances.

    Parameters

    Returns BN

  • description

    create a reduction context with the Montgomery trick.

    Parameters

    Returns ReductionContext

  • description

    create a reduction context

    Parameters

    Returns ReductionContext

Generated using TypeDoc