Пример #1
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();
                }
            }
        }
Пример #2
0
        public static BroadcastClue Create(string type, Timestamp creationTime, Clue clue, OmniDigitalSignature digitalSignature)
        {
            var hub = new Hub();

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

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

                return(new BroadcastClue(type, creationTime, clue, certificate));
            }
            finally
            {
                hub.Reset();
            }
        }
Пример #3
0
        public static OmniSignature GetOmniSignature(OmniCertificate certificate)
        {
            if (certificate is null)
            {
                throw new ArgumentNullException(nameof(certificate));
            }
            if (certificate.Name == null)
            {
                throw new ArgumentNullException(nameof(certificate.Name));
            }

            if (certificate.AlgorithmType == OmniDigitalSignatureAlgorithmType.EcDsa_P521_Sha2_256)
            {
                return(new OmniSignature(certificate.Name, CreateOmniHash(certificate.Name, certificate.PublicKey.Span, OmniHashAlgorithmType.Sha2_256)));
            }
            else
            {
                throw new NotSupportedException();
            }
        }
Пример #4
0
 public static bool VerifyOmniCertificate(OmniCertificate certificate, ReadOnlySequence <byte> sequence)
 {
     return(certificate.Verify(sequence));
 }
Пример #5
0
 public static OmniCertificate CreateOmniCertificate(OmniDigitalSignature digitalSignature, ReadOnlySequence <byte> sequence)
 {
     return(OmniCertificate.Create(digitalSignature, sequence));
 }