mpc_dart 0.1.1 copy "mpc_dart: ^0.1.1" to clipboard
mpc_dart: ^0.1.1 copied to clipboard

outdated

Safeamtrix mpc dart package, ecdsa and bls supported.

example/lib/main.dart

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<KeyPair> ecdsaResult = [];
  String ecdsaAddress = '';
  KeyPair? ecdsaKey;
  String ecdsaSignature = '';
  List<KeyPair> blsResult = [];
  String blsAddress = '';
  KeyPair? blsKey;
  String blsSignature = '';
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DefaultTabController(
        length: 2,
        child: Scaffold(
          appBar: AppBar(
              title: const Text('Plugin example app'),
              bottom:
                  const TabBar(tabs: [Tab(text: 'Ecdsa'), Tab(text: 'Bls')])),
          body: TabBarView(
            children: [
              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                mainAxisSize: MainAxisSize.min,
                children: [
                  TextButton(
                      onPressed: () => _generate(), child: const Text('Generate')),
                  Text(ecdsaResult.toString()),
                  TextButton(onPressed: _address, child: const Text('Address')),
                  Text(ecdsaAddress),
                  TextButton(onPressed: _recover, child: const Text('Recover')),
                  Text(ecdsaKey?.toJson() ?? 'Error'),
                  TextButton(onPressed: _sign, child: const Text('Sign')),
                  Text(ecdsaSignature)
                ],
              ),
              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                mainAxisSize: MainAxisSize.min,
                children: [
                  TextButton(
                      onPressed: () => _generate(isEcdsa: false),
                      child: const Text('Generate')),
                  Text(blsResult.toString()),
                  TextButton(
                      onPressed: () => _address(isEcdsa: false),
                      child: const Text('Address')),
                  Text(blsAddress),
                  TextButton(
                      onPressed: () => _recover(isEcdsa: false),
                      child: const Text('Recover')),
                  Text(blsKey?.toJson() ?? 'Error'),
                  TextButton(
                      onPressed: () => _sign(isEcdsa: false),
                      child: const Text('Sign')),
                  Text(blsSignature)
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }

  _generate({isEcdsa = true}) {
    setState(() {
      if (isEcdsa) {
        ecdsaResult = Ecdsa.generate(1, 3);
      } else {
        blsResult = Bls.generate(1, 3);
      }
    });
    return null;
  }

  _address({isEcdsa = true}) {
    setState(() {
      if (isEcdsa) {
        ecdsaAddress = Ecdsa.address(ecdsaResult[0]);
      } else {
        blsAddress = Bls.address(blsResult[0]);
      }
    });
  }

  _recover({isEcdsa = true}) {
    setState(() {
      if (isEcdsa) {
        ecdsaKey = Ecdsa.recover([ecdsaResult[0], ecdsaResult[1]]);
      } else {
        blsKey = Bls.recover([blsResult[0], blsResult[1]]);
      }
    });
  }

  _sign({isEcdsa = true}) {
    setState(() {
      final msgs = [List<int>.filled(32, 1)];
      if (isEcdsa) {
        ecdsaSignature = Ecdsa.sign(SignParams(msgs, 1, ecdsaResult));
      } else {
        blsSignature = Bls.sign(SignParams(msgs, 1, blsResult));
      }
    });
  }
}
2
likes
0
points
92
downloads

Publisher

unverified uploader

Weekly Downloads

Safeamtrix mpc dart package, ecdsa and bls supported.

Homepage

License

unknown (license)

Dependencies

ffi, flutter, plugin_platform_interface

More

Packages that depend on mpc_dart