Ejemplo n.º 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.Sha2_256)
        {
            var target = Hmac_Sha2_256.ComputeHash(sequence, key.Span);

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

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

        await Task.Delay(1, cancellationToken).ConfigureAwait(false);

        if (hashcashAlgorithmType == OmniHashcashAlgorithmType.Sha2_256)
        {
            var target      = Hmac_Sha2_256.ComputeHash(sequence, key.Span);
            var hashcashKey = MinerHelper.Compute_Simple_Sha2_256(target, limit, timeout, cancellationToken);

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

        throw new NotSupportedException(nameof(hashcashAlgorithmType));
    }