Elixir NIF bindings for the bitcoin-core/secp256k1 cryptographic library. Used extensively in Bitcoin, Ethereum, Nostr, and other blockchain/cryptocurrency applications.
This package exposes libsecp256k1 behavior in Elixir. It intentionally relies on Erlang's
:cryptomodule for generic cryptographic building blocks such as hashing, random bytes, generic ECDSA, and raw ECDH.
- Keypair generation - secure random secret keys with compressed, uncompressed, or x-only public keys
- Key validation - validate externally received secret and public keys before use
- Key tweaks - BIP-32-style full-key derivation and x-only Taproot commitments
- ECDSA signatures - sign, verify, normalize low-S, and convert compact signatures to and from DER
- Schnorr signatures - BIP-340 compatible, used in Taproot and Nostr
- MuSig2 - BIP-327 multi-party Schnorr signatures (experimental)
- ECDH - Diffie-Hellman shared secret computation
The package includes the upstream libsecp256k1 source as a vendored tarball with a pre-generated configure script. Users need make, a C compiler, and standard Unix tools tar plus either sha256sum or shasum, which are present in standard Unix userland. No network, git, autoconf, automake, or libtool is required to compile the package.
Linux (Ubuntu/Debian)
sudo apt-get install build-essentialmacOS
Install Xcode Command Line Tools:
xcode-select --installRequires Elixir 1.16 or later. Add to your mix.exs:
def deps do
[
{:lib_secp256k1, "~> 0.8"}
]
end- HexDocs - API reference
- Usage Guide - detailed examples, also runnable as a Livebook
- MuSig Guide - multi-signature protocol walkthrough, also runnable as a Livebook
From a local checkout, run the guides interactively with Livebook:
livebook server docs- Linux - fully supported, primary development platform
- macOS - supported with Xcode Command Line Tools
- Windows - not tested, contributions welcome
WTFPL - Do What The Fuck You Want To Public License
The underlying secp256k1 C library is MIT licensed. Its COPYING file ships inside the vendored tarball, and the Hex package metadata declares both WTFPL and MIT licenses.
