Package org.drasyl.identity
Class ProofOfWork
- java.lang.Object
-
- org.drasyl.identity.ProofOfWork
-
public class ProofOfWork extends Object
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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
static ProofOfWork
generateProofOfWork(CompressedPublicKey publicKey, byte difficulty)
static byte
getDifficulty(ProofOfWork proofOfWork, CompressedPublicKey publicKey)
int
getNonce()
int
hashCode()
void
incNonce()
int
intValue()
Returns the value of thisProofOfWork
as anint
.boolean
isValid(CompressedPublicKey publicKey, byte difficulty)
Checks if the current proof of work is valid for given public key and difficulty.static ProofOfWork
of(int nonce)
String
toString()
-
-
-
Method Detail
-
getNonce
public int getNonce()
-
intValue
public int intValue()
Returns the value of thisProofOfWork
as anint
.
-
of
public static ProofOfWork of(int nonce)
-
generateProofOfWork
public static ProofOfWork generateProofOfWork(CompressedPublicKey publicKey, byte difficulty)
-
isValid
public boolean isValid(CompressedPublicKey publicKey, byte difficulty)
Checks if the current proof of work is valid for given public key and difficulty.- Parameters:
publicKey
- the public keydifficulty
- the difficulty- Returns:
- if valid true, otherwise false
- Throws:
IllegalArgumentException
- if the difficulty is not in between [0,64]
-
getDifficulty
public static byte getDifficulty(ProofOfWork proofOfWork, CompressedPublicKey publicKey)
-
incNonce
public void incNonce()
-
-