Module: kadence/utils

Source:

Methods


<static> compareKeyBuffers(b1, b2)

Compare two buffers for sorting
Parameters:
Name Type Description
b1 buffer Buffer to compare
b2 buffer Buffer to compare
Source:
Returns:
Type
number

<static> getBucketIndex(referenceKey, foreignKey)

Calculate the index of the bucket that key would belong to
Parameters:
Name Type Description
referenceKey string Key to compare
foreignKey string Key to compare
Source:
Returns:
Type
number

<static> getContactURL(contact)

Returns a stringified URL from the supplied contact object
Parameters:
Name Type Description
contact Bucket~contact
Source:
Returns:
Type
string

<static> getDistance(key1, key2)

Calculate the distance between two keys
Parameters:
Name Type Description
key1 string Identity key to compare
key2 string Identity key to compare
Source:
Returns:
Type
buffer

<static> getPowerOfTwoBufferForIndex(referenceKey, bucketIndex)

Returns a buffer with a power-of-two value given a bucket index
Parameters:
Name Type Description
referenceKey string | buffer Key to find next power of two
bucketIndex number Bucket index for key
Source:
Returns:
Type
buffer

<static> getRandomBufferInBucketRange(referenceKey, index)

Generate a random number within the bucket's range
Parameters:
Name Type Description
referenceKey buffer Key for bucket distance reference
index number Bucket index for random buffer selection
Source:

<static> getRandomKeyBuffer()

Returns a random valid key/identity as a buffer
Source:
Returns:
Type
buffer

<static> getRandomKeyString()

Returns a random valid key/identity as a string
Source:
Returns:
Type
string

<static> hash160(input)

Returns the RMD-160 hash of the input
Parameters:
Name Type Description
input buffer Data to hash
Source:

<static> hash256(input)

Returns the SHA-256 hash of the input
Parameters:
Name Type Description
input buffer Data to hash
Source:

<static> isCompatibleVersion(version)

Returns whether or not the supplied semver tag is compatible
Parameters:
Name Type Description
version string The semver tag from the contact
Source:
Returns:
Type
boolean

<static> isDerivedFromExtendedPublicKey(hexPublicKey, extPublicKey, derivationIndex, derivationPath)

Verifies the public key is derives from the index of the extended public key. Special case: if index is -1, then matches the public key against the extended public key with zeroed chain code.
Parameters:
Name Type Description
hexPublicKey string Public ECDSA key
extPublicKey string Public extended key
derivationIndex number Derivation index
derivationPath string Derivation path
Source:
Returns:
Type
boolean

<static> isHexaString(a)

Determines if a value is hexadecimal string
Parameters:
Name Type Description
a string The value to be tested
Source:
Returns:
Type
boolean

<static> isValidContact(contact, loopback)

Determines if the supplied contact is valid
Parameters:
Name Type Description
contact Bucket~contact The contact information for a given peer
loopback boolean Allows contacts that are localhost
Source:
Returns:
Type
boolean

<static> isValidHDNodeKey(hdKey)

Checks if the supplied HD key is valid (base58 encoded) and proper length
Parameters:
Name Type Description
hdKey string The HD key in base 58 encoding
Source:
Returns:
isValidHDKey
Type
boolean

<static> isValidNodeIndex(hdIndex)

Checks if the input is a non-hardened HD key index
Parameters:
Name Type Description
hdIndex number The HD key index
Source:
Returns:
isValidHDKeyIndex
Type
boolean

<static> keyBufferIsValid(key)

Determines if the given buffer key is valid
Parameters:
Name Type Description
key buffer Node ID or item key
Source:
Returns:
Type
boolean

<static> keyStringIsValid(key)

Determines if the given string key is valid
Parameters:
Name Type Description
key string Node ID or item key
Source:
Returns:
Type
boolean

<static> noise33()

Returns 33 bytes of random data
Source:
Returns:
Type
buffer

<static> parseContactURL()

Returns a parsed contact object from a URL
Source:
Returns:
Type
object

<static> preventConvoy(func [, maxtime])

Wraps the supplied function in a pseudo-random length timeout to help prevent convoy effects. These occur when a number of processes need to use a resource in turn. There is a tendency for such bursts of activity to drift towards synchronization, which can be disasterous. In Kademlia all nodes are requird to republish their contents every hour (T_REPLICATE). A convoy effect might lead to this being synchronized across the network, which would appear to users as the network dying every hour. The default timeout will be between 0 and 30 minutes unless specified.
Parameters:
Name Type Argument Description
func function Function to wrap to execution later
maxtime number <optional>
Maximum timeout
Source:
Returns:
Type
function

<static> satisfiesDifficulty(buffer, difficulty)

Returns a boolean indicating if the supplied buffer meets the given difficulty requirement
Parameters:
Name Type Description
buffer buffer Buffer to check difficulty
difficulty number Number of leading zeroes
Source:
Returns:
Type
boolean

<static> scrypt(input [, callback])

Returns the Scrypt hash of the input
Parameters:
Name Type Argument Description
input buffer Data to hash
callback function <optional>
Callback including hash value
Source:

<static> toBinaryStringFromBuffer(buffer)

Converts a buffer to a string representation of binary
Parameters:
Name Type Description
buffer buffer Byte array to convert to binary string
Source:
Returns:
Type
string

<static> toExtendedFromPrivateKey(privateKey)

Takes a plain secp256k1 private key and converts it to an HD key - note that the chain code is zeroed out and thus provides no additional security.
Parameters:
Name Type Description
privateKey buffer Raw bytes for the private key
Source:
Returns:
Type
string

<static> toHDKeyFromSeed( [masterSeed] [, derivationPath])

Generates a private key or derives one from the supplied seed
Parameters:
Name Type Argument Description
masterSeed buffer <optional>
64 bytes of data
derivationPath string <optional>
HD key derivation path
Source:
Returns:
Type
object

<static> toPublicKeyHash(publicKey)

Takes a public key are returns the identity
Parameters:
Name Type Description
publicKey buffer Raw public key bytes
Source:
Returns:
Type
buffer

<static> validateLogger(logger)

Validates the given object is a logger
Parameters:
Name Type Description
logger AbstractNode~logger
Source:

<static> validateStorageAdapter(storageAdapter)

Validates the given object is a storage adapter
Parameters:
Name Type Description
storageAdapter AbstractNode~storage
Source:

<static> validateTransport(transport)

Validates the given object is a transport
Parameters:
Name Type Description
transport AbstractNode~transport
Source: