Пример #1
0
        public static ForkVersion DecodeForkVersion(ReadOnlySpan <byte> span, ref int offset)
        {
            ForkVersion forkVersion = new ForkVersion(span.Slice(offset, ForkVersionLength));

            offset += ForkVersionLength;
            return(forkVersion);
        }
Пример #2
0
 /// <summary>
 /// Returns the domain for the 'domain_type' and 'fork_version'
 /// </summary>
 public Domain ComputeDomain(DomainType domainType, ForkVersion forkVersion = new ForkVersion())
 {
     Span<byte> combined = stackalloc byte[Domain.Length];
     domainType.AsSpan().CopyTo(combined);
     forkVersion.AsSpan().CopyTo(combined.Slice(DomainType.Length));
     return new Domain(combined);
 }
Пример #3
0
        public static ForkVersion DecodeForkVersion(Span <byte> span, ref int offset)
        {
            ForkVersion forkVersion = new ForkVersion(BinaryPrimitives.ReadUInt32LittleEndian(span.Slice(offset)));

            offset += ForkVersion.SszLength;
            return(forkVersion);
        }
Пример #4
0
        /// <summary>
        /// Returns the domain for the 'domain_type' and 'fork_version'
        /// </summary>
        public Domain ComputeDomain(DomainType domainType, ForkVersion forkVersion = new ForkVersion())
        {
            Span <byte> combined = new Span <byte>(new byte[Domain.Length]);

            BinaryPrimitives.WriteUInt32LittleEndian(combined, (uint)domainType);
            forkVersion.AsSpan().CopyTo(combined.Slice(sizeof(DomainType)));
            return(new Domain(combined));
        }
Пример #5
0
        /// <summary>
        /// Returns the domain for the 'domain_type' and 'fork_version'
        /// </summary>
        public Domain ComputeDomain(DomainType domainType, ForkVersion forkVersion = new ForkVersion())
        {
            var combined = new Span <byte>(new byte[Domain.Length]);

            domainType.AsSpan().CopyTo(combined);
            forkVersion.AsSpan().CopyTo(combined.Slice(DomainType.Length));
            return(new Domain(combined));
        }
Пример #6
0
 public PeeringStatus(ForkVersion headForkVersion, Root finalizedRoot, Epoch finalizedEpoch, Root headRoot,
                      Slot headSlot)
 {
     HeadForkVersion = headForkVersion;
     FinalizedRoot   = finalizedRoot;
     FinalizedEpoch  = finalizedEpoch;
     HeadRoot        = headRoot;
     HeadSlot        = headSlot;
 }
Пример #7
0
        private ApplicationManager()
        {
            ResourceManager rm = Resources.ResourceManager;

            CurrentForkVersion = new ForkVersion
            {
                Major = int.Parse(rm.GetString("VersionMajor")),
                Minor = int.Parse(rm.GetString("VersionMinor")),
                Patch = int.Parse(rm.GetString("VersionPatch"))
            };
        }
Пример #8
0
        public static Fork DecodeFork(Span <byte> span)
        {
            if (span.Length != Fork.SszLength)
            {
                ThrowSourceLength <Fork>(span.Length, Fork.SszLength);
            }
            int         offset   = 0;
            ForkVersion previous = DecodeForkVersion(span, ref offset);
            ForkVersion current  = DecodeForkVersion(span, ref offset);
            Epoch       epoch    = DecodeEpoch(span, ref offset);

            return(new Fork(previous, current, epoch));
        }
Пример #9
0
        private ApplicationManager()
        {
            ResourceManager rm = Resources.ResourceManager;

            CurrentForkVersion = new ForkVersion
            {
                Major = int.Parse(rm.GetString("VersionMajor")),
                Minor = int.Parse(rm.GetString("VersionMinor")),
                Patch = int.Parse(rm.GetString("VersionPatch")),
                Beta  = int.Parse(rm.GetString("VersionBeta"))
            };
            DiscordRichPresenceUtils.SetupRichPresence();
        }
Пример #10
0
        public static PeeringStatus DecodePeeringStatus(ReadOnlySpan <byte> span)
        {
            if (span.Length != PeeringStatusLength)
            {
                ThrowSourceLength <PeeringStatus>(span.Length, PeeringStatusLength);
            }
            int         offset          = 0;
            ForkVersion headForkVersion = DecodeForkVersion(span, ref offset);
            Root        finalizedRoot   = DecodeRoot(span, ref offset);
            Epoch       finalizedEpoch  = DecodeEpoch(span, ref offset);
            Root        headRoot        = DecodeRoot(span, ref offset);
            Slot        headSlot        = DecodeSlot(span, ref offset);

            return(new PeeringStatus(headForkVersion, finalizedRoot, finalizedEpoch, headRoot, headSlot));
        }
Пример #11
0
        private BlsSignature GetEpochSignature(IServiceProvider testServiceProvider, byte[] privateKey, ForkVersion forkVersion, Slot slot)
        {
            SignatureDomains   signatureDomains   = testServiceProvider.GetService <IOptions <SignatureDomains> >().Value;
            BeaconChainUtility beaconChainUtility = testServiceProvider.GetService <BeaconChainUtility>();
            var domain = beaconChainUtility.ComputeDomain(signatureDomains.Randao, forkVersion);

            var epoch = beaconChainUtility.ComputeEpochAtSlot(slot);

            var epochRoot        = epoch.HashTreeRoot();
            var epochSigningRoot = beaconChainUtility.ComputeSigningRoot(epochRoot, domain);

            BLSParameters parameters = new BLSParameters()
            {
                PrivateKey = privateKey
            };
            BLS bls         = BLS.Create(parameters);
            var destination = new Span <byte>(new byte[96]);

            bls.TrySignData(epochSigningRoot.AsSpan(), destination, out var bytesWritten);

            var signature = new BlsSignature(destination.ToArray());

            return(signature);
        }
Пример #12
0
 public Fork(ForkVersion previousVersion, ForkVersion currentVersion, Epoch epoch)
 {
     PreviousVersion = previousVersion;
     CurrentVersion  = currentVersion;
     Epoch           = epoch;
 }
Пример #13
0
 public static SszElement ToSszBasicVector(this ForkVersion item)
 {
     return(new SszBasicVector(item.AsSpan()));
 }
Пример #14
0
 private static void Encode(Span <byte> span, ForkVersion value, ref int offset)
 {
     // FIXME: ForkVersion can be created by marshalling a span onto it, with no guarantee the underlying architecture is little endian.
     value.AsSpan().CopyTo(span.Slice(offset, ForkVersionLength));
     offset += ForkVersionLength;
 }
Пример #15
0
 public static void Encode(Span <byte> span, ForkVersion value)
 {
     value.AsSpan().CopyTo(span);
 }
Пример #16
0
 private static void Encode(Span <byte> span, ForkVersion value, ref int offset)
 {
     BinaryPrimitives.WriteUInt32LittleEndian(span.Slice(offset), value.Number);
     offset += ForkVersion.SszLength;
 }
Пример #17
0
 public static void Encode(Span <byte> span, ForkVersion value)
 {
     Encode(span, value.Number);
 }