Skip to content

Commit

Permalink
implement a simple signer with yui-relayer/signer
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Jun 17, 2024
1 parent 3cd02ae commit 18ab23b
Show file tree
Hide file tree
Showing 14 changed files with 569 additions and 111 deletions.
6 changes: 3 additions & 3 deletions proto/relayer/provers/lcp/config/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ message ProverConfig {
// this only works when operators is not empty
// the value must be less than or equal to 1
Fraction operators_threshold = 13 [(gogoproto.nullable) = false];
// TODO use signer module instead
// hex string
string operator_private_key = 14;
// signer for eip712 commitment
google.protobuf.Any operator_signer = 14;
// eip712 params
oneof operators_eip712_params {
EVMChainEIP712Params operators_evm_chain_eip712_params = 31;
CosmosChainEIP712Params operators_cosmos_chain_eip712_params = 32;
Expand Down
11 changes: 11 additions & 0 deletions proto/relayer/provers/lcp/signers/raw/config.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";
package relayer.provers.lcp.signers.raw;

import "gogoproto/gogo.proto";

option go_package = "github.com/datachainlab/lcp-go/relay/signers/raw";
option (gogoproto.goproto_getters_all) = false;

message SignerConfig {
string private_key = 1;
}
2 changes: 2 additions & 0 deletions relay/bin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"log"

lcp "github.com/datachainlab/lcp-go/relay"
"github.com/datachainlab/lcp-go/relay/signers/raw"
lcptm "github.com/datachainlab/lcp-go/relay/tendermint"
tendermint "github.com/hyperledger-labs/yui-relayer/chains/tendermint/module"
"github.com/hyperledger-labs/yui-relayer/cmd"
Expand All @@ -14,6 +15,7 @@ func main() {
tendermint.Module{},
lcp.Module{},
lcptm.Module{},
raw.Module{},
); err != nil {
log.Fatal(err)
}
Expand Down
20 changes: 14 additions & 6 deletions relay/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
lcptypes "github.com/datachainlab/lcp-go/light-clients/lcp/types"
"github.com/ethereum/go-ethereum/common"
"github.com/hyperledger-labs/yui-relayer/core"
"github.com/hyperledger-labs/yui-relayer/signer"
)

const (
Expand Down Expand Up @@ -48,6 +49,11 @@ func (cfg *ProverConfig) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error
if err := unpacker.UnpackAny(cfg.OriginProver, new(core.ProverConfig)); err != nil {
return err
}
if cfg.OperatorSigner != nil {
if err := unpacker.UnpackAny(cfg.OperatorSigner, new(signer.SignerConfig)); err != nil {
return err
}
}
return nil
}

Expand Down Expand Up @@ -121,8 +127,14 @@ func (pc ProverConfig) Validate() error {
return fmt.Errorf("Operators: currently only one or zero(=permissionless) operator is supported, but got %v", l)
}
if pc.OperatorsEip712Params != nil {
if len(pc.OperatorPrivateKey) == 0 {
return fmt.Errorf("OperatorPrivateKey must be set if OperatorsEip712Salt is set")
if pc.OperatorSigner == nil {
return fmt.Errorf("OperatorSigner must be set if OperatorsEip712Params is set")
}
signerConfig, ok := pc.OperatorSigner.GetCachedValue().(signer.SignerConfig)
if !ok {
return fmt.Errorf("failed to cast OperatorSigner's config: %T", pc.OperatorSigner.GetCachedValue())
} else if err := signerConfig.Validate(); err != nil {
return fmt.Errorf("failed to validate the OperatorSigner's config: %v", err)
}
switch salt := pc.OperatorsEip712Params.(type) {
case *ProverConfig_OperatorsEvmChainEip712Params:
Expand All @@ -146,10 +158,6 @@ func (pc ProverConfig) Validate() error {
return nil
}

func (f Fraction) String() string {
return fmt.Sprintf("%v/%v", f.Numerator, f.Denominator)
}

func decodeMrenclaveHex(s string) ([]byte, error) {
trimmed := strings.ToLower(strings.TrimPrefix(s, "0x"))
bz, err := hex.DecodeString(trimmed)
Expand Down
141 changes: 75 additions & 66 deletions relay/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion relay/lcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (pr *Prover) registerEnclaveKey(verifier core.Chain, eki *enclave.EnclaveKe
if err != nil {
return nil, err
}
sig, err := pr.OperatorSign(commitment)
sig, err := pr.eip712Signer.Sign(commitment)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 18ab23b

Please sign in to comment.