Exemple #1
0
        public static uint Verify(OmniHashcash hashcash, ReadOnlySequence <byte> sequence, ReadOnlyMemory <byte> key)
        {
            if (hashcash is null)
            {
                throw new ArgumentNullException(nameof(hashcash));
            }

            if (hashcash.AlgorithmType == OmniHashcashAlgorithmType.Simple_Sha2_256)
            {
                var target = Hmac_Sha2_256.ComputeHash(sequence, key.Span);

                return(MinerHelper.Verify_Simple_Sha2_256(hashcash.Key.Span, target));
            }

            return(0);
        }
Exemple #2
0
        public static async ValueTask <OmniHashcash> Create(ReadOnlySequence <byte> sequence, ReadOnlyMemory <byte> key, OmniHashcashAlgorithmType hashcashAlgorithmType, int limit, TimeSpan timeout, CancellationToken token)
        {
            if (!EnumHelper.IsValid(hashcashAlgorithmType))
            {
                throw new ArgumentException(nameof(OmniHashcashAlgorithmType));
            }

            return(await Task.Run(() =>
            {
                if (hashcashAlgorithmType == OmniHashcashAlgorithmType.Simple_Sha2_256)
                {
                    var target = Hmac_Sha2_256.ComputeHash(sequence, key.Span);
                    var hashcashKey = MinerHelper.Compute_Simple_Sha2_256(target, limit, timeout, token);

                    return new OmniHashcash(OmniHashcashAlgorithmType.Simple_Sha2_256, hashcashKey);
                }

                throw new NotSupportedException(nameof(hashcashAlgorithmType));
            }, token));
        }