ed448_goldilock 0.0.2 ed448_goldilock: ^0.0.2 copied to clipboard
ed448_goldilock encryption implementation for flutter.
example/lib/main.dart
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:ed448_goldilock/ed448_goldilock.dart';
import 'package:flutter_bip39/bip39.dart';
import 'package:web3dart/crypto.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _keyPair = 'Unknown';
String _pubKey = "Nothing";
String privKey =
"69bb68c3a00a0cd9cbf2cab316476228c758329bbfe0b1759e8634694a9497afea05bcbf24e2aa0627eac4240484bb71de646a9296872a3c0e";
@override
void initState() {
super.initState();
initKeyPairGeneration();
initGetPubKey();
initSignAMessage();
}
Future<void> initKeyPairGeneration() async {
Uint8List seed = mnemonicToSeed(
"spoon inform surface emerge behind affair web clean outdoor wink tunnel foam estate level round blush lab feed amazing tower proud unlock section social");
var a = bytesToHex(seed);
print(bytesToHex(seed));
String keyPair;
try {
keyPair = await Ed448Goldilock.generatePrivateKey(bytesToHex(seed));
print(keyPair);
} on PlatformException {
keyPair = 'Failed to generate keypair.';
}
// 23ba6752fa239fc2f9537bceaf103c46cd90f95221df4fdf530d94e0f1918b002ef508f9a159beb133bf51fb8b18094935b3858fb5cc822e24
// 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(() {
_keyPair = keyPair;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
children: [
Center(
child: Text('key pair is : $_keyPair\n'),
),
Center(
child: Text('pubKey is+' + _pubKey),
),
],
),
),
);
}
Future<void> initGetPubKey() async {
String pubKey;
try {
pubKey = await Ed448Goldilock.getPublicKeyFromPrivateKey(privKey);
} on PlatformException {
pubKey = 'Failed to generate pubKey.';
}
// 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(() {
_pubKey = pubKey;
});
}
Future<void> initSignAMessage() async {
String signedMsg;
try {
signedMsg = await Ed448Goldilock.signWithPrivateKeyNConcatPubkey(
privKey, "666f6f");
} on PlatformException {
signedMsg = 'Failed to generate signedMsg.';
}
// 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;
}
}