Files
mpc/pkg/infra/consul_adapter.go
zeekay 6f42074e06 Merge hanzo/mpc additions: ConsensusKV, HSM providers, policy engine, rename CLI to mpc-cli
- pkg/infra: Add abstract KV interface, ConsensusKV (dual-cert BFT with
  Ed25519 + ML-DSA-65), NatsKV, ConsulKVAdapter, HybridKV, SQLiteMeta
  with full test coverage
- pkg/hsm: Add Provider interface and implementations for AWS KMS,
  GCP Cloud KMS, Azure Key Vault, Zymbit HSM, Hanzo KMS, and file-based
  providers with registry and tests. Rename existing FileProvider to
  FilePasswordProvider to avoid collision with new Provider interface
- pkg/policy: Add transaction governance engine with signers, roles,
  spending limits, whitelist/blacklist, time windows, rate limiting,
  approval workflow, audit log, and FHE private policy evaluation
- contracts: Add ThresholdPolicy.sol for on-chain policy enforcement
- cmd: Rename lux-mpc-cli to mpc-cli
- Makefile: Update build targets for mpc-cli
2025-12-28 03:12:38 -08:00

55 lines
1.3 KiB
Go

package infra
import (
"github.com/hashicorp/consul/api"
)
// ConsulKVAdapter wraps the existing ConsulKV interface to implement the
// abstract KV interface. This allows existing Consul-based deployments to
// continue working while new deployments use consensus-backed storage.
type ConsulKVAdapter struct {
consul ConsulKV
}
// NewConsulKVAdapter creates a KV implementation backed by Consul.
func NewConsulKVAdapter(consulKV ConsulKV) *ConsulKVAdapter {
return &ConsulKVAdapter{consul: consulKV}
}
func (c *ConsulKVAdapter) Put(key string, value []byte) error {
_, err := c.consul.Put(&api.KVPair{Key: key, Value: value}, nil)
return err
}
func (c *ConsulKVAdapter) Get(key string) ([]byte, error) {
pair, _, err := c.consul.Get(key, nil)
if err != nil {
return nil, err
}
if pair == nil {
return nil, nil
}
return pair.Value, nil
}
func (c *ConsulKVAdapter) Delete(key string) error {
_, err := c.consul.Delete(key, nil)
return err
}
func (c *ConsulKVAdapter) List(prefix string) ([]*KVPair, error) {
pairs, _, err := c.consul.List(prefix, nil)
if err != nil {
return nil, err
}
result := make([]*KVPair, 0, len(pairs))
for _, p := range pairs {
result = append(result, &KVPair{
Key: p.Key,
Value: p.Value,
})
}
return result, nil
}