Ufsecp 3.19.0
dotnet add package Ufsecp --version 3.19.0
NuGet\Install-Package Ufsecp -Version 3.19.0
<PackageReference Include="Ufsecp" Version="3.19.0" />
<PackageVersion Include="Ufsecp" Version="3.19.0" />
<PackageReference Include="Ufsecp" />
paket add Ufsecp --version 3.19.0
#r "nuget: Ufsecp, 3.19.0"
#:package Ufsecp@3.19.0
#addin nuget:?package=Ufsecp&version=3.19.0
#tool nuget:?package=Ufsecp&version=3.19.0
Ufsecp
C# P/Invoke bindings for UltrafastSecp256k1 -- high-performance secp256k1 elliptic curve cryptography.
Bundles native runtimes for Windows x64, Linux x64, Linux ARM64, and macOS ARM64. The native library is auto-copied to your build output -- no manual setup required.
Install
dotnet add package Ufsecp
Quick Start
using Ultrafast.Ufsecp;
using System.Security.Cryptography;
using var ctx = new Ufsecp();
// Generate key pair
byte[] privkey = RandomNumberGenerator.GetBytes(32);
byte[] pubkey = ctx.PubkeyCreate(privkey);
Console.WriteLine($"Version: {Ufsecp.VersionString}");
Console.WriteLine($"Pubkey: {Convert.ToHexString(pubkey)}");
ECDSA Sign & Verify
byte[] msgHash = Ufsecp.Sha256("hello world"u8.ToArray());
// Sign (RFC 6979 deterministic nonce, low-S normalized)
byte[] sig = ctx.EcdsaSign(msgHash, privkey);
// Verify
bool valid = ctx.EcdsaVerify(msgHash, sig, pubkey);
// DER encode/decode
byte[] der = ctx.EcdsaSigToDer(sig);
byte[] compact = ctx.EcdsaSigFromDer(der);
ECDSA Recovery
var (recSig, recId) = ctx.EcdsaSignRecoverable(msgHash, privkey);
byte[] recovered = ctx.EcdsaRecover(msgHash, recSig, recId);
Schnorr (BIP-340)
byte[] xOnlyPub = ctx.PubkeyXonly(privkey);
byte[] auxRand = RandomNumberGenerator.GetBytes(32);
byte[] schnorrSig = ctx.SchnorrSign(msgHash, privkey, auxRand);
bool ok = ctx.SchnorrVerify(msgHash, schnorrSig, xOnlyPub);
ECDH
byte[] otherPriv = RandomNumberGenerator.GetBytes(32);
byte[] otherPub = ctx.PubkeyCreate(otherPriv);
byte[] shared = ctx.Ecdh(privkey, otherPub); // SHA-256 of compressed point
byte[] xonly = ctx.EcdhXonly(privkey, otherPub); // SHA-256 of x-coordinate
byte[] raw = ctx.EcdhRaw(privkey, otherPub); // raw 32-byte x-coordinate
Bitcoin Addresses
string p2pkh = ctx.AddrP2PKH(pubkey); // 1...
string p2wpkh = ctx.AddrP2WPKH(pubkey); // bc1q...
string p2tr = ctx.AddrP2TR(xOnlyPub); // bc1p...
string test = ctx.AddrP2WPKH(pubkey, Network.Testnet); // tb1q...
BIP-32 HD Derivation
byte[] seed = RandomNumberGenerator.GetBytes(64);
byte[] master = ctx.Bip32Master(seed);
byte[] child = ctx.Bip32DerivePath(master, "m/44'/0'/0'/0/0");
byte[] childPriv = ctx.Bip32Privkey(child);
byte[] childPub = ctx.Bip32Pubkey(child);
WIF
string wif = ctx.WifEncode(privkey, compressed: true, Network.Mainnet);
var decoded = ctx.WifDecode(wif);
// decoded.Privkey, decoded.Compressed, decoded.Network
Taproot (BIP-341)
var (outputKeyX, parity) = ctx.TaprootOutputKey(xOnlyPub);
byte[] tweakedPriv = ctx.TaprootTweakSeckey(privkey);
bool tapValid = ctx.TaprootVerify(outputKeyX, parity, xOnlyPub);
Hashing
byte[] sha = Ufsecp.Sha256(data); // SHA-256 (SHA-NI accelerated)
byte[] h160 = Ufsecp.Hash160(data); // RIPEMD160(SHA256(data))
byte[] tagged = Ufsecp.TaggedHash("BIP0340/aux", data); // BIP-340 tagged hash
API Coverage (45+ functions)
Keys, ECDSA (sign/verify/recover/DER), Schnorr BIP-340, ECDH (compressed/xonly/raw), SHA-256, HASH160, Tagged Hash, BIP-32 HD, Taproot (BIP-341), Bitcoin Addresses (P2PKH/P2WPKH/P2TR), WIF, Key Tweaking.
Architecture Note
The C ABI layer uses the fast (variable-time) implementation for maximum throughput. A constant-time (CT) layer with identical mathematical operations is available via the C++ headers for applications requiring timing-attack resistance.
Supported Platforms
| Platform | Runtime |
|---|---|
| Windows x64 | ufsecp.dll |
| Linux x64 | libufsecp.so |
| Linux ARM64 | libufsecp.so |
| macOS ARM64 | libufsecp.dylib |
License
MIT
Links
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.