Utilities for handling routing keys, validation, distance computation, and cryptography.

Methods

(static) compareKeyBuffers(b1, b2) → {number}

Compare two buffers for sorting

Parameters:
NameTypeDescription
b1buffer

Buffer to compare

b2buffer

Buffer to compare

Returns:
Type: 
number

(static) getBucketIndex(referenceKey, foreignKey) → {number}

Calculate the index of the bucket that key would belong to

Parameters:
NameTypeDescription
referenceKeystring

Key to compare

foreignKeystring

Key to compare

Returns:
Type: 
number

(static) getDistance(key1, key2) → {buffer}

Calculate the distance between two keys

Parameters:
NameTypeDescription
key1string

Identity key to compare

key2string

Identity key to compare

Returns:
Type: 
buffer

(static) getPowerOfTwoBufferForIndex(referenceKey, bucketIndex) → {buffer}

Returns a buffer with a power-of-two value given a bucket index

Parameters:
NameTypeDescription
referenceKeystring | buffer

Key to find next power of two

bucketIndexnumber

Bucket index for key

Returns:
Type: 
buffer

(static) getRandomBufferInBucketRange(referenceKey, index)

Generate a random number within the bucket's range

Parameters:
NameTypeDescription
referenceKeybuffer

Key for bucket distance reference

indexnumber

Bucket index for random buffer selection

(static) getRandomKeyBuffer() → {buffer}

Returns a random valid key/identity as a buffer

Returns:
Type: 
buffer

(static) getRandomKeyString() → {string}

Returns a random valid key/identity as a string

Returns:
Type: 
string

(static) hash160(input)

Returns the RMD-160 hash of the input

Parameters:
NameTypeDescription
inputbuffer

Data to hash

(static) hash256(input)

Returns the SHA-256 hash of the input

Parameters:
NameTypeDescription
inputbuffer

Data to hash

(static) isHexaString(str) → {boolean}

Tests if a string is valid hex

Parameters:
NameTypeDescription
strstring

String to validate

Returns:
Type: 
boolean

(static) keyBufferIsValid(key) → {boolean}

Determines if the given buffer key is valid

Parameters:
NameTypeDescription
keybuffer

Node ID or item key

Returns:
Type: 
boolean

(static) keyStringIsValid(key) → {boolean}

Determines if the given string key is valid

Parameters:
NameTypeDescription
keystring

Node ID or item key

Returns:
Type: 
boolean

(static) toBinaryStringFromBuffer(buffer) → {string}

Converts a buffer to a string representation of binary

Parameters:
NameTypeDescription
bufferbuffer

Byte array to convert to binary string

Returns:
Type: 
string