This package provides a unified interface for secp256k1 cryptographic operations with automatic fallback from C bindings to pure Go.
The signer detects which optional modules are compiled into libsecp256k1:
This means you can have libsecp256k1 without Schnorr support, and the signer will use C for ECDSA while transparently falling back to pure Go for Schnorr operations.
import "p8k.mleku.dev/p8k"
func main() {
// Create signer (automatically detects and falls back)
signer, err := p8k.NewSigner()
if err != nil {
log.Fatal(err)
}
defer signer.Close()
// Check which modules are available
status := signer.GetModuleStatus()
log.Printf("Library: %v, Schnorr: %v, ECDH: %v",
status["library"], status["schnorr"], status["ecdh"])
// Use normally - interface is the same regardless
privkey := make([]byte, 32)
rand.Read(privkey)
pubkey, _ := signer.GeneratePublicKey(privkey)
sig, _ := signer.SchnorrSign(msg, privkey, auxrand)
valid, _ := signer.SchnorrVerify(sig, msg, xonly)
}
NewSigner() - Create new signer with auto-fallbackClose() - Clean up resourcesIsUsingFallback() - Check if using pure Go for everythingGetModuleStatus() - Check which modules are availableGeneratePublicKey(privkey) - Derive public keySchnorrSign(msg, privkey, auxrand) - BIP-340 Schnorr signatureSchnorrVerify(sig, msg, xonly) - Verify Schnorr signatureSign(msg, privkey) - ECDSA signatureVerify(msg, sig, pubkey) - Verify ECDSA signatureECDHSharedSecret(pubkey, privkey) - Compute shared secretGetXOnlyPubkey(privkey) - Extract x-only pubkeyWhen libsecp256k1 is available with all modules, you get full C-level performance. When specific modules are missing, only those functions fall back to pure Go while the rest stay at C performance.
Full C bindings (all modules available):
Library: true, Schnorr: true, ECDH: true, Recovery: true
→ All operations use C bindings (maximum performance)
Partial C bindings (Schnorr module missing):
Library: true, Schnorr: false, ECDH: true, Recovery: true
→ ECDSA and ECDH use C, Schnorr uses pure Go
Full pure Go fallback (library not available):
Library: false, Schnorr: false, ECDH: false, Recovery: false
→ All operations use pure Go (guaranteed compatibility)
MIT License