durt 0.1.1 durt: ^0.1.1 copied to clipboard
Dart lib for duniter cryptography, useful to integrate Ğ1 libre currency to your app
import 'dart:typed_data';
import 'package:durt/src/hd_wallet.dart';
import 'package:durt/src/dewif.dart';
import 'package:durt/src/cesium_wallet.dart';
void main() {
const String mnemonicLang = 'french';
print('------------------\n HD Wallet example\n------------------\n');
var mnemonic = generateMnemonic(lang: mnemonicLang);
HdWallet _hdWallet = HdWallet.fromMnemonic(mnemonic, lang: mnemonicLang);
Bip32KeyPair _key = Bip32KeyPair(
signingKey: _hdWallet.rootSigningKey, verifyKey: _hdWallet.rootVerifyKey);
Bip32KeyPair derivation0 = _hdWallet.derive(keys: _key, index: 0);
String pubkey0 = _hdWallet.getPubkey(derivation0);
String message = "blabla test";
var signature = _hdWallet.sign(message, keypair: derivation0);
bool isOK = _hdWallet.verifySign(message, signature, keypair: derivation0);
print('Mnemonic: ' + mnemonic);
print('Pubkey 0: ' + pubkey0);
print('Is signature OK ? : ' + isOK.toString());
print('\n------------------\n DEWIF example\n------------------\n');
var _dewif = Dewif();
var _dewifData = _dewif.generateDewif(mnemonic, 'ABCDE', lang: mnemonicLang);
print(_dewifData);
String? decryptedDewif;
try {
decryptedDewif =
_dewif.mnemonicFromDewif(_dewifData, 'ABCDE', lang: mnemonicLang);
print('Unlock: ' + decryptedDewif);
} on ChecksumException {
print('Bad secret code');
} catch (e) {
print(e);
}
print(
'\n------------------\n Cesium wallet generation example\n------------------\n');
// Build Cesium wallet from salt + password
var cesiumWallet =
CesiumWallet('myCesiumID', 'myCesiumPassword'); // Cesium ID + Password
print('Seed: ' + cesiumWallet.seed.toString());
print('Pubkey: ' + cesiumWallet.pubkey);
var signatureCesium = cesiumWallet.sign(message);
bool isOKCesium = cesiumWallet.verifySign(message, signatureCesium);
// Is signature valid ?
print(isOKCesium); //true
print('\n------------------\n Dewif for Cesium wallet\n------------------\n');
var _dewifCesiumData = _dewif.generateCesiumDewif(cesiumWallet.seed, 'FGHIJ');
Uint8List? decryptedCesiumDewif;
try {
decryptedCesiumDewif =
_dewif.cesiumSeedFromDewif(_dewifCesiumData, 'FGHIJ');
print('Unlock: ' + decryptedCesiumDewif.toString());
} on ChecksumException {
print('Bad secret code');
} catch (e) {
print(e);
}
// Rebuild Cesium wallet, but this time from seed
var reCesiumWallet = CesiumWallet.fromSeed(decryptedCesiumDewif!);
print('Pubkey: ' + reCesiumWallet.pubkey);
}