dvote 0.2.3 copy "dvote: ^0.2.3" to clipboard
dvote: ^0.2.3 copied to clipboard

outdated

Flutter plugin to allow native mobile apps to interact with Vocdoni decentralized votes.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:dvote/dvote.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _mnemonic = '(mnemonic)';
  String _privKey = '(priv key)';
  String _pubKey = '(pub key)';
  String _address = '(addr)';
  String _messageToSign = "hello";
  String _privKeyToSign =
      "fad9c8855b740a0b7ed4c221dbad0f33a83a49cad6b3fe8d5817ac83d38b6a19";
  String _publicKey = "0x049a7df67f79246283fdc93af76d4f8cdd62c4886e8cd870944e817dd0b97934fdd7719d0810951e03418205868a5c1b40b192451367f28e0088dd75e15de40c05";
  String _signature = "-";
  bool _validSignature = false;
  String _message = 'This is the super secret text message';
  String _passphrase = "One key to rule them all";
  String _cipherText = "-";
  String _decryptedMessage = "-";

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String mnemonic, privKey, pubKey, addr;
    String signature;
    bool valid;
    String cipherText, decryptedText;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      mnemonic = await Dvote.generateMnemonic(size: 192);
      privKey = await Dvote.mnemonicToPrivateKey(mnemonic);
      pubKey = await Dvote.mnemonicToPublicKey(mnemonic);
      addr = await Dvote.mnemonicToAddress(mnemonic);

      signature = await Dvote.signString(_messageToSign, _privKeyToSign);
      valid = await Dvote.verifySignature(signature, _messageToSign, _publicKey);

      cipherText = await Dvote.encryptString(_message, _passphrase);
      decryptedText = await Dvote.decryptString(cipherText, _passphrase);
    } on PlatformException {
      mnemonic = "(err)";
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _mnemonic = mnemonic;
      _privKey = privKey;
      _pubKey = pubKey;
      _address = addr;

      _signature = signature;
      _validSignature = valid ?? false;

      _cipherText = cipherText;
      _decryptedMessage = decryptedText;
    });
  }

  @override
  Widget build(BuildContext context) {
    final signingData =
        "Signing '$_messageToSign' with $_privKeyToSign:\n\n$_signature\n\nThe signature is ${_validSignature ? "valid" : "not valid"}";
    final encryptionData = '''Original message: \n > $_message\n
Encryption key: \n > $_passphrase\n
Encrypted message: \n > $_cipherText\n
Decrypted message: \n > $_decryptedMessage''';

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('DVote plugin example'),
        ),
        body: ListView(
          children: <Widget>[
            Padding(
              padding: EdgeInsets.all(16),
              child: Column(
                children: <Widget>[
                  Text("HD WALLET:"),
                  SizedBox(height: 30),
                  Text('Mnemonic: \n$_mnemonic'),
                  SizedBox(height: 15),
                  Text('Private key: \n$_privKey'),
                  SizedBox(height: 15),
                  Text('Public key: \n$_pubKey'),
                  SizedBox(height: 15),
                  Text('Address: \n$_address'),
                ],
              ),
            ),
            Divider(),
            Padding(
              padding: EdgeInsets.all(16),
              child: Column(
                children: <Widget>[
                  Text("SIGNING:"),
                  SizedBox(height: 30),
                  Text(signingData),
                ],
              ),
            ),
            Divider(),
            Padding(
              padding: EdgeInsets.all(16),
              child: Column(
                children: <Widget>[
                  Text("ENCRYPTION:"),
                  SizedBox(height: 30),
                  Text(encryptionData),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
2
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Flutter plugin to allow native mobile apps to interact with Vocdoni decentralized votes.

Homepage
Repository (GitLab)
View/report issues

Documentation

Documentation

License

unknown (LICENSE)

Dependencies

flutter, http, web_socket_channel

More

Packages that depend on dvote