Skip to content

Latest commit

 

History

History
300 lines (186 loc) · 4.64 KB

_src_base_.base.md

File metadata and controls

300 lines (186 loc) · 4.64 KB

merkletreejsGlobals"src/Base"Base

Class: Base

Hierarchy

Index

Methods

Methods

Protected _bufferIndexOf

_bufferIndexOf(array: Buffer[], element: Buffer): number

bufferIndexOf

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

example

const index = tree.bufferIndexOf(haystack, needle)

Parameters:

Name Type
array Buffer[]
element Buffer

Returns: number

  • Index number

Protected _isHexString

_isHexString(value: string): boolean

isHexString

desc Returns true if value is a hex string.

example

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

Parameters:

Name Type
value string

Returns: boolean


Protected _log2

_log2(n: number): number

log2

desc Returns the log2 of number.

Parameters:

Name Type
n number

Returns: number


Protected _zip

_zip(a: any[], b: any[]): any[][]

zip

desc Returns true if value is a hex string.

example

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

Parameters:

Name Type Description
a any[] first array
b any[] second array

Returns: any[][]


bufferToHex

bufferToHex(value: Buffer, withPrefix: boolean): string

bufferToHex

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

example

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

Parameters:

Name Type Default
value Buffer -
withPrefix boolean true

Returns: string


bufferify

bufferify(value: any): Buffer

bufferify

desc Returns a buffer type for the given value.

example

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

Parameters:

Name Type
value any

Returns: Buffer


bufferifyFn

bufferifyFn(f: any): any

bufferifyFn

desc Returns a function that will bufferify the return value.

example

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

Parameters:

Name Type
f any

Returns: any


print

print(): void

print

desc Prints out a visual representation of the merkle tree.

example

tree.print()

Returns: void


Static bufferToHex

bufferToHex(value: Buffer, withPrefix: boolean): string

bufferToHex

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

example

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

Parameters:

Name Type Default
value Buffer -
withPrefix boolean true

Returns: string


Static bufferify

bufferify(value: any): Buffer

bufferify

desc Returns a buffer type for the given value.

example

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

Parameters:

Name Type
value any

Returns: Buffer


Static isHexString

isHexString(v: string): boolean

isHexString

desc Returns true if value is a hex string.

example

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

Parameters:

Name Type
v string

Returns: boolean


Static print

print(tree: any): void

print

desc Prints out a visual representation of the given merkle tree.

example

MerkleTree.print(tree)

Parameters:

Name Type Description
tree any Merkle tree instance.

Returns: void