Hierarchy

Constructors

Methods

  • Parameters

    • value: any

    Returns BigInt

  • binarySearch

    Desc

    Returns the first index of which given item is found in array using binary search.

    Returns

    • Index number

    Example

    const index = tree.binarySearch(array, element, Buffer.compare)
    

    Parameters

    • array: Buffer[]

      Array of items.

    • element: Buffer

      Item to find.

    • compareFunction: ((a: unknown, b: unknown) => number)
        • (a: unknown, b: unknown): number
        • Parameters

          • a: unknown
          • b: unknown

          Returns number

    Returns number

  • bufferIndexOf

    Desc

    Returns the first index of which given buffer is found in array.

    Returns

    • Index number

    Example

    const index = tree.bufferIndexOf(haystack, needle)
    

    Parameters

    Returns number

  • bufferToHex

    Desc

    Returns a hex string with 0x prefix for given buffer.

    Returns

    Example

    const hexStr = tree.bufferToHex(Buffer.from('A'))
    

    Parameters

    • value: Buffer
    • Optional withPrefix: boolean

    Returns string

  • bufferify

    Desc

    Returns a buffer type for the given value.

    Returns

    Example

    const buf = tree.bufferify('0x1234')
    

    Parameters

    • value: any

    Returns Buffer

  • bufferifyFn

    Desc

    Returns a function that will bufferify the return value.

    Returns

    Example

    const fn = tree.bufferifyFn((value) => sha256(value))
    

    Parameters

    • f: any

    Returns any

  • isHexString

    Desc

    Returns true if value is a hex string.

    Returns

    Example

    console.log(MerkleTree.isHexString('0x1234'))
    

    Parameters

    • value: string

    Returns boolean

  • linearSearch

    Desc

    Returns the first index of which given item is found in array using linear search.

    Returns

    • Index number

    Example

    const index = tree.linearSearch(array, element, (a, b) => a === b)
    

    Parameters

    • array: Buffer[]

      Array of items.

    • element: Buffer

      Item to find.

    • eqChecker: ((a: unknown, b: unknown) => boolean)
        • (a: unknown, b: unknown): boolean
        • Parameters

          • a: unknown
          • b: unknown

          Returns boolean

    Returns number

  • log2

    Desc

    Returns the log2 of number.

    Returns

    Parameters

    • n: number

    Returns number

  • print

    Desc

    Prints out a visual representation of the merkle tree.

    Example

    tree.print()
    

    Returns void

  • zip

    Desc

    Returns true if value is a hex string.

    Returns

    Example

    const zipped = tree.zip(['a', 'b'],['A', 'B'])
    console.log(zipped) // [ [ 'a', 'A' ], [ 'b', 'B' ] ]

    Parameters

    • a: any[]

      first array

    • b: any[]

      second array

    Returns any[][]

  • Parameters

    • value: any

    Returns BigInt

  • binarySearch

    Desc

    Returns the first index of which given item is found in array using binary search.

    Returns

    • Index number

    Example

    const index = MerkleTree.binarySearch(array, element, Buffer.compare)
    

    Parameters

    • array: Buffer[]

      Array of items.

    • element: Buffer

      Item to find.

    • compareFunction: ((a: unknown, b: unknown) => number)
        • (a: unknown, b: unknown): number
        • Parameters

          • a: unknown
          • b: unknown

          Returns number

    Returns number

  • bufferToHex

    Desc

    Returns a hex string with 0x prefix for given buffer.

    Returns

    Example

    const hexStr = MerkleTree.bufferToHex(Buffer.from('A'))
    

    Parameters

    • value: Buffer
    • Optional withPrefix: boolean

    Returns string

  • bufferify

    Desc

    Returns a buffer type for the given value.

    Returns

    Example

    const buf = MerkleTree.bufferify('0x1234')
    

    Parameters

    • value: any

    Returns Buffer

  • Parameters

    • hexStr: string
    • length: number

    Returns string

  • isHexString

    Desc

    Returns true if value is a hex string.

    Returns

    Example

    console.log(MerkleTree.isHexString('0x1234'))
    

    Parameters

    • v: string

    Returns boolean

  • linearSearch

    Desc

    Returns the first index of which given item is found in array using linear search.

    Returns

    • Index number

    Example

    const index = MerkleTree.linearSearch(array, element, (a, b) => a === b)
    

    Parameters

    • array: Buffer[]

      Array of items.

    • element: Buffer

      Item to find.

    • eqChecker: ((a: unknown, b: unknown) => boolean)
        • (a: unknown, b: unknown): boolean
        • Parameters

          • a: unknown
          • b: unknown

          Returns boolean

    Returns number

  • print

    Desc

    Prints out a visual representation of the given merkle tree.

    Returns

    Example

    MerkleTree.print(tree)
    

    Parameters

    • tree: any

      Merkle tree instance.

    Returns void

Generated using TypeDoc