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.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 <MulticastClue> Create(string type, Channel channel, Timestamp creationTime, Clue clue, OmniDigitalSignature digitalSignature, int miningLimit, TimeSpan miningTimeout, CancellationToken token)
        {
            OmniHashcash hashcash = null;
            {
                var hub = new Hub();

                try
                {
                    var target = new MulticastClue(type, channel, creationTime, clue, null, null);
                    target.Export(hub.Writer, BufferPool.Shared);
                    hub.Writer.Complete();

                    hashcash = await OmniMiner.Create(hub.Reader.GetSequence(), _utf8Encoding.Value.GetBytes(digitalSignature.GetOmniSignature().ToString()), OmniHashcashAlgorithmType.Sha2_256, miningLimit, miningTimeout, token);

                    hub.Reader.Complete();
                }
                finally
                {
                    hub.Reset();
                }
            }

            {
                var hub = new Hub();

                try
                {
                    var target = new MulticastClue(type, channel, creationTime, clue, hashcash, null);
                    target.Export(hub.Writer, BufferPool.Shared);
                    hub.Writer.Complete();

                    var certificate = OmniCertificate.Create(digitalSignature, hub.Reader.GetSequence());
                    hub.Reader.Complete();

                    return(new MulticastClue(type, channel, creationTime, clue, hashcash, certificate));
                }
                finally
                {
                    hub.Reset();
                }
            }
        }