Files
zeekay 8273105926 The signing curve is derived from the network, not stated by the caller
Solana addresses were correct and receive-only: ConsensusKeyInfoStore.Save was
the only RegisterKey caller and hardcoded "secp256k1", and TriggerSign read the
curve from that field, so no product entry point could reach Ed25519 signing.

The hardcode is not fixed, it is UNREPRESENTABLE. transport.KeyInfo.KeyType is
deleted — the record carries one public key per curve and a PublicKeyFor(curve)
— and RegisterKey lost its keyType parameter, so there is no longer a place to
state a curve wrongly. A scalar KeyType was the wrong shape anyway: one keygen
ceremony produces BOTH a secp256k1 and an Ed25519 key, so "what curve is this
wallet" has no single answer.

The request carries the network instead, and ONE table maps it to a curve, with
NO default arm — KeyTypeForNetwork returns ErrUnknownNetwork rather than
guessing. That is the point: the old default returned secp256k1 for anything
unrecognized, which is how a Solana request would have been signed with the
wrong key.

/sign's 32-byte clamp becomes the SCHEME's rule rather than the endpoint's:
secp256k1 signs a digest and requires exactly 32 bytes, Ed25519 signs the
message at any length. /sign no longer accepts key_type at all — two ways to say
the curve is the misuse being removed — and Network is bound into the
idempotency fingerprint, so the same bytes for SOL and ETH conflict instead of
sharing one cached signature from a different key.

⚠ The trap this nearly shipped with: every pre-existing KeyInfo record has EMPTY
public keys, because the old Save wrote "", "". A naive "does this wallet have
this curve" gate would have refused every existing wallet on every curve. The
check is gated on RecordsCurves() — a record naming no curve denies none, and
the missing share stays the thing that fails closed.

Verified end to end, not by mirroring: a Solana request through
ConsensusMPCBackend.TriggerSign with a real 2-of-3 FROST ring produces a
signature crypto/ed25519.Verify accepts, over a 63-byte message so any
reintroduced clamp or pre-hash fails it; ETH/EVM/BTC/LUX still route to
secp256k1 and must RECOVER to the wallet's key. Four mutations tried, all
caught.

Behavioral risk worth naming: an unrecognized chain string now fails its
transaction closed rather than signing with a default. That is correct, and the
real fix is validating chain at POST /v1/transactions.
2026-08-06 15:59:30 -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 {
keyType, err := types.KeyTypeForNetwork(types.NetworkCode(network))
if err != nil {
fmt.Printf("%s is not supported: %v\n", network, err)
continue
}
fmt.Printf("%s is supported (uses %s)\n", network, keyType)
}
}