Files
zeekay 19b49809fd Implement threshold MPC signing with CGGMP21, FROST, and LSS protocols
This commit adds complete multi-party computation (MPC) threshold signing
for multiple cryptographic protocols:

CGGMP21 (ECDSA/secp256k1):
- Key generation for Bitcoin/Ethereum/EVM chains
- Threshold signing with t-of-n security
- Recovery byte calculation for Ethereum compatibility

FROST/Taproot (EdDSA/BIP-340):
- EdDSA key generation for Solana/Sui/Polkadot
- BIP-340 compatible Schnorr signatures (64 bytes)
- CBOR serialization for TaprootConfig crypto types

LSS (Linear Secret Sharing):
- Dynamic resharing support (change participants)
- ECDSA signing with blinding protocol
- Protocol adapter for unified interface

Key fixes:
- Use MarshalBinary/UnmarshalBinary for protocol messages
- CBOR serialization for FROST TaprootConfig (not JSON)
- Correct type assertion for taproot.Signature ([]byte)
- Sorted party IDs for deterministic ordering

E2E tests pass for both ECDSA and EdDSA signing.
2026-01-24 23:41:43 -08:00

52 lines
1.3 KiB
Go

package pathutil
import (
"fmt"
"path/filepath"
"strings"
)
// SafePath validates and constructs a safe file path within a base directory
func SafePath(baseDir, filename string) (string, error) {
// Clean the filename to prevent path traversal
cleanFilename := filepath.Clean(filename)
// Check for path traversal attempts
if strings.Contains(cleanFilename, "..") {
return "", fmt.Errorf("invalid filename: path traversal not allowed")
}
// Construct the full path
fullPath := filepath.Join(baseDir, cleanFilename)
// Ensure the path is within the base directory
absBase, err := filepath.Abs(baseDir)
if err != nil {
return "", fmt.Errorf("failed to get absolute path for base directory: %w", err)
}
absPath, err := filepath.Abs(fullPath)
if err != nil {
return "", fmt.Errorf("failed to get absolute path: %w", err)
}
if !strings.HasPrefix(absPath, absBase) {
return "", fmt.Errorf("path outside base directory not allowed")
}
return fullPath, nil
}
// ValidateFilePath validates a file path for security concerns
func ValidateFilePath(filePath string) error {
// Clean the path
cleanPath := filepath.Clean(filePath)
// Check for path traversal attempts
if strings.Contains(cleanPath, "..") {
return fmt.Errorf("invalid file path: path traversal not allowed")
}
return nil
}