/// <summary> /// Computes the commitment Hash /// </summary> /// <param name="commitment">Commitment the commitment as a byte array.</param> /// <returns>Commitment hash as a byte array</returns> public virtual byte[] ComputeCommitmentHash(byte[] commitment) { Guard.NotNull(commitment, nameof(commitment)); Guard.NotLessThanOrEqualTo(commitment.Length, 0, nameof(commitment)); return(Digests.Sha256(commitment)); }
/// <summary> /// Verifies the commitmentHash is resulted from commitment /// </summary> /// <param name="commitment">Commitment as a byte array</param> /// <param name="commitmentHash">CommitmentHash the commitment hash as a byte array</param> /// <returns>true if commitmentHash is the Hash of commitment, false otherwise</returns> public bool ValidateCommitment(byte[] commitment, byte[] commitmentHash) { Guard.NotNull(commitment, nameof(commitment)); Guard.NotLessThanOrEqualTo(commitment.Length, 0, nameof(commitment)); Guard.NotNull(commitmentHash, nameof(commitmentHash)); Guard.NotLessThanOrEqualTo(commitmentHash.Length, 0, nameof(commitmentHash)); var computedHash = Digests.Sha256(commitment); return(computedHash.SequenceEqual(commitmentHash)); }