mirror of
https://github.com/hanzoai/mpc.git
synced 2026-10-30 19:45:28 +00:00
Replace Consul with private BFT blockchain (ConsensusKV) as default state management backend for MPC cluster. MPC nodes are now validators on their own chain with dual-certificate finality: - Ed25519 (classical, 64B sig) + ML-DSA-65 (FIPS 204, 3,309B sig) - Block finalized only when BOTH signature types reach t-of-n threshold - Abstract KV interface with 3 backends: consensus (default), nats, consul - Signer interface for KMS/HSM delegation (keys never leave enclave) - Bootstrap via NATS JetStream KV bucket before consensus genesis - State sync via snapshot for new node joins - Same luxfi/crypto/mldsa used by Lux mainnet precompiles All existing Consul code preserved for 100% parity testing.
65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
package keyinfo
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/hanzoai/mpc/pkg/infra"
|
|
)
|
|
|
|
type KeyInfo struct {
|
|
ParticipantPeerIDs []string `json:"participant_peer_ids"`
|
|
Threshold int `json:"threshold"`
|
|
Version int `json:"version"`
|
|
Curve string `json:"curve,omitempty"`
|
|
}
|
|
|
|
type store struct {
|
|
kv infra.KV
|
|
}
|
|
|
|
func NewStore(kv infra.KV) *store {
|
|
return &store{kv: kv}
|
|
}
|
|
|
|
type Store interface {
|
|
Get(walletID string) (*KeyInfo, error)
|
|
Save(walletID string, info *KeyInfo) error
|
|
}
|
|
|
|
func (s *store) Get(walletID string) (*KeyInfo, error) {
|
|
data, err := s.kv.Get(s.composeKey(walletID))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Failed to get key info: %w", err)
|
|
}
|
|
if data == nil {
|
|
return nil, fmt.Errorf("Key info not found")
|
|
}
|
|
|
|
info := &KeyInfo{}
|
|
err = json.Unmarshal(data, info)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Failed to unmarshal key info: %w", err)
|
|
}
|
|
|
|
return info, nil
|
|
}
|
|
|
|
func (s *store) Save(walletID string, info *KeyInfo) error {
|
|
bytes, err := json.Marshal(info)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to marshal key info: %w", err)
|
|
}
|
|
|
|
err = s.kv.Put(s.composeKey(walletID), bytes)
|
|
if err != nil {
|
|
return fmt.Errorf("Failed to save key info: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *store) composeKey(walletID string) string {
|
|
return fmt.Sprintf("threshold_keyinfo/%s", walletID)
|
|
}
|