Utilities for handling routing keys, validation, distance computation, and cryptography.
Methods
(static) compareKeyBuffers(b1, b2) → {number}
Compare two buffers for sorting
Name | Type | Description |
---|---|---|
b1 | buffer | Buffer to compare |
b2 | buffer | Buffer to compare |
- Type:
- number
(static) getBucketIndex(referenceKey, foreignKey) → {number}
Calculate the index of the bucket that key would belong to
Name | Type | Description |
---|---|---|
referenceKey | string | Key to compare |
foreignKey | string | Key to compare |
- Type:
- number
(static) getDistance(key1, key2) → {buffer}
Calculate the distance between two keys
Name | Type | Description |
---|---|---|
key1 | string | Identity key to compare |
key2 | string | Identity key to compare |
- Type:
- buffer
(static) getPowerOfTwoBufferForIndex(referenceKey, bucketIndex) → {buffer}
Returns a buffer with a power-of-two value given a bucket index
Name | Type | Description |
---|---|---|
referenceKey | string | | Key to find next power of two |
bucketIndex | number | Bucket index for key |
- Type:
- buffer
(static) getRandomBufferInBucketRange(referenceKey, index)
Generate a random number within the bucket's range
Name | Type | Description |
---|---|---|
referenceKey | buffer | Key for bucket distance reference |
index | number | Bucket index for random buffer selection |
(static) getRandomKeyBuffer() → {buffer}
Returns a random valid key/identity as a buffer
- Type:
- buffer
(static) getRandomKeyString() → {string}
Returns a random valid key/identity as a string
- Type:
- string
(static) hash160(input)
Returns the RMD-160 hash of the input
Name | Type | Description |
---|---|---|
input | buffer | Data to hash |
(static) hash256(input)
Returns the SHA-256 hash of the input
Name | Type | Description |
---|---|---|
input | buffer | Data to hash |
(static) isHexaString(str) → {boolean}
Tests if a string is valid hex
Name | Type | Description |
---|---|---|
str | string | String to validate |
- Type:
- boolean
(static) keyBufferIsValid(key) → {boolean}
Determines if the given buffer key is valid
Name | Type | Description |
---|---|---|
key | buffer | Node ID or item key |
- Type:
- boolean
(static) keyStringIsValid(key) → {boolean}
Determines if the given string key is valid
Name | Type | Description |
---|---|---|
key | string | Node ID or item key |
- Type:
- boolean
(static) toBinaryStringFromBuffer(buffer) → {string}
Converts a buffer to a string representation of binary
Name | Type | Description |
---|---|---|
buffer | buffer | Byte array to convert to binary string |
- Type:
- string