diff --git a/CHANGELOG.md b/CHANGELOG.md index 380d28fc..6da76533 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## Unreleased +### Bug Fixes + +* [#244](https://github.com/babylonlabs-io/finality-provider/pull/244) fix: save key name mapping +verifies if there is a eots client running + ## v0.14.1 ### Bug Fixes diff --git a/eotsmanager/client/rpcclient.go b/eotsmanager/client/rpcclient.go index c306e830..10866cac 100644 --- a/eotsmanager/client/rpcclient.go +++ b/eotsmanager/client/rpcclient.go @@ -83,6 +83,15 @@ func (c *EOTSManagerGRpcClient) CreateRandomnessPairList(uid, chainID []byte, st return pubRandFieldValList, nil } +func (c *EOTSManagerGRpcClient) SaveEOTSKeyName(pk *btcec.PublicKey, keyName string) error { + req := &proto.SaveEOTSKeyNameRequest{ + KeyName: keyName, + EotsPk: pk.SerializeUncompressed(), + } + _, err := c.client.SaveEOTSKeyName(context.Background(), req) + return err +} + func (c *EOTSManagerGRpcClient) KeyRecord(uid []byte, passphrase string) (*types.KeyRecord, error) { req := &proto.KeyRecordRequest{Uid: uid, Passphrase: passphrase} diff --git a/eotsmanager/cmd/eotsd/daemon/flags.go b/eotsmanager/cmd/eotsd/daemon/flags.go index 81d907b1..b5e7a2ba 100644 --- a/eotsmanager/cmd/eotsd/daemon/flags.go +++ b/eotsmanager/cmd/eotsd/daemon/flags.go @@ -3,6 +3,7 @@ package daemon const ( forceFlag = "force" rpcListenerFlag = "rpc-listener" + rpcClientFlag = "rpc-client" flagInteractive = "interactive" flagNoBackup = "no-backup" flagMultisig = "multisig" diff --git a/eotsmanager/cmd/eotsd/daemon/keys.go b/eotsmanager/cmd/eotsd/daemon/keys.go index 5d61d138..c550d216 100644 --- a/eotsmanager/cmd/eotsd/daemon/keys.go +++ b/eotsmanager/cmd/eotsd/daemon/keys.go @@ -5,11 +5,13 @@ import ( "encoding/json" "fmt" "io" + "strings" "github.com/btcsuite/btcd/btcec/v2/schnorr" "github.com/babylonlabs-io/babylon/types" "github.com/babylonlabs-io/finality-provider/eotsmanager" + eotsclient "github.com/babylonlabs-io/finality-provider/eotsmanager/client" "github.com/babylonlabs-io/finality-provider/eotsmanager/config" "github.com/babylonlabs-io/finality-provider/log" "github.com/babylonlabs-io/finality-provider/util" @@ -35,6 +37,8 @@ func NewKeysCmd() *cobra.Command { panic("failed to find keys add command") } + addCmd.Flags().String(rpcClientFlag, "", "The RPC address of a running eotsd to connect and save new key") + // Override the original RunE function to run almost the same as // the sdk, but it allows empty hd path and allow to save the key // in the name mapping @@ -73,6 +77,8 @@ func saveKeyOnPostRun(cmd *cobra.Command, commandName string) { panic(fmt.Sprintf("failed to find keys %s command", commandName)) } + subCmd.Flags().String(rpcClientFlag, "", "The RPC address of a running eotsd to connect and save new key") + subCmd.PostRunE = func(cmd *cobra.Command, args []string) error { keyName := args[0] _, err := saveKeyNameMapping(cmd, keyName) @@ -92,6 +98,34 @@ func saveKeyNameMapping(cmd *cobra.Command, keyName string) (*types.BIP340PubKey return nil, fmt.Errorf("failed to load config: %w", err) } + rpcListener, err := cmd.Flags().GetString(rpcClientFlag) + if err != nil { + return nil, err + } + + if len(rpcListener) > 0 { + client, err := eotsclient.NewEOTSManagerGRpcClient(rpcListener) + if err != nil { + return nil, err + } + + kr, err := eotsmanager.InitKeyring(clientCtx.HomeDir, clientCtx.Keyring.Backend(), strings.NewReader("")) + if err != nil { + return nil, fmt.Errorf("failed to init keyring: %w", err) + } + + eotsPk, err := eotsmanager.LoadBIP340PubKeyFromKeyName(kr, keyName) + if err != nil { + return nil, fmt.Errorf("failed to get public key for key %s: %w", keyName, err) + } + + if err := client.SaveEOTSKeyName(eotsPk.MustToBTCPK(), keyName); err != nil { + return nil, fmt.Errorf("failed to save key name mapping: %w", err) + } + + return eotsPk, nil + } + // Setup logger logger, err := log.NewRootLoggerWithFile(config.LogFile(clientCtx.HomeDir), cfg.LogLevel) if err != nil { diff --git a/eotsmanager/eotsmanager.go b/eotsmanager/eotsmanager.go index 017bd941..aa4537bc 100644 --- a/eotsmanager/eotsmanager.go +++ b/eotsmanager/eotsmanager.go @@ -42,5 +42,8 @@ type EOTSManager interface { // or passPhrase is incorrect SignSchnorrSig(uid []byte, msg []byte, passphrase string) (*schnorr.Signature, error) + // SaveEOTSKeyName saves a new key under the EOTS key name mapping + SaveEOTSKeyName(pk *btcec.PublicKey, keyName string) error + Close() error } diff --git a/eotsmanager/localmanager.go b/eotsmanager/localmanager.go index 28ba6b36..afe5b970 100644 --- a/eotsmanager/localmanager.go +++ b/eotsmanager/localmanager.go @@ -50,7 +50,7 @@ func NewLocalEOTSManager(homeDir, keyringBackend string, dbbackend kvdb.Backend, return nil, fmt.Errorf("failed to initialize store: %w", err) } - kr, err := initKeyring(homeDir, keyringBackend, inputReader) + kr, err := InitKeyring(homeDir, keyringBackend, inputReader) if err != nil { return nil, fmt.Errorf("failed to initialize keyring: %w", err) } @@ -66,7 +66,7 @@ func NewLocalEOTSManager(homeDir, keyringBackend string, dbbackend kvdb.Backend, }, nil } -func initKeyring(homeDir, keyringBackend string, inputReader *strings.Reader) (keyring.Keyring, error) { +func InitKeyring(homeDir, keyringBackend string, inputReader *strings.Reader) (keyring.Keyring, error) { return keyring.New( "eots-manager", keyringBackend, @@ -149,7 +149,11 @@ func (lm *LocalEOTSManager) SaveEOTSKeyName(pk *btcec.PublicKey, keyName string) } func (lm *LocalEOTSManager) LoadBIP340PubKeyFromKeyName(keyName string) (*bbntypes.BIP340PubKey, error) { - info, err := lm.kr.Key(keyName) + return LoadBIP340PubKeyFromKeyName(lm.kr, keyName) +} + +func LoadBIP340PubKeyFromKeyName(kr keyring.Keyring, keyName string) (*bbntypes.BIP340PubKey, error) { + info, err := kr.Key(keyName) if err != nil { return nil, fmt.Errorf("failed to load keyring record for key %s: %w", keyName, err) } diff --git a/eotsmanager/proto/eotsmanager.pb.go b/eotsmanager/proto/eotsmanager.pb.go index d1fa3a55..1207629d 100644 --- a/eotsmanager/proto/eotsmanager.pb.go +++ b/eotsmanager/proto/eotsmanager.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: eotsmanager.proto @@ -702,6 +702,102 @@ func (x *SignSchnorrSigResponse) GetSig() []byte { return nil } +type SaveEOTSKeyNameRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // KeyName is the name of the key which corresponds to the + // BIP340 public key + KeyName string `protobuf:"bytes,1,opt,name=key_name,json=keyName,proto3" json:"key_name,omitempty"` + // EotsPK is the public key of the EOTS key BIP340PubKey + EotsPk []byte `protobuf:"bytes,2,opt,name=eots_pk,json=eotsPk,proto3" json:"eots_pk,omitempty"` +} + +func (x *SaveEOTSKeyNameRequest) Reset() { + *x = SaveEOTSKeyNameRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_eotsmanager_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SaveEOTSKeyNameRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SaveEOTSKeyNameRequest) ProtoMessage() {} + +func (x *SaveEOTSKeyNameRequest) ProtoReflect() protoreflect.Message { + mi := &file_eotsmanager_proto_msgTypes[12] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SaveEOTSKeyNameRequest.ProtoReflect.Descriptor instead. +func (*SaveEOTSKeyNameRequest) Descriptor() ([]byte, []int) { + return file_eotsmanager_proto_rawDescGZIP(), []int{12} +} + +func (x *SaveEOTSKeyNameRequest) GetKeyName() string { + if x != nil { + return x.KeyName + } + return "" +} + +func (x *SaveEOTSKeyNameRequest) GetEotsPk() []byte { + if x != nil { + return x.EotsPk + } + return nil +} + +type SaveEOTSKeyNameResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *SaveEOTSKeyNameResponse) Reset() { + *x = SaveEOTSKeyNameResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_eotsmanager_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SaveEOTSKeyNameResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SaveEOTSKeyNameResponse) ProtoMessage() {} + +func (x *SaveEOTSKeyNameResponse) ProtoReflect() protoreflect.Message { + mi := &file_eotsmanager_proto_msgTypes[13] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SaveEOTSKeyNameResponse.ProtoReflect.Descriptor instead. +func (*SaveEOTSKeyNameResponse) Descriptor() ([]byte, []int) { + return file_eotsmanager_proto_rawDescGZIP(), []int{13} +} + var File_eotsmanager_proto protoreflect.FileDescriptor var file_eotsmanager_proto_rawDesc = []byte{ @@ -760,43 +856,55 @@ var file_eotsmanager_proto_rawDesc = []byte{ 0x0a, 0x70, 0x61, 0x73, 0x73, 0x70, 0x68, 0x72, 0x61, 0x73, 0x65, 0x22, 0x2a, 0x0a, 0x16, 0x53, 0x69, 0x67, 0x6e, 0x53, 0x63, 0x68, 0x6e, 0x6f, 0x72, 0x72, 0x53, 0x69, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x69, 0x67, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x03, 0x73, 0x69, 0x67, 0x32, 0xfa, 0x03, 0x0a, 0x0b, 0x45, 0x4f, 0x54, 0x53, - 0x4d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x12, 0x2f, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, - 0x12, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x69, 0x6e, 0x67, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3e, 0x0a, 0x09, 0x43, 0x72, 0x65, 0x61, - 0x74, 0x65, 0x4b, 0x65, 0x79, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, + 0x28, 0x0c, 0x52, 0x03, 0x73, 0x69, 0x67, 0x22, 0x4c, 0x0a, 0x16, 0x53, 0x61, 0x76, 0x65, 0x45, + 0x4f, 0x54, 0x53, 0x4b, 0x65, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x19, 0x0a, 0x08, 0x6b, 0x65, 0x79, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x6b, 0x65, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, + 0x65, 0x6f, 0x74, 0x73, 0x5f, 0x70, 0x6b, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x65, + 0x6f, 0x74, 0x73, 0x50, 0x6b, 0x22, 0x19, 0x0a, 0x17, 0x53, 0x61, 0x76, 0x65, 0x45, 0x4f, 0x54, + 0x53, 0x4b, 0x65, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x32, 0xcc, 0x04, 0x0a, 0x0b, 0x45, 0x4f, 0x54, 0x53, 0x4d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, + 0x12, 0x2f, 0x0a, 0x04, 0x50, 0x69, 0x6e, 0x67, 0x12, 0x12, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x3e, 0x0a, 0x09, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x18, 0x43, 0x72, 0x65, 0x61, - 0x74, 0x65, 0x52, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x6e, 0x65, 0x73, 0x73, 0x50, 0x61, 0x69, 0x72, - 0x4c, 0x69, 0x73, 0x74, 0x12, 0x26, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x72, 0x65, - 0x61, 0x74, 0x65, 0x52, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x6e, 0x65, 0x73, 0x73, 0x50, 0x61, 0x69, - 0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x61, 0x6e, 0x64, 0x6f, - 0x6d, 0x6e, 0x65, 0x73, 0x73, 0x50, 0x61, 0x69, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3e, 0x0a, 0x09, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x63, 0x6f, - 0x72, 0x64, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4b, 0x65, 0x79, 0x52, 0x65, - 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x08, 0x53, 0x69, 0x67, 0x6e, 0x45, 0x4f, 0x54, - 0x53, 0x12, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x45, 0x4f, - 0x54, 0x53, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x45, 0x4f, 0x54, 0x53, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0e, 0x55, 0x6e, 0x73, 0x61, 0x66, 0x65, 0x53, 0x69, 0x67, 0x6e, - 0x45, 0x4f, 0x54, 0x53, 0x12, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x69, 0x67, - 0x6e, 0x45, 0x4f, 0x54, 0x53, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x45, 0x4f, 0x54, 0x53, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4d, 0x0a, 0x0e, 0x53, 0x69, 0x67, 0x6e, 0x53, 0x63, 0x68, - 0x6e, 0x6f, 0x72, 0x72, 0x53, 0x69, 0x67, 0x12, 0x1c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, - 0x53, 0x69, 0x67, 0x6e, 0x53, 0x63, 0x68, 0x6e, 0x6f, 0x72, 0x72, 0x53, 0x69, 0x67, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x69, - 0x67, 0x6e, 0x53, 0x63, 0x68, 0x6e, 0x6f, 0x72, 0x72, 0x53, 0x69, 0x67, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3f, 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x62, 0x61, 0x62, 0x79, 0x6c, 0x6f, 0x6e, 0x6c, 0x61, 0x62, 0x73, 0x2d, 0x69, - 0x6f, 0x2f, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x74, 0x79, 0x2d, 0x70, 0x72, 0x6f, 0x76, 0x69, - 0x64, 0x65, 0x72, 0x2f, 0x65, 0x6f, 0x74, 0x73, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2f, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, + 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x6b, 0x0a, 0x18, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x61, 0x6e, 0x64, 0x6f, + 0x6d, 0x6e, 0x65, 0x73, 0x73, 0x50, 0x61, 0x69, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x26, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x61, 0x6e, 0x64, + 0x6f, 0x6d, 0x6e, 0x65, 0x73, 0x73, 0x50, 0x61, 0x69, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x52, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x6e, 0x65, 0x73, 0x73, 0x50, 0x61, + 0x69, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3e, + 0x0a, 0x09, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x12, 0x17, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4b, 0x65, 0x79, + 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, + 0x0a, 0x08, 0x53, 0x69, 0x67, 0x6e, 0x45, 0x4f, 0x54, 0x53, 0x12, 0x16, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x45, 0x4f, 0x54, 0x53, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x45, + 0x4f, 0x54, 0x53, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0e, 0x55, + 0x6e, 0x73, 0x61, 0x66, 0x65, 0x53, 0x69, 0x67, 0x6e, 0x45, 0x4f, 0x54, 0x53, 0x12, 0x16, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x45, 0x4f, 0x54, 0x53, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x69, + 0x67, 0x6e, 0x45, 0x4f, 0x54, 0x53, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4d, + 0x0a, 0x0e, 0x53, 0x69, 0x67, 0x6e, 0x53, 0x63, 0x68, 0x6e, 0x6f, 0x72, 0x72, 0x53, 0x69, 0x67, + 0x12, 0x1c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x53, 0x63, 0x68, + 0x6e, 0x6f, 0x72, 0x72, 0x53, 0x69, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x53, 0x63, 0x68, 0x6e, 0x6f, + 0x72, 0x72, 0x53, 0x69, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x50, 0x0a, + 0x0f, 0x53, 0x61, 0x76, 0x65, 0x45, 0x4f, 0x54, 0x53, 0x4b, 0x65, 0x79, 0x4e, 0x61, 0x6d, 0x65, + 0x12, 0x1d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x45, 0x4f, 0x54, + 0x53, 0x4b, 0x65, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x1e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x61, 0x76, 0x65, 0x45, 0x4f, 0x54, 0x53, + 0x4b, 0x65, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, + 0x3f, 0x5a, 0x3d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x61, + 0x62, 0x79, 0x6c, 0x6f, 0x6e, 0x6c, 0x61, 0x62, 0x73, 0x2d, 0x69, 0x6f, 0x2f, 0x66, 0x69, 0x6e, + 0x61, 0x6c, 0x69, 0x74, 0x79, 0x2d, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x2f, 0x65, + 0x6f, 0x74, 0x73, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -811,7 +919,7 @@ func file_eotsmanager_proto_rawDescGZIP() []byte { return file_eotsmanager_proto_rawDescData } -var file_eotsmanager_proto_msgTypes = make([]protoimpl.MessageInfo, 12) +var file_eotsmanager_proto_msgTypes = make([]protoimpl.MessageInfo, 14) var file_eotsmanager_proto_goTypes = []interface{}{ (*PingRequest)(nil), // 0: proto.PingRequest (*PingResponse)(nil), // 1: proto.PingResponse @@ -825,6 +933,8 @@ var file_eotsmanager_proto_goTypes = []interface{}{ (*SignEOTSResponse)(nil), // 9: proto.SignEOTSResponse (*SignSchnorrSigRequest)(nil), // 10: proto.SignSchnorrSigRequest (*SignSchnorrSigResponse)(nil), // 11: proto.SignSchnorrSigResponse + (*SaveEOTSKeyNameRequest)(nil), // 12: proto.SaveEOTSKeyNameRequest + (*SaveEOTSKeyNameResponse)(nil), // 13: proto.SaveEOTSKeyNameResponse } var file_eotsmanager_proto_depIdxs = []int32{ 0, // 0: proto.EOTSManager.Ping:input_type -> proto.PingRequest @@ -834,15 +944,17 @@ var file_eotsmanager_proto_depIdxs = []int32{ 8, // 4: proto.EOTSManager.SignEOTS:input_type -> proto.SignEOTSRequest 8, // 5: proto.EOTSManager.UnsafeSignEOTS:input_type -> proto.SignEOTSRequest 10, // 6: proto.EOTSManager.SignSchnorrSig:input_type -> proto.SignSchnorrSigRequest - 1, // 7: proto.EOTSManager.Ping:output_type -> proto.PingResponse - 3, // 8: proto.EOTSManager.CreateKey:output_type -> proto.CreateKeyResponse - 5, // 9: proto.EOTSManager.CreateRandomnessPairList:output_type -> proto.CreateRandomnessPairListResponse - 7, // 10: proto.EOTSManager.KeyRecord:output_type -> proto.KeyRecordResponse - 9, // 11: proto.EOTSManager.SignEOTS:output_type -> proto.SignEOTSResponse - 9, // 12: proto.EOTSManager.UnsafeSignEOTS:output_type -> proto.SignEOTSResponse - 11, // 13: proto.EOTSManager.SignSchnorrSig:output_type -> proto.SignSchnorrSigResponse - 7, // [7:14] is the sub-list for method output_type - 0, // [0:7] is the sub-list for method input_type + 12, // 7: proto.EOTSManager.SaveEOTSKeyName:input_type -> proto.SaveEOTSKeyNameRequest + 1, // 8: proto.EOTSManager.Ping:output_type -> proto.PingResponse + 3, // 9: proto.EOTSManager.CreateKey:output_type -> proto.CreateKeyResponse + 5, // 10: proto.EOTSManager.CreateRandomnessPairList:output_type -> proto.CreateRandomnessPairListResponse + 7, // 11: proto.EOTSManager.KeyRecord:output_type -> proto.KeyRecordResponse + 9, // 12: proto.EOTSManager.SignEOTS:output_type -> proto.SignEOTSResponse + 9, // 13: proto.EOTSManager.UnsafeSignEOTS:output_type -> proto.SignEOTSResponse + 11, // 14: proto.EOTSManager.SignSchnorrSig:output_type -> proto.SignSchnorrSigResponse + 13, // 15: proto.EOTSManager.SaveEOTSKeyName:output_type -> proto.SaveEOTSKeyNameResponse + 8, // [8:16] is the sub-list for method output_type + 0, // [0:8] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name @@ -998,6 +1110,30 @@ func file_eotsmanager_proto_init() { return nil } } + file_eotsmanager_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SaveEOTSKeyNameRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_eotsmanager_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SaveEOTSKeyNameResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1005,7 +1141,7 @@ func file_eotsmanager_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_eotsmanager_proto_rawDesc, NumEnums: 0, - NumMessages: 12, + NumMessages: 14, NumExtensions: 0, NumServices: 1, }, diff --git a/eotsmanager/proto/eotsmanager.proto b/eotsmanager/proto/eotsmanager.proto index ad32b192..c0cbc91e 100644 --- a/eotsmanager/proto/eotsmanager.proto +++ b/eotsmanager/proto/eotsmanager.proto @@ -30,6 +30,10 @@ service EOTSManager { // SignSchnorrSig signs a Schnorr sig with the EOTS private key rpc SignSchnorrSig (SignSchnorrSigRequest) returns (SignSchnorrSigResponse); + + // SaveEOTSKeyName saves a new key name mapping for the EOTS public key + rpc SaveEOTSKeyName (SaveEOTSKeyNameRequest) + returns (SaveEOTSKeyNameResponse); } message PingRequest {} @@ -113,3 +117,13 @@ message SignSchnorrSigResponse { // sig is the Schnorr signature bytes sig = 1; } + +message SaveEOTSKeyNameRequest { + // KeyName is the name of the key which corresponds to the + // BIP340 public key + string key_name = 1; + // EotsPK is the public key of the EOTS key BIP340PubKey + bytes eots_pk = 2; +} + +message SaveEOTSKeyNameResponse {} diff --git a/eotsmanager/proto/eotsmanager_grpc.pb.go b/eotsmanager/proto/eotsmanager_grpc.pb.go index 3028009f..4b695e92 100644 --- a/eotsmanager/proto/eotsmanager_grpc.pb.go +++ b/eotsmanager/proto/eotsmanager_grpc.pb.go @@ -26,6 +26,7 @@ const ( EOTSManager_SignEOTS_FullMethodName = "/proto.EOTSManager/SignEOTS" EOTSManager_UnsafeSignEOTS_FullMethodName = "/proto.EOTSManager/UnsafeSignEOTS" EOTSManager_SignSchnorrSig_FullMethodName = "/proto.EOTSManager/SignSchnorrSig" + EOTSManager_SaveEOTSKeyName_FullMethodName = "/proto.EOTSManager/SaveEOTSKeyName" ) // EOTSManagerClient is the client API for EOTSManager service. @@ -45,6 +46,8 @@ type EOTSManagerClient interface { UnsafeSignEOTS(ctx context.Context, in *SignEOTSRequest, opts ...grpc.CallOption) (*SignEOTSResponse, error) // SignSchnorrSig signs a Schnorr sig with the EOTS private key SignSchnorrSig(ctx context.Context, in *SignSchnorrSigRequest, opts ...grpc.CallOption) (*SignSchnorrSigResponse, error) + // SaveEOTSKeyName saves a new key name mapping for the EOTS public key + SaveEOTSKeyName(ctx context.Context, in *SaveEOTSKeyNameRequest, opts ...grpc.CallOption) (*SaveEOTSKeyNameResponse, error) } type eOTSManagerClient struct { @@ -118,6 +121,15 @@ func (c *eOTSManagerClient) SignSchnorrSig(ctx context.Context, in *SignSchnorrS return out, nil } +func (c *eOTSManagerClient) SaveEOTSKeyName(ctx context.Context, in *SaveEOTSKeyNameRequest, opts ...grpc.CallOption) (*SaveEOTSKeyNameResponse, error) { + out := new(SaveEOTSKeyNameResponse) + err := c.cc.Invoke(ctx, EOTSManager_SaveEOTSKeyName_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // EOTSManagerServer is the server API for EOTSManager service. // All implementations must embed UnimplementedEOTSManagerServer // for forward compatibility @@ -135,6 +147,8 @@ type EOTSManagerServer interface { UnsafeSignEOTS(context.Context, *SignEOTSRequest) (*SignEOTSResponse, error) // SignSchnorrSig signs a Schnorr sig with the EOTS private key SignSchnorrSig(context.Context, *SignSchnorrSigRequest) (*SignSchnorrSigResponse, error) + // SaveEOTSKeyName saves a new key name mapping for the EOTS public key + SaveEOTSKeyName(context.Context, *SaveEOTSKeyNameRequest) (*SaveEOTSKeyNameResponse, error) mustEmbedUnimplementedEOTSManagerServer() } @@ -163,6 +177,9 @@ func (UnimplementedEOTSManagerServer) UnsafeSignEOTS(context.Context, *SignEOTSR func (UnimplementedEOTSManagerServer) SignSchnorrSig(context.Context, *SignSchnorrSigRequest) (*SignSchnorrSigResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SignSchnorrSig not implemented") } +func (UnimplementedEOTSManagerServer) SaveEOTSKeyName(context.Context, *SaveEOTSKeyNameRequest) (*SaveEOTSKeyNameResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SaveEOTSKeyName not implemented") +} func (UnimplementedEOTSManagerServer) mustEmbedUnimplementedEOTSManagerServer() {} // UnsafeEOTSManagerServer may be embedded to opt out of forward compatibility for this service. @@ -302,6 +319,24 @@ func _EOTSManager_SignSchnorrSig_Handler(srv interface{}, ctx context.Context, d return interceptor(ctx, in, info, handler) } +func _EOTSManager_SaveEOTSKeyName_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SaveEOTSKeyNameRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(EOTSManagerServer).SaveEOTSKeyName(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: EOTSManager_SaveEOTSKeyName_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EOTSManagerServer).SaveEOTSKeyName(ctx, req.(*SaveEOTSKeyNameRequest)) + } + return interceptor(ctx, in, info, handler) +} + // EOTSManager_ServiceDesc is the grpc.ServiceDesc for EOTSManager service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -337,6 +372,10 @@ var EOTSManager_ServiceDesc = grpc.ServiceDesc{ MethodName: "SignSchnorrSig", Handler: _EOTSManager_SignSchnorrSig_Handler, }, + { + MethodName: "SaveEOTSKeyName", + Handler: _EOTSManager_SaveEOTSKeyName_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "eotsmanager.proto", diff --git a/eotsmanager/proto/signstore.pb.go b/eotsmanager/proto/signstore.pb.go index af355827..1e9058a3 100644 --- a/eotsmanager/proto/signstore.pb.go +++ b/eotsmanager/proto/signstore.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: signstore.proto diff --git a/eotsmanager/service/rpcserver.go b/eotsmanager/service/rpcserver.go index 7827bbee..a100b4d2 100644 --- a/eotsmanager/service/rpcserver.go +++ b/eotsmanager/service/rpcserver.go @@ -3,6 +3,7 @@ package service import ( "context" + "github.com/btcsuite/btcd/btcec/v2" "google.golang.org/grpc" "github.com/babylonlabs-io/finality-provider/eotsmanager" @@ -121,3 +122,16 @@ func (r *rpcServer) SignSchnorrSig(_ context.Context, req *proto.SignSchnorrSigR return &proto.SignSchnorrSigResponse{Sig: sig.Serialize()}, nil } + +// SaveEOTSKeyName signs a Schnorr sig with the EOTS private key +func (r *rpcServer) SaveEOTSKeyName( + _ context.Context, + req *proto.SaveEOTSKeyNameRequest, +) (*proto.SaveEOTSKeyNameResponse, error) { + eotsPk, err := btcec.ParsePubKey(req.EotsPk) + if err != nil { + return nil, err + } + + return &proto.SaveEOTSKeyNameResponse{}, r.em.SaveEOTSKeyName(eotsPk, req.KeyName) +} diff --git a/finality-provider/proto/finality_providers.pb.go b/finality-provider/proto/finality_providers.pb.go index 685da2c7..c545ea01 100644 --- a/finality-provider/proto/finality_providers.pb.go +++ b/finality-provider/proto/finality_providers.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 +// protoc-gen-go v1.33.0 // protoc (unknown) // source: finality_providers.proto