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

92 lines
1.7 KiB
Go

package pathutil
import (
"testing"
)
func TestValidateFilePath(t *testing.T) {
tests := []struct {
name string
path string
wantErr bool
}{
{
name: "valid simple path",
path: "test.json",
wantErr: false,
},
{
name: "valid relative path",
path: "config/test.json",
wantErr: false,
},
{
name: "path traversal attempt",
path: "../../../etc/passwd",
wantErr: true,
},
{
name: "path traversal with clean",
path: "config/../../../etc/passwd",
wantErr: true,
},
{
name: "valid absolute path",
path: "/tmp/test.json",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := ValidateFilePath(tt.path)
if (err != nil) != tt.wantErr {
t.Errorf("ValidateFilePath() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestSafePath(t *testing.T) {
tests := []struct {
name string
baseDir string
filename string
wantErr bool
}{
{
name: "valid file in base dir",
baseDir: "/tmp",
filename: "test.json",
wantErr: false,
},
{
name: "path traversal attempt",
baseDir: "/tmp",
filename: "../../../etc/passwd",
wantErr: true,
},
{
name: "path traversal with clean",
baseDir: "/tmp",
filename: "config/../../../etc/passwd",
wantErr: true,
},
{
name: "valid subdirectory",
baseDir: "/tmp",
filename: "config/test.json",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := SafePath(tt.baseDir, tt.filename)
if (err != nil) != tt.wantErr {
t.Errorf("SafePath() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}