Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • BN

Index

Constructors

constructor

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

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

    Returns BN

  • Parameters

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

    Returns BN

Properties

Static BN

BN: typeof BN

Static wordSize

wordSize: 26

Methods

abs

  • description

    absolute value

    Returns BN

add

  • description

    addition

    Parameters

    Returns BN

addn

  • addn(b: number): BN
  • description

    addition

    Parameters

    • b: number

    Returns BN

and

  • description

    and

    Parameters

    Returns BN

andln

  • andln(b: number): BN
  • description

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

    Parameters

    • b: number

    Returns BN

bincn

  • bincn(b: number): BN
  • description

    add 1 << b to the number

    Parameters

    • b: number

    Returns BN

bitLength

  • bitLength(): number
  • description

    get number of bits occupied

    Returns number

byteLength

  • byteLength(): number
  • description

    return number of bytes occupied

    Returns number

clone

  • clone(): BN
  • description

    clone number

    Returns BN

cmp

  • 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

  • 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

div

  • description

    divide

    Parameters

    Returns BN

divRound

  • description

    rounded division

    Parameters

    Returns BN

divn

  • divn(b: number): BN
  • description

    divide

    Parameters

    • b: number

    Returns BN

egcd

  • description

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

    Parameters

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

eq

  • eq(b: BN): boolean
  • description

    a equals b

    Parameters

    Returns boolean

eqn

  • eqn(b: number): boolean
  • description

    a equals b

    Parameters

    • b: number

    Returns boolean

fromTwos

  • fromTwos(width: number): BN
  • description

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

    Parameters

    • width: number

    Returns BN

gcd

  • description

    GCD

    Parameters

    Returns BN

gt

  • gt(b: BN): boolean
  • description

    a greater than b

    Parameters

    Returns boolean

gte

  • gte(b: BN): boolean
  • description

    a greater than or equals b

    Parameters

    Returns boolean

gten

  • gten(b: number): boolean
  • description

    a greater than or equals b

    Parameters

    • b: number

    Returns boolean

gtn

  • gtn(b: number): boolean
  • description

    a greater than b

    Parameters

    • b: number

    Returns boolean

iabs

  • iabs(): BN
  • description

    absolute value

    Returns BN

iadd

  • description

    addition

    Parameters

    Returns BN

iaddn

  • iaddn(b: number): BN
  • description

    addition

    Parameters

    • b: number

    Returns BN

iand

  • description

    and

    Parameters

    Returns BN

idivn

  • idivn(b: number): BN
  • description

    divide

    Parameters

    • b: number

    Returns BN

imaskn

  • imaskn(b: number): BN
  • description

    clear bits with indexes higher or equal to b

    Parameters

    • b: number

    Returns BN

imul

  • description

    multiply

    Parameters

    Returns BN

imuln

  • imuln(b: number): BN
  • description

    multiply

    Parameters

    • b: number

    Returns BN

ineg

  • ineg(): BN
  • description

    negate sign

    Returns BN

inotn

  • inotn(w: number): BN
  • description

    not (for the width specified by w)

    Parameters

    • w: number

    Returns BN

invm

  • description

    inverse a modulo b

    Parameters

    Returns BN

ior

  • description

    or

    Parameters

    Returns BN

isEven

  • isEven(): boolean
  • description

    check if value is even

    Returns boolean

isNeg

  • isNeg(): boolean
  • description

    true if the number is negative

    Returns boolean

isOdd

  • isOdd(): boolean
  • description

    check if value is odd

    Returns boolean

isZero

  • isZero(): boolean
  • description

    check if value is zero

    Returns boolean

ishln

  • ishln(b: number): BN
  • description

    shift left

    Parameters

    • b: number

    Returns BN

ishrn

  • ishrn(b: number): BN

isqr

  • isqr(): BN
  • description

    square

    Returns BN

isub

  • description

    subtraction

    Parameters

    Returns BN

isubn

  • isubn(b: number): BN
  • description

    subtraction

    Parameters

    • b: number

    Returns BN

iuand

  • description

    and

    Parameters

    Returns BN

iuor

  • description

    or

    Parameters

    Returns BN

iushln

  • iushln(b: number): BN
  • description

    shift left

    Parameters

    • b: number

    Returns BN

iushrn

  • iushrn(b: number): BN
  • description

    shift right

    Parameters

    • b: number

    Returns BN

iuxor

  • description

    xor

    Parameters

    Returns BN

ixor

  • description

    xor

    Parameters

    Returns BN

lt

  • lt(b: BN): boolean
  • description

    a less than b

    Parameters

    Returns boolean

lte

  • lte(b: BN): boolean
  • description

    a less than or equals b

    Parameters

    Returns boolean

lten

  • lten(b: number): boolean
  • description

    a less than or equals b

    Parameters

    • b: number

    Returns boolean

ltn

  • ltn(b: number): boolean
  • description

    a less than b

    Parameters

    • b: number

    Returns boolean

maskn

  • maskn(b: number): BN
  • description

    clear bits with indexes higher or equal to b

    Parameters

    • b: number

    Returns BN

mod

  • description

    reduct

    Parameters

    Returns BN

modn

  • modn(b: number): number
  • deprecated
    description

    reduct

    Parameters

    • b: number

    Returns number

modrn

  • modrn(b: number): number
  • description

    reduct

    Parameters

    • b: number

    Returns number

mul

  • description

    multiply

    Parameters

    Returns BN

muln

  • muln(b: number): BN
  • description

    multiply

    Parameters

    • b: number

    Returns BN

neg

  • description

    negate sign

    Returns BN

notn

  • notn(w: number): BN
  • description

    not (for the width specified by w)

    Parameters

    • w: number

    Returns BN

or

  • description

    or

    Parameters

    Returns BN

pow

  • description

    raise a to the power of b

    Parameters

    Returns BN

setn

  • setn(b: number): BN
  • description

    set specified bit to 1

    Parameters

    • b: number

    Returns BN

shln

  • shln(b: number): BN
  • description

    shift left

    Parameters

    • b: number

    Returns BN

shrn

  • shrn(b: number): BN
  • description

    shift right

    Parameters

    • b: number

    Returns BN

sqr

  • description

    square

    Returns BN

sub

  • description

    subtraction

    Parameters

    Returns BN

subn

  • subn(b: number): BN
  • description

    subtraction

    Parameters

    • b: number

    Returns BN

testn

  • testn(b: number): boolean
  • description

    test if specified bit is set

    Parameters

    • b: number

    Returns boolean

toArray

  • 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

  • toArrayLike(ArrayType: typeof Buffer, 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: typeof Buffer
    • Optional endian: Endianness
    • Optional length: number

    Returns Buffer

  • Parameters

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

    Returns any[]

toBuffer

  • 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

  • toJSON(): string
  • description

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

    Returns string

toNumber

  • toNumber(): number
  • description

    convert to Javascript Number (limited to 53 bits)

    Returns number

toRed

  • description

    Convert number to red

    Parameters

    Returns RedBN

toString

  • 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

  • toTwos(width: number): BN
  • description

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

    Parameters

    • width: number

    Returns BN

uand

  • description

    and

    Parameters

    Returns BN

ucmp

  • 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

umod

  • description

    reduct

    Parameters

    Returns BN

uor

  • description

    or

    Parameters

    Returns BN

ushln

  • ushln(b: number): BN
  • description

    shift left

    Parameters

    • b: number

    Returns BN

ushrn

  • ushrn(b: number): BN
  • description

    shift right

    Parameters

    • b: number

    Returns BN

uxor

  • description

    xor

    Parameters

    Returns BN

xor

  • description

    xor

    Parameters

    Returns BN

zeroBits

  • zeroBits(): number
  • description

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

    Returns number

Static isBN

  • 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

Static max

  • description

    returns the maximum of 2 BN instances.

    Parameters

    Returns BN

Static min

  • description

    returns the minimum of 2 BN instances.

    Parameters

    Returns BN

Static mont

  • description

    create a reduction context with the Montgomery trick.

    Parameters

    Returns ReductionContext

Static red

  • description

    create a reduction context

    Parameters

    Returns ReductionContext

Generated using TypeDoc