Skip to content
Snippets Groups Projects
Select Git revision
  • 7b2e40ddf4821b12f9925fa3521ac1b1a2c79e84
  • master default protected
  • ed25519_hd_key-lib
  • 0.1.9
  • 0.1.8
  • 0.1.7
6 results

durt_example.dart

Blame
  • durt_example.dart 2.50 KiB
    import 'dart:typed_data';
    
    import 'package:durt/src/crypto/hd_wallet.dart';
    import 'package:durt/src/crypto/dewif.dart';
    import 'package:durt/src/crypto/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());