Package org.drasyl.identity
Class ProofOfWork
- java.lang.Object
-
- org.drasyl.identity.ProofOfWork
-
public abstract 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.
-
-
Constructor Summary
Constructors Constructor Description ProofOfWork()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static ProofOfWork
generateProofOfWork(Key publicKey, byte difficulty)
static byte
getDifficulty(ProofOfWork proofOfWork, IdentityPublicKey publicKey)
abstract int
getNonce()
ProofOfWork
incNonce()
int
intValue()
Returns the value of thisProofOfWork
as anint
.boolean
isValid(Key publicKey, byte difficulty)
Checks if the current proof of work is valid for given public key and difficulty.static ProofOfWork
of(int nonce)
-
-
-
Method Detail
-
getNonce
public abstract int getNonce()
-
intValue
public int intValue()
Returns the value of thisProofOfWork
as anint
.
-
isValid
public boolean isValid(Key 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
, otherwisefalse
- Throws:
IllegalArgumentException
- if the difficulty is not in between [0,64]
-
getDifficulty
public static byte getDifficulty(ProofOfWork proofOfWork, IdentityPublicKey publicKey)
-
incNonce
public ProofOfWork incNonce()
-
of
public static ProofOfWork of(int nonce)
-
generateProofOfWork
public static ProofOfWork generateProofOfWork(Key publicKey, byte difficulty)
-
-