Package org.drasyl.identity
Class ProofOfWork
java.lang.Object
org.drasyl.identity.ProofOfWork
This class models the proof of work for a given public key. Hence, identity creation becomes an
expensive operation and sybil attacks should be made more difficult.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ProofOfWorkgenerateProofOfWork(DrasylAddress address, byte difficulty) static bytegetDifficulty(ProofOfWork proofOfWork, DrasylAddress publicKey) abstract intgetNonce()incNonce()Returns a Proof of Work with nonce incremented by 1.intintValue()Returns the value of thisProofOfWorkas anint.booleanisValid(DrasylAddress address, byte difficulty) Checks if the current proof of work is valid for given public key and difficulty.static ProofOfWorkof(int nonce) static ProofOfWorktoString()
-
Constructor Details
-
ProofOfWork
public ProofOfWork()
-
-
Method Details
-
getNonce
public abstract int getNonce() -
toString
-
intValue
public int intValue()Returns the value of thisProofOfWorkas anint. -
isValid
Checks if the current proof of work is valid for given public key and difficulty.- Parameters:
address- the public keydifficulty- the difficulty- Returns:
- if valid
true, otherwisefalse - Throws:
NullPointerException- ifaddressisnullIllegalArgumentException- if the difficulty is not in between [0,64]
-
getDifficulty
-
incNonce
Returns a Proof of Work with nonce incremented by 1.- Returns:
- a Proof of Work with nonce incremented by 1
- Throws:
IllegalStateException- if incrementing would lead to an overflow of the nonce
-
of
- Throws:
NullPointerException- ifnonceisnull
-
of
- Throws:
IllegalArgumentException- ifnoncedoes not contain a parsable integer.
-
generateProofOfWork
- Throws:
IllegalStateException- if there is no valid nonce foraddressat givendifficulty. In this case a newaddressshould be generated ordifficultyshould be reduced.
-