CI | Platform | Build |
---|---|---|
AppVeyor | Windows & Ubuntu | |
TravisCI | Linux x64 | |
TravisCI | MacOS x64 |
Cross platform C# wrapper for the native secp256k1 library.
The nuget package supports win-x64, win-x86, macOS-x64, and linux-x64 out of the box. The native libraries are bundled from the Secp256k1.Native package. This wrapper should work on any other platform that supports netstandard2.0 (.NET Core 2.0+, Mono 5.4+, etc) but requires that the native secp256k1 library be compiled from source.
// Create a secp256k1 context (ensure disposal to prevent unmanaged memory leaks).
using (var secp256k1 = new Secp256k1())
{
// Generate a private key.
var privateKey = new byte[32];
var rnd = System.Security.Cryptography.RandomNumberGenerator.Create();
do { rnd.GetBytes(privateKey); }
while (!secp256k1.SecretKeyVerify(privateKey));
// Create public key from private key.
var publicKey = new byte[64];
Debug.Assert(secp256k1.PublicKeyCreate(publicKey, privateKey));
// Sign a message hash.
var messageBytes = Encoding.UTF8.GetBytes("Hello world.");
var messageHash = System.Security.Cryptography.SHA256.Create().ComputeHash(messageBytes);
var signature = new byte[64];
Debug.Assert(secp256k1.Sign(signature, messageHash, privateKey));
// Verify message hash.
Debug.Assert(secp256k1.Verify(signature, messageHash, publicKey));
}
See the tests project for more complex examples of using recoverable and serialization functions.