dubp.dart 5.70 KiB
import 'dart:async';
import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:isolate/ports.dart';
import "package:system_info/system_info.dart";
import 'ffi.dart' as native;
/// Language
enum Language {
/// English
english,
/// French
french,
}
/// New wallet
class NewWallet {
/// DEWIF: Encrypted wallet
String dewif;
/// Secret code
String pin;
/// Public key
String publicKey;
NewWallet._(this.dewif, this.pin, this.publicKey);
}
/// Secret code type
enum SecretCodeType {
/// Digits
digits,
/// Letters
letters,
}
/// DUBP Rust utilities
///
/// All the functions of this package are static methods of this
/// class `DubpRust`.
class DubpRust {
/// Must be called only once at the start of your application.
static void setup() {
native.store_dart_post_cobject(NativeApi.postCObject);
print("DUBP_RS Setup Done");
}
/// Generate a random mnemonic
static Future<String> genMnemonic({Language language = Language.english}) {
final completer = Completer<String>();
final sendPort =
singleCompletePort<String, String>(completer, callback: _handleErr);
native.gen_mnemonic(
sendPort.nativePort,
language.index,
);
return completer.future;
}
/// Change the secret code that encrypts the `dewif` keypair.
static Future<NewWallet> changeDewifPin({
String currency = "g1",
String dewif,
String oldPin,
SecretCodeType secretCodeType = SecretCodeType.letters,
}) async {