From ce268be2ee75eb8c9aff3ce66ad837e6a1e4bc17 Mon Sep 17 00:00:00 2001 From: iurii Date: Fri, 7 Mar 2025 10:54:52 +0200 Subject: [PATCH] preconfs: preconf-commitment duty --- signer/sign_preconf_commitment.go | 34 +++++++++++++++++++++++++++++++ signer/validator_signer.go | 1 + 2 files changed, 35 insertions(+) create mode 100644 signer/sign_preconf_commitment.go diff --git a/signer/sign_preconf_commitment.go b/signer/sign_preconf_commitment.go new file mode 100644 index 00000000..15816600 --- /dev/null +++ b/signer/sign_preconf_commitment.go @@ -0,0 +1,34 @@ +package signer + +import ( + "encoding/hex" + + "github.com/attestantio/go-eth2-client/spec/phase0" + "github.com/pkg/errors" +) + +// TODO - add test(s) +// SignSlot signes the given preconf-commitment data +func (signer *SimpleSigner) SignPreconfCommitment(data []byte, domain phase0.Domain, pubKey []byte) ([]byte, []byte, error) { + if pubKey == nil { + return nil, nil, errors.New("account was not supplied") + } + + account, err := signer.wallet.AccountByPublicKey(hex.EncodeToString(pubKey)) + if err != nil { + return nil, nil, err + } + + sszRoot := SSZBytes(data) + root, err := ComputeETHSigningRoot(sszRoot, domain) + if err != nil { + return nil, nil, err + } + + sig, err := account.ValidationKeySign(root[:]) + if err != nil { + return nil, nil, err + } + + return sig, root[:], nil +} diff --git a/signer/validator_signer.go b/signer/validator_signer.go index f0df3443..d48f0a19 100644 --- a/signer/validator_signer.go +++ b/signer/validator_signer.go @@ -28,6 +28,7 @@ type ValidatorSigner interface { SignRegistration(registration *api.VersionedValidatorRegistration, domain phase0.Domain, pubKey []byte) (sig []byte, root []byte, err error) SignVoluntaryExit(voluntaryExit *phase0.VoluntaryExit, domain phase0.Domain, pubKey []byte) (sig []byte, root []byte, err error) SignBLSToExecutionChange(blsToExecutionChange *capella.BLSToExecutionChange, domain phase0.Domain, pubKey []byte) (sig []byte, root []byte, err error) + SignPreconfCommitment(data []byte, domain phase0.Domain, pubKey []byte) (sig []byte, root []byte, err error) } // SimpleSigner implements ValidatorSigner interface