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> eqsolve(input)

Performs an equihash solution using defaults
Parameters:
Name Type Description
input buffer Input hash to solve
Source:
Returns:
Type
Promise.<EquihashProof>

<static> eqverify(input, proof)

Perform an equihash proof verification
Parameters:
Name Type Description
input buffer Input hash for proof
proof buffer Equihash proof to verify
Source:
Returns:
Type
boolean

<static> generatePrivateKey()

Generates a private key
Source:
Returns:
Type
buffer

<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> isHexaString(str)

Tests if a string is valid hex
Parameters:
Name Type Description
str string
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> 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> 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> 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> 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:

Type Definitions


EquihashProof

Type:
  • object
Properties:
Name Type Description
n number
k number
nonce number
value buffer
Source: