Skip to content

WalletWasabi/NWabiSabi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WabiSabi

CodeFactor .NET NuGet

WabiSabi is an anonymous credential scheme used in CoinJoin to let participants register inputs and outputs without the coordinator learning which inputs correspond to which outputs. It is based on keyed-verification anonymous credentials (KVAC) over secp256k1 and zero-knowledge proofs.

This repository contains two independent implementations of the protocol that are fully wire-compatible with each other:

Project Language NuGet package
csharp/WabiSabi C# (managed) WabiSabi
csharp/WabiSabi.Native C# wrappers over a C shared library WabiSabi.Native

The interop/ directory contains an executable and test suite that verify the two implementations are binary-compatible: a request produced by one is correctly processed by the other.


Repository layout

WabiSabi/
├── c/                          C implementation (libwabisabi)
│   ├── src/                    Protocol sources
│   ├── include/wabisabi_ffi.h  Public C API
│   ├── tests/                  C test suite
│   └── CMakeLists.txt
├── csharp/
│   ├── WabiSabi/               Managed C# library
│   ├── WabiSabi.Native/        C# wrappers over libwabisabi (P/Invoke)
│   ├── WabiSabi.Tests/         Unit tests for the managed library
│   └── WabiSabi.sln
├── interop/
│   ├── Program.cs              Cross-language interop smoke test
│   ├── WabiSabiInterop.csproj
│   └── WabiSabiInterop.Tests/  xUnit interop compatibility tests
├── flake.nix                   Root Nix flake (C + .NET + NuGet)
└── c/flake.nix                 Standalone C-only Nix flake

The managed library — WabiSabi

A pure C# implementation with no native dependencies. It provides:

  • CredentialIssuer — coordinator-side: validates requests, issues MACs, tracks serial numbers
  • WabiSabiClient — client-side: builds zero and real credential requests, validates responses
  • The full zero-knowledge proof system (range proofs, balance proofs, show-credential proofs)

Build and test

dotnet build  csharp/WabiSabi.sln
dotnet test   csharp/WabiSabi.Tests/WabiSabi.Tests.csproj

Use as a NuGet dependency

dotnet add package WabiSabi
using WabiSabi.Crypto;
using WabiSabi.Crypto.Randomness;

var sk      = new CredentialIssuerSecretKey(SecureRandom.Instance);
var iparams = sk.ComputeCredentialIssuerParameters();

var issuer = new CredentialIssuer(sk, SecureRandom.Instance, maxAmount: 100_000_000);
var client = new WabiSabiClient(iparams, SecureRandom.Instance, rangeProofUpperBound: 100_000_000);

// Round 1 — bootstrap zero-value credentials
var zeroData = client.CreateRequestForZeroAmount();
var zeroResp = issuer.HandleRequest(zeroData.CredentialsRequest);
var zeroCreds = client.HandleResponse(zeroResp, zeroData.CredentialsResponseValidation);

// Round 2 — register an input of 500 000 satoshis
var realData  = client.CreateRequest(new[] { 500_000L }, zeroCreds, CancellationToken.None);
var realResp  = issuer.HandleRequest(realData.CredentialsRequest);
var valueCreds = client.HandleResponse(realResp, realData.CredentialsResponseValidation);

The native library — WabiSabi.Native

A C shared library (libwabisabi.so / wabisabi.dll / libwabisabi.dylib) that implements the same protocol in C, plus thin C# P/Invoke wrappers that expose an identical API to the managed library. This lets you swap WabiSabi.Native in for WabiSabi without changing any calling code.

The C library is stateless: all mutable state (issuer serial-number set, balance) is serialized to a byte array and passed back in on each call, making it straightforward to embed in any language.

Build the C library

Prerequisites: cmake, a C11 compiler, and an internet connection (or a local secp256k1 checkout).

cmake -B c/build -S c \
  -DCMAKE_BUILD_TYPE=Release \
  [-DFETCHCONTENT_SOURCE_DIR_SECP256K1=/path/to/secp256k1]
cmake --build c/build

The shared library is written to c/build/libwabisabi.so (Linux), c/build/wabisabi.dll (Windows), or c/build/libwabisabi.dylib (macOS).

Build and test the C# wrappers

dotnet build csharp/WabiSabi.Native/WabiSabi.Native.csproj

The interop tests require libwabisabi.so to be on LD_LIBRARY_PATH:

LD_LIBRARY_PATH=$PWD/c/build \
  dotnet test interop/WabiSabiInterop.Tests/WabiSabiInterop.Tests.csproj

Nix flake

The root flake.nix automates building both the C library and the NuGet package, including cross-compilation for all supported platforms.

Available outputs

Command Description
nix build Build the C library and run the C test suite
nix build .#wabisabi-c Same as above (explicit)
nix build .#wabisabi-nuget Pack WabiSabi.Native.nupkg with binaries for linux-x64, linux-arm64, and win-x64
nix run .#test Execute the C test binary
nix develop Combined C + .NET dev shell
nix develop .#c C-only dev shell (cmake, ninja, clangd, gdb)
nix develop .#dotnet .NET-only dev shell

macOS binaries: cross-compilation from Linux requires the macOS SDK, which is not available in nixpkgs. To include an osx-x64 binary in the package, build on a macOS host — the flake detects the Darwin host and includes the binary automatically.

Regenerate the NuGet lock file

If you add or update NuGet dependencies in WabiSabi.Native.csproj, regenerate the lock file used by Nix:

nix build .#packages.x86_64-linux.wabisabi-nuget.passthru.fetch-deps
./result csharp/WabiSabi.Native/nuget-deps.nix

Dev shells

# C development (auto-generates compile_commands.json for clangd)
nix develop .#c

# .NET development
nix develop .#dotnet

# Full interop development (C + .NET, sets LD_LIBRARY_PATH and SECP256K1_SOURCE_DIR)
nix develop

Inside the default dev shell you can run the full build and test cycle:

# Build the C library
cmake -B c/build -G Ninja -DCMAKE_BUILD_TYPE=Debug \
  -DFETCHCONTENT_SOURCE_DIR_SECP256K1=$SECP256K1_SOURCE_DIR -S c
cmake --build c/build

# C tests
./c/build/wabisabi_test

# .NET tests
dotnet test csharp/WabiSabi.Tests/WabiSabi.Tests.csproj

# Interop tests
dotnet test interop/WabiSabiInterop.Tests/WabiSabiInterop.Tests.csproj

# Interop smoke test
dotnet run --project interop/WabiSabiInterop.csproj

About

WabiSabi protocol implementation in .NET

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors