zetrix_vc_flutter 0.0.2
zetrix_vc_flutter: ^0.0.2 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!;
}
3. Link Native .so Library Automatically
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
.solibraries generated from Rust (cargo-ndk,jnicrate).
๐ 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
- โ Publish to pub.dev
๐ช 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>