zetrix_vc_flutter 0.0.3 copy "zetrix_vc_flutter: ^0.0.3" to clipboard
zetrix_vc_flutter: ^0.0.3 copied to clipboard

Zetrix flutter SDK for Verifiable Credential (Verifiable Presentation)

πŸ“¦ zetrix_vc_flutter Plugin #

A Flutter plugin that enables Verifiable Credential (VC) and Verifiable Presentation (VP) generation using BBS+ signatures, built on top of Zetrix blockchain specifications.

This implementation uses platform-specific native libraries (Rust-compiled via JNI/FFI) and exposes functionality to Dart via MethodChannel.


βœ… Features #

  • 🧠 BBS+ key generation (BLS12-381)
  • ✍️ BBS+ signature creation
  • πŸ” Selective disclosure proofs
  • 🧱 Works across Android and iOS (iOS soon)
  • πŸ“¦ Built as a Flutter plugin (no manual linking for consumers)

🧹 Project Structure #

zetrix_vc_flutter/
β”œβ”€β”€ android/
β”‚   β”œβ”€β”€ src/main/java/.../MethodChannelHandler.java
β”‚   β”œβ”€β”€ src/main/jniLibs/arm64-v8a/libbbs.so
β”‚   └── ...
β”œβ”€β”€ ios/
β”‚   └── (pending FFI integration)
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ bbs_bindings.dart
β”‚   β”œβ”€β”€ bbs.dart
β”‚   └── zetrix_vc_flutter.dart
β”œβ”€β”€ example/
└── pubspec.yaml

πŸ”§ How We Integrated Using MethodChannel #

βœ… Step-by-step: #

1. Expose Native Methods via Java (Android)

We created a wrapper class in android/src/main/java/.../BbsMethodHandler.java that maps Dart calls to native Rust bindings via JNI.

Example:

methodChannel.setMethodCallHandler((call, result) -> {
    switch (call.method) {
        case "createBbsProof":
            // call Rust JNI wrapper
            byte[] proof = Bbs.createProof(...);
            result.success(proof);
            break;
        default:
            result.notImplemented();
    }
});

2. Implement Dart MethodChannel

In bbs.dart, we use Flutter's MethodChannel to call native methods:

const _channel = MethodChannel('zetrix_vc');

Future<Uint8List> createBbsProof(Map<String, dynamic> args) async {
  final result = await _channel.invokeMethod<Uint8List>('createBbsProof', args);
  return result!;
}

We placed libbbs.so in android/src/main/jniLibs/ so it is automatically bundled into the APK:

android/
└── src/main/jniLibs/
    └── arm64-v8a/
        └── libbbs.so

No manual linking needed from consumers.

4. Generate and Use JNI Headers

To link Java and Rust, we generated bbs_signatures_Bbs.h using javac -h. This header defines all native functions that the Rust/C side must implement.

javac -h . Bbs.java

πŸ” Why MethodChannel? #

We chose MethodChannel over Dart FFI for Android because:

  • JNI is well-documented and stable for native Rust ↔ Java bindings.
  • Flutter Android's MethodChannel provides simple serialization and error propagation.
  • No need to handle cross-platform memory management at Dart-level.
  • Works well with .so libraries generated from Rust (cargo-ndk, jni crate).

πŸš€ Usage in Flutter #

final proof = await createBbsProof({
  "publicKey": [...],
  "signature": [...],
  "nonce": [...],
  "messages": [...],
});

πŸ“‹ TODOs #

  • ❌ iOS native integration (Obj-C/Swift + Rust static lib)
  • ❌ Fallback to Dart FFI for cross-platform consistency

πŸ’ͺ Build Notes #

To rebuild the plugin after modifying native libs:

flutter clean
flutter pub get
flutter build apk

If your app uses this plugin as a dependency:

dependencies:
  zetrix_vc_flutter: <VERSION>

πŸ™Œ Credits #