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 Details

    • ProofOfWork

      public ProofOfWork()
  • Method Details

    • getNonce

      public abstract int getNonce()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • intValue

      public int intValue()
      Returns the value of this ProofOfWork as an int.
    • isValid

      public boolean isValid(DrasylAddress address, byte difficulty)
      Checks if the current proof of work is valid for given public key and difficulty.
      Parameters:
      address - the public key
      difficulty - the difficulty
      Returns:
      if valid true, otherwise false
      Throws:
      NullPointerException - if address is null
      IllegalArgumentException - if the difficulty is not in between [0,64]
    • getDifficulty

      public static byte getDifficulty(ProofOfWork proofOfWork, DrasylAddress publicKey)
    • incNonce

      public ProofOfWork 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

      public static ProofOfWork of(int nonce)
      Throws:
      NullPointerException - if nonce is null
    • of

      public static ProofOfWork of(String nonce)
      Throws:
      IllegalArgumentException - if nonce does not contain a parsable integer.
    • generateProofOfWork

      public static ProofOfWork generateProofOfWork(DrasylAddress address, byte difficulty)
      Throws:
      IllegalStateException - if there is no valid nonce for address at given difficulty. In this case a new address should be generated or difficulty should be reduced.