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
-
Method Summary
Modifier and TypeMethodDescriptionstatic ProofOfWork
generateProofOfWork
(DrasylAddress address, byte difficulty) static byte
getDifficulty
(ProofOfWork proofOfWork, DrasylAddress publicKey) abstract int
getNonce()
incNonce()
Returns a Proof of Work with nonce incremented by 1.int
intValue()
Returns the value of thisProofOfWork
as anint
.boolean
isValid
(DrasylAddress address, byte difficulty) Checks if the current proof of work is valid for given public key and difficulty.static ProofOfWork
of
(int nonce) static ProofOfWork
toString()
-
Constructor Details
-
ProofOfWork
public ProofOfWork()
-
-
Method Details
-
getNonce
public abstract int getNonce() -
toString
-
intValue
public int intValue()Returns the value of thisProofOfWork
as 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
- ifaddress
isnull
IllegalArgumentException
- 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
- ifnonce
isnull
-
of
- Throws:
IllegalArgumentException
- ifnonce
does not contain a parsable integer.
-
generateProofOfWork
- Throws:
IllegalStateException
- if there is no valid nonce foraddress
at givendifficulty
. In this case a newaddress
should be generated ordifficulty
should be reduced.
-