Files
zeekay 1fa6eb5fd5 refactor(mpc): thin wrapper over luxfi/mpc (canonical) — v2.0.0
Per CTO directive: hanzo/mpc must be identical to luxfi/mpc with only
defaults differing. Eliminates fork drift and consolidates the canonical
implementation in github.com/luxfi/mpc.

What changed:
  - cmd/hanzo-mpc/main.go: now mirrors luxfi/mpc/cmd/mpcd verbatim, with
    Hanzo overrides applied via setEnvDefault before viper init:
      MPC_DATA_DIR    = /data/hanzo-mpc      (lux: /data/mpc)
      MPC_DB_PATH     = /data/hanzo-mpc/db
      MPC_BACKUP_DIR  = /data/hanzo-mpc/backups
      BRAND_NAME      = Hanzo
    Version bumped to 2.0.0; banner shows "Hanzo MPC v2.0.0 — thin wrapper
    over luxfi/mpc (canonical)".
  - cmd/hanzo-mpc-cli/main.go: removed `recover` subcommand (the kvstore
    BackupExecutor API moved into luxfi/mpc/pkg/backup; downstream tooling
    should call that directly). Renamed binary to "hanzo-mpc-cli" and
    bumped to v2.0.0.
  - examples/, scripts/: import paths swapped from
    github.com/hanzoai/mpc/pkg/* → github.com/luxfi/mpc/pkg/*. Broken
    migration scripts (BadgerKVStore API removed upstream) deleted.
  - go.mod: drops 40+ direct deps that lived in the fork. Adds direct
    dep on github.com/luxfi/mpc with replace directive to ../../lux/mpc
    for local dev. Mirrors luxfi/mpc's `replace github.com/agl/ed25519
    => github.com/luxfi/edwards25519` for transitive correctness.
  - Dockerfile: data dir bumped to /data/hanzo-mpc; ports updated to the
    canonical luxfi/mpc layout (9651=P2P, 9800=internal API,
    8081=dashboard).
  - pkg/: DELETED entirely (api/, client/, config/, constant/, encoding/,
    encryption/, event/, eventconsumer/, hsm/, identity/, infra/,
    keyinfo/, kms/, kvstore/, logger/, messaging/, mpc/, policy/,
    protocol/, storage/, threshold/, types/, utils/). All consumers
    (zero external Go consumers found) point at luxfi/mpc/pkg/* now.

Net: -26961 / +1663 LOC.

Wire/protocol compatibility:
  Hanzo MPC speaks the same NATS messaging, ZapDB key-share format,
  consensus transport, and HSM signer protocols as luxfi/mpc — they are
  literally the same code. A Hanzo MPC node can join a Lux MPC cluster
  and participate in keygen/sign rounds without modification.
2026-04-18 21:26:32 -07:00

132 lines
3.6 KiB
Go

package main
import (
"encoding/hex"
"fmt"
"log"
"time"
"github.com/google/uuid"
"github.com/luxfi/mpc/pkg/client"
"github.com/luxfi/mpc/pkg/event"
"github.com/luxfi/mpc/pkg/types"
"github.com/nats-io/nats.go"
)
func main() {
// Connect to NATS
nc, err := nats.Connect(nats.DefaultURL)
if err != nil {
log.Fatal("Failed to connect to NATS:", err)
}
defer nc.Close()
// Create MPC client
mpcClient := client.NewMPCClient(client.Options{
NatsConn: nc,
KeyPath: "./event_initiator.key",
})
// Example 1: Sign an XRPL transaction
signXRPLTransaction(mpcClient)
}
func signXRPLTransaction(mpcClient client.MPCClient) {
fmt.Println("=== XRPL Transaction Signing Example ===")
// In a real scenario, you would have a wallet ID from a previously created wallet
walletID := "your-xrpl-wallet-id"
// Example XRPL transaction data
// In production, this would be a properly formatted XRPL transaction JSON
// that has been serialized according to XRPL standards
xrplTxJSON := `{
"TransactionType": "Payment",
"Account": "rN7n7otQDd6FczFgLdSqtcsAUxDkw6fzRH",
"Destination": "rLNaPoKeeBjZe2qs6x52yVPZpZ8td4dc6w",
"Amount": "1000000",
"Fee": "12",
"Sequence": 1,
"SigningPubKey": "YOUR_PUBLIC_KEY_HERE"
}`
// Convert to bytes (in production, use proper XRPL serialization)
txData := []byte(xrplTxJSON)
txID := fmt.Sprintf("xrpl-tx-%s", uuid.New().String())
// Create signing message
signingMsg := &types.SignTxMessage{
WalletID: walletID,
TxID: txID,
Tx: txData,
KeyType: types.KeyTypeSecp256k1, // XRPL uses secp256k1
NetworkInternalCode: string(types.NetworkXRPL),
}
// Sign the message with initiator key
_, err := signingMsg.Raw()
if err != nil {
log.Fatal("Failed to get raw message:", err)
}
// In production, use your actual initiator private key
// signature, err := initiatorPrivKey.Sign(msg)
// signingMsg.Signature = signature
// Set up result listener
resultChan := make(chan event.SigningResultEvent, 1)
err = mpcClient.OnSignResult(func(result event.SigningResultEvent) {
if result.TxID == txID {
resultChan <- result
}
})
if err != nil {
log.Fatal("Failed to set up result listener:", err)
}
// Send signing request
fmt.Printf("Sending XRPL signing request for transaction: %s\n", txID)
err = mpcClient.SignTransaction(signingMsg)
if err != nil {
log.Fatal("Failed to send signing request:", err)
}
// Wait for result
select {
case result := <-resultChan:
if result.ResultType == event.ResultTypeSuccess {
fmt.Println("✅ XRPL Transaction signed successfully!")
fmt.Printf("Wallet ID: %s\n", result.WalletID)
fmt.Printf("Transaction ID: %s\n", result.TxID)
fmt.Printf("Network: %s\n", result.NetworkInternalCode)
fmt.Printf("Signature (hex): %s\n", hex.EncodeToString(result.Signature))
// The signature can now be added to the XRPL transaction
// and submitted to the XRPL network
} else {
fmt.Printf("❌ Signing failed: %s\n", result.ErrorReason)
}
case <-time.After(30 * time.Second):
fmt.Println("⏱️ Timeout waiting for signing result")
}
}
// Example function showing how to verify network support
func verifyXRPLSupport() {
networks := []string{
string(types.NetworkXRPL),
string(types.NetworkXRPLTestnet),
string(types.NetworkXRPLDevnet),
}
fmt.Println("=== XRPL Network Support ===")
for _, network := range networks {
if types.IsNetworkSupported(network) {
keyType := types.GetNetworkKeyType(types.NetworkCode(network))
fmt.Printf("✅ %s is supported (uses %s)\n", network, keyType)
} else {
fmt.Printf("❌ %s is not supported\n", network)
}
}
}