A complete Go package providing bindings to libsecp256k1 without CGO. Uses dynamic library loading via purego to call C functions directly.
p8k.mleku.dev/
├── libsecp256k1.so # Bundled library for Linux AMD64 (1.8 MB)
├── secp.go # Core library with context management and ECDSA
├── schnorr.go # Schnorr signature (BIP-340) module
├── ecdh.go # ECDH key exchange module
├── recovery.go # Public key recovery module
├── utils.go # High-level convenience functions
├── secp_test.go # Comprehensive test suite
├── examples/
│ ├── ecdsa/ # ECDSA example
│ ├── schnorr/ # Schnorr signature example
│ ├── ecdh/ # ECDH key exchange example
│ └── recovery/ # Public key recovery example
├── bench/ # Comparative benchmark suite
│ ├── bench_test.go # Benchmarks vs BTCEC and P256K1
│ ├── Makefile # Convenient benchmark targets
│ ├── README.md # Benchmark documentation
│ └── run_benchmarks.sh # Automated benchmark runner
├── go.mod # Module definition
├── go.sum # Dependency checksums
├── Makefile # Build automation
├── README.md # Main documentation
├── QUICKSTART.md # Quick reference guide
├── API.md # Complete API documentation
├── LIBRARY.md # Bundled library documentation
└── LICENSE # MIT License
✓ Dynamic library loading for Linux, macOS, Windows ✓ Context creation and management with automatic cleanup ✓ Context randomization ✓ Public key generation from private keys ✓ Public key serialization (compressed/uncompressed) ✓ Public key parsing ✓ ECDSA signature creation ✓ ECDSA signature verification ✓ DER signature encoding/decoding ✓ Compact signature encoding/decoding ✓ Signature normalization
✓ Keypair creation for Schnorr ✓ X-only public key extraction ✓ Schnorr signature creation (BIP-340) ✓ Schnorr signature verification (BIP-340) ✓ X-only public key parsing/serialization ✓ Conversion from regular to x-only public keys
✓ EC Diffie-Hellman shared secret computation
✓ Recoverable signature creation ✓ Recoverable signature serialization ✓ Recoverable signature parsing ✓ Public key recovery from signatures
✓ Private key generation ✓ One-line key generation helpers ✓ One-line signing helpers ✓ One-line verification helpers ✓ Key validation functions ✓ All operations with automatic context management
✓ Context creation tests ✓ Public key generation tests ✓ Serialization tests ✓ ECDSA signing and verification tests ✓ DER encoding tests ✓ Compact encoding tests ✓ Signature normalization tests ✓ Schnorr signature tests ✓ ECDH tests ✓ Recovery tests ✓ Performance benchmarks
✓ Complete ECDSA example ✓ Complete Schnorr signature example ✓ Complete ECDH example ✓ Complete recovery example
✓ Comprehensive README with installation and usage ✓ Quick reference guide (QUICKSTART.md) ✓ Complete API documentation (API.md) ✓ Inline code documentation ✓ Example programs
✓ Makefile with targets for test, build, examples, etc. ✓ Automated library installation helper ✓ Example building and running
purego library for dynamic loading// Context flags
ContextNone, ContextVerify, ContextSign, ContextDeclassify
// EC flags
ECCompressed, ECUncompressed
// Sizes
PublicKeySize = 64
CompressedPublicKeySize = 33
UncompressedPublicKeySize = 65
SignatureSize = 64
CompactSignatureSize = 64
PrivateKeySize = 32
SharedSecretSize = 32
SchnorrSignatureSize = 64
RecoverableSignatureSize = 65
import "p8k.mleku.dev"
// Generate keys
privKey, _ := secp.GeneratePrivateKey()
pubKey, _ := secp.PublicKeyFromPrivate(privKey, true)
// Sign message
msgHash := sha256.Sum256([]byte("Hello"))
sig, _ := secp.SignMessage(msgHash[:], privKey)
// Verify signature
valid, _ := secp.VerifyMessage(msgHash[:], sig, pubKey)
# Run all tests
make test
# Run benchmarks
make bench
# Build and run examples
make run-examples
# Build everything
make build
# Install the package
go get p8k.mleku.dev
# Install libsecp256k1
make install-secp256k1 # Or use your package manager
Linux AMD64: ✅ Bundled library included (libsecp256k1.so v5.0.0, 1.8 MB) - works out of the box!
Other Platforms:
Context objects are NOT thread-safe. Each goroutine should have its own context. Utility functions are safe to use concurrently.
MIT License
Bindings to libsecp256k1 by Bitcoin Core developers.
✅ All core functionality implemented ✅ All modules implemented (Schnorr, ECDH, Recovery) ✅ Comprehensive tests written ✅ Examples provided ✅ Comprehensive benchmark suite (vs BTCEC & P256K1) ✅ Documentation complete ✅ Bundled library for Linux AMD64 (zero installation!) ✅ Compiles without errors ✅ Ready for production use