Exemplo n.º 1
0
        public BlsSignature GetBlockSignature(BeaconBlock block, BlsPublicKey blsPublicKey)
        {
            var fork  = _beaconChainInformation.Fork;
            var epoch = ComputeEpochAtSlot(block.Slot);

            ForkVersion forkVersion;

            if (epoch < fork.Epoch)
            {
                forkVersion = fork.PreviousVersion;
            }
            else
            {
                forkVersion = fork.CurrentVersion;
            }

            var domainType     = _signatureDomainOptions.CurrentValue.BeaconProposer;
            var proposerDomain = ComputeDomain(domainType, forkVersion);

            /*
             * JsonSerializerOptions options = new System.Text.Json.JsonSerializerOptions { WriteIndented = true };
             * options.ConfigureNethermindCore2();
             * string blockJson = System.Text.Json.JsonSerializer.Serialize(block, options);
             */

            var blockRoot   = _cryptographyService.HashTreeRoot(block);
            var signingRoot = ComputeSigningRoot(blockRoot, proposerDomain);

            var signature = _validatorKeyProvider.SignRoot(blsPublicKey, signingRoot);

            return(signature);
        }
Exemplo n.º 2
0
        public async Task <BlsSignature> GetAttestationSignatureAsync(Attestation unsignedAttestation,
                                                                      BlsPublicKey blsPublicKey)
        {
            Fork  fork  = _beaconChainInformation.Fork;
            Epoch epoch = ComputeEpochAtSlot(unsignedAttestation.Data.Slot);

            ForkVersion forkVersion;

            if (epoch < fork.Epoch)
            {
                forkVersion = fork.PreviousVersion;
            }
            else
            {
                forkVersion = fork.CurrentVersion;
            }

            DomainType domainType = _signatureDomainOptions.CurrentValue.BeaconAttester;

            (DomainType domainType, ForkVersion forkVersion)cacheKey = (domainType, forkVersion);
            Domain attesterDomain =
                await _cache.GetOrCreateAsync(cacheKey,
                                              entry => { return(Task.FromResult(ComputeDomain(domainType, forkVersion))); }).ConfigureAwait(false);

            Root attestationDataRoot = _cryptographyService.HashTreeRoot(unsignedAttestation.Data);
            Root signingRoot         = ComputeSigningRoot(attestationDataRoot, attesterDomain);

            BlsSignature signature = _validatorKeyProvider.SignRoot(blsPublicKey, signingRoot);

            return(signature);
        }