trySolveChallenge static method

int? trySolveChallenge(
  1. ChallengeInfo challengeInfo, [
  2. int startNonce = 0,
  3. int? endNonceExclusive
])

Implementation

static int? trySolveChallenge(ChallengeInfo challengeInfo, [int startNonce = 0, int? endNonceExclusive]){
  int nonce = startNonce;
  String result = "";

  while(endNonceExclusive == null || nonce < endNonceExclusive){
    result = challengeInfo.challengeAlgorithm.hashToHexFunc(challengeInfo.token + ':' + nonce.toRadixString(16));
    if(ChallengeAlgorithm.hexStringCompliesWithComplexity(result, challengeInfo.complexity)){
      return nonce;
    }
    nonce++;
  }
  return null;
}