diff --git a/cmd/horcrux/cmd/shards.go b/cmd/horcrux/cmd/shards.go index 518aeac3..3f3e12d5 100644 --- a/cmd/horcrux/cmd/shards.go +++ b/cmd/horcrux/cmd/shards.go @@ -130,7 +130,7 @@ func createCosignerEd25519ShardsCmd() *cobra.Command { cmd.SilenceUsage = true for _, c := range csKeys { - dir, err := createCosignerDirectoryIfNecessary(out, c.ID()) + dir, err := createCosignerDirectoryIfNecessary(out, c.ID) if err != nil { return err } diff --git a/pkg/cosigner/local_cosigner.go b/pkg/cosigner/local_cosigner.go index ce60fc56..3646d2b6 100644 --- a/pkg/cosigner/local_cosigner.go +++ b/pkg/cosigner/local_cosigner.go @@ -316,9 +316,8 @@ func (cosigner *LocalCosigner) LoadSignStateIfNecessary(chainID string) error { return err } - // var signer IThresholdSigner - - signer, err := tss.NewThresholdEd25519SignerSoft(cosigner.config, cosigner.GetIndex(), chainID) + var signer IThresholdSigner + signer, err = tss.NewThresholdEd25519SignerSoft(cosigner.config, cosigner.GetIndex(), chainID) if err != nil { return err } diff --git a/pkg/tss/doc.go b/pkg/tss/doc.go new file mode 100644 index 00000000..d7f96ed8 --- /dev/null +++ b/pkg/tss/doc.go @@ -0,0 +1,44 @@ +package tss + +/* +// Package tss provides functionality related to threshold signature schemes. +// It includes functions for key generation, signing, and verification. +// +// The tss package includes the following primary types: +// +// - Key: Represents a key used in threshold signature schemes. +// +// - Signature: Represents a signature produced by a threshold signature scheme. +// +// - Verifier: Provides functions for verifying signatures. +// +// - Signer: Provides functions for generating signatures. +// +// Example usage: +// +// // Generate a new key. +// key, err := tss.NewKey() +// if err != nil { +// log.Fatalf("failed to generate key: %v", err) +// } +// +// // Create a new signer. +// signer := tss.NewSigner(key) +// +// // Sign a message. +// msg := []byte("hello, world") +// sig, err := signer.Sign(msg) +// if err != nil { +// log.Fatalf("failed to sign message: %v", err) +// } +// +// // Create a new verifier. +// verifier := tss.NewVerifier(key) +// +// // Verify the signature. +// if !verifier.Verify(msg, sig) { +// log.Fatalf("failed to verify signature") +// } +// +// Note: This is a simplified example. The actual usage may be different depending on the specifics of the threshold signature scheme. +*/ diff --git a/pkg/tss/godoc.go b/pkg/tss/godoc.go deleted file mode 100644 index 6b42b965..00000000 --- a/pkg/tss/godoc.go +++ /dev/null @@ -1,5 +0,0 @@ -package tss - -/* -Package tss -*/ diff --git a/pkg/tss/threshold-ed25519_signer_soft.go b/pkg/tss/threshold-ed25519_signer_soft.go index c67198f3..d2450809 100644 --- a/pkg/tss/threshold-ed25519_signer_soft.go +++ b/pkg/tss/threshold-ed25519_signer_soft.go @@ -47,19 +47,19 @@ func NewThresholdEd25519SignerSoft(config *config.RuntimeConfig, id int, chainID key, err := LoadVaultKeyFromFile(keyFile) if err != nil { - return nil, fmt.Errorf("error reading cosigner key: %s", err) + return nil, fmt.Errorf("error reading Vault key: %s", err) } - if key.id != id { - return nil, fmt.Errorf("key shard Index (%d) in (%s) does not match cosigner Index (%d)", key.id, keyFile, id) + if key.ID != id { + return nil, fmt.Errorf("key shard Index (%d) in (%s) does not match cosigner Index (%d)", key.ID, keyFile, id) } s := ThresholdSignerSoft{ - privateKeyShard: key.privateShard, + privateKeyShard: key.PrivateShard, pubKey: key.PubKey.Bytes(), threshold: uint8(config.Config.ThresholdModeConfig.Threshold), total: uint8(len(config.Config.ThresholdModeConfig.Cosigners)), - id: uint8(key.id), + id: uint8(key.ID), } return &s, nil diff --git a/pkg/tss/threshold_signer.go b/pkg/tss/threshold_signer.go index 7b1b1ac8..65785777 100644 --- a/pkg/tss/threshold_signer.go +++ b/pkg/tss/threshold_signer.go @@ -8,16 +8,22 @@ import ( "github.com/cometbft/cometbft/privval" ) -// LoadVaultKeyFromFile loads the persistent ThresholdSignerEd25519Key from file. -func LoadVaultKeyFromFile(file string) (VaultKey, error) { - pvKey := VaultKey{} +// LoadVaultKeyFromFile loads the persistent ThresholdSignerKey from file. + +func LoadVaultKeyFromFile(file string) (Ed25519Key, error) { + //pvKey := VaultKey{} + var pvKey Ed25519Key keyJSONBytes, err := os.ReadFile(file) - if err != nil { + if err != nil || len(keyJSONBytes) == 0 { + fmt.Printf("Could not read key from file %s", file) return pvKey, err } + fmt.Printf("keyJsonBytes is: %s", keyJSONBytes) + err = json.Unmarshal(keyJSONBytes, &pvKey) if err != nil { + fmt.Printf("Could not unmarshal key from file %s", file) return pvKey, err } @@ -54,8 +60,8 @@ func generatePersistentThresholdSignShards(filePVKey privval.FilePVKey, function for i, key := range keys { vaultKeys[i] = VaultKey{ PubKey: key.PubKey, - privateShard: key.PrivateShard, - id: key.ID, + PrivateShard: key.PrivateShard, + ID: key.ID, } } return vaultKeys, nil diff --git a/pkg/tss/types.go b/pkg/tss/types.go index 0b825a88..df4e5355 100644 --- a/pkg/tss/types.go +++ b/pkg/tss/types.go @@ -28,23 +28,27 @@ type PersistentEd25519Key struct { index int // Shamir index of this shard } -type VaultKey struct { - PubKey cometcrypto.PubKey `json:"pubKey"` - privateShard []byte //`// json:"privateShard"` - id int //`/Shamir index / json:"id"` -} +/* + type Ed25519Key struct { + PubKey cometcrypto.PubKey `json:"pubKey"` + PrivateShard []byte `json:"privateShard"` + Id int `json:"id"` + } // TODO: Should not actually get this. -func (key *VaultKey) ID() int { - return key.id -} + func (key *Ed25519Key) ID() int { + return key.Id + } +*/ type Ed25519Key struct { PubKey cometcrypto.PubKey `json:"pubKey"` PrivateShard []byte `json:"privateShard"` ID int `json:"id"` } +type VaultKey Ed25519Key + // TODO: redo to a function. func (key *Ed25519Key) MarshalJSON() ([]byte, error) { type Alias Ed25519Key @@ -68,7 +72,6 @@ func (key *Ed25519Key) MarshalJSON() ([]byte, error) { }) } -// redo to a function func (key *Ed25519Key) UnmarshalJSON(data []byte) error { type Alias Ed25519Key @@ -126,7 +129,7 @@ func ReadCometBFTPrivValidatorFile(filename string) (out privval.FilePVKey, err } type VaultPrivateKey interface { - VaultKey | Ed25519Key + Ed25519Key | VaultKey } // WriteToFile writes a key structure to a given file name. diff --git a/signer/cosigner_grpc_server.go b/signer/cosigner_grpc_server.go index adc20297..2c01c6a4 100644 --- a/signer/cosigner_grpc_server.go +++ b/signer/cosigner_grpc_server.go @@ -122,8 +122,8 @@ func (rpc *NodeGRPCServer) TransferLeadership( shardIndex := fmt.Sprint(c.GetIndex()) if shardIndex == leaderID { raftAddress := p2pURLToRaftAddress(c.GetAddress()) - // TODO: Change to logging + fmt.Printf("Transferring leadership to Index: %s - Address: %s\n", shardIndex, raftAddress) rpc.raftStore.raft.LeadershipTransferToServer(raft.ServerID(shardIndex), raft.ServerAddress(raftAddress)) return &proto.TransferLeadershipResponse{LeaderID: shardIndex, LeaderAddress: raftAddress}, nil }