Skip to content
Snippets Groups Projects
Commit 8234025f authored by fred's avatar fred
Browse files

miam

parents c7d5d26b 84e05b9a
No related branches found
No related tags found
No related merge requests found
//filename: lib/data/models/cesium_wallet.dart
import 'package:cesium_js_dart/cesium_js_dart.dart';
class CesiumWallet {
CesiumWallet.fromSecrets(String secret1, String secret2) {
// Initialize the wallet from secrets using cesium_js_dart
final Uint8List secret1Bytes = Base58Decode(secret1);
final Uint8List secret2Bytes = Base58Decode(secret2);
final Uint8List seed = Uint8List(64);
seed.setRange(0, 32, secret1Bytes);
seed.setRange(32, 64, secret2Bytes);
final KeyPair keyPair = KeyPair.fromSeed(seed);
// You can now use the keyPair to sign transactions, derive the public key, etc.
// For example:
// final String pubKey = keyPair.publicKey.toBase58();
// final String signature = keyPair.sign(message);
}
// Other methods and properties
// ...
}
// lib/g1/astroid_helper.dart
import 'package:encrypt/encrypt.dart' as encrypt;
import 'package:tuple/tuple.dart';
import '../g1/g1_helper.dart';
Future<Tuple2<String, String>?> decryptAstroID(
String disco, String password) async {
......
......@@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:durt/durt.dart';
import 'package:flutter/foundation.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tuple/tuple.dart';
import 'data/models/cesium_card.dart';
import 'data/models/credit_card_themes.dart';
......@@ -68,8 +69,7 @@ class SharedPreferencesHelper with ChangeNotifier {
final Tuple2<String, String>? secrets =
await decryptAstroID(disco, password);
if (secrets != null) {
final CesiumWallet wallet =
CesiumWallet.fromSecrets(secrets.item1, secrets.item2);
final CesiumWallet wallet = CesiumWallet(secrets.item1, secrets.item2);
final CesiumCard card =
buildCesiumCard(seed: '', pubKey: wallet.pubkey);
addCesiumCard(card);
......
// ignore_for_file: use_build_context_synchronously
import 'dart:async';
import 'package:durt/durt.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../data/models/cesium_card.dart';
import 'package:ndef/utilities.dart';
import 'qr_manager.dart';
import 'package:tuple/tuple.dart';
import '../../../data/models/contact.dart';
......@@ -132,7 +137,6 @@ Future<bool> payWithRetry(
'Node used: ${result != null && result.node != null ? result.node!.url : 'unknown'}');
if (result.message == 'success') {
paymentCubit.sent();
// ignore: use_build_context_synchronously
if (!context.mounted) {
return true;
}
......@@ -288,10 +292,34 @@ Future<void> importAstroID(BuildContext context) async {
}
// Demander à l'utilisateur de saisir le mot de passe unique ($UNIQID)
final String? password = await showTextInputDialog(
final String? password = await showDialog<String>(
context: context,
title: 'Saisir le mot de passe',
hint: 'Mot de passe unique',
builder: (BuildContext context) {
String passwordLocal = '';
return AlertDialog(
title: const Text('Saisir le mot de passe'),
content: TextField(
decoration: const InputDecoration(hintText: 'Mot de passe unique'),
onChanged: (String value) {
// Handle password input
passwordLocal = value;
},
),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.of(context).pop(null),
child: const Text('Cancel'),
),
TextButton(
onPressed: () {
// Handle password submission
Navigator.of(context).pop(passwordLocal);
},
child: const Text('OK'),
),
],
);
},
);
if (password == null || password.isEmpty) {
return;
......@@ -307,17 +335,17 @@ Future<void> importAstroID(BuildContext context) async {
}
// Initialiser un nouveau portefeuille CesiumWallet avec les secrets déchiffrés
final CesiumWallet wallet =
CesiumWallet.fromSecrets(secrets.item1, secrets.item2);
final CesiumWallet wallet = CesiumWallet(secrets.item1, secrets.item2);
// Sauvegarder ce portefeuille
await SharedPreferencesHelper().saveWallet(wallet);
// Add the AstroID wallet to the storage
SharedPreferencesHelper().importAstroIDWallet(disco, password);
final CesiumCard card = SharedPreferencesHelper().buildCesiumCard(
seed: wallet.seed.toHexString(), pubKey: wallet.pubkey);
// Mettre à jour l'état de l'app
context.read<AppState>().setWallet(wallet);
// Select the AstroID wallet as the current wallet
SharedPreferencesHelper().selectCurrentWallet(card);
// Rediriger vers l'écran principal
// ignore: use_build_context_synchronously
Navigator.of(context).pushReplacementNamed('/');
} catch (e, stacktrace) {
logger('Erreur importation AstroID: $e');
......
// ignore_for_file: use_build_context_synchronously
import 'package:durt/durt.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
<<<<<<< HEAD
import 'package:tuple/tuple.dart';
=======
import 'package:ndef/ndef.dart';
import '../../data/models/cesium_card.dart';
import '../logger.dart';
import 'package:tuple/tuple.dart';
>>>>>>> 84e05b9aa8f4188ec9d24643d9d17d37deb02e10
import '../tutorial.dart';
import '../widgets/card_drawer.dart';
import '../widgets/second_screen/card_terminal.dart';
......@@ -8,7 +19,6 @@ import '../widgets/second_screen/second_tutorial.dart';
import '../../g1/astroid_helper.dart';
import '../../g1/api.dart';
import '../../shared_prefs_helper.dart';
import '../pay_helper.dart';
import '../qr_manager_mobile.dart';
import '../ui_helpers.dart';
......@@ -36,11 +46,36 @@ class _SecondScreenState extends State<SecondScreen> {
return;
}
// Ask the user for the unique password
final String? password = await showTextInputDialog(
// Demander à l'utilisateur de saisir le mot de passe unique ($UNIQID)
final String? password = await showDialog<String>(
context: context,
title: 'Enter Password',
hint: 'Unique Password',
builder: (BuildContext context) {
String passwordLocal = '';
return AlertDialog(
title: const Text('Saisir le mot de passe'),
content: TextField(
decoration:
const InputDecoration(hintText: 'Mot de passe unique'),
onChanged: (String value) {
// Handle password input
passwordLocal = value;
},
),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.of(context).pop(null),
child: const Text('Cancel'),
),
TextButton(
onPressed: () {
// Handle password submission
Navigator.of(context).pop(passwordLocal);
},
child: const Text('OK'),
),
],
);
},
);
if (password == null || password.isEmpty) {
return;
......@@ -55,17 +90,25 @@ class _SecondScreenState extends State<SecondScreen> {
return;
}
// Initialize a new CesiumWallet with the decrypted secrets
final CesiumWallet astroIDWallet =
CesiumWallet.fromSecrets(secrets.item1, secrets.item2);
// Get the currently loaded wallet
final CesiumWallet currentWallet =
await SharedPreferencesHelper().getWallet();
// Initialize a new CesiumWallet with the decrypted secrets
final CesiumWallet astroIDWallet =
CesiumWallet(secrets.item1, secrets.item2);
// Add the AstroID wallet to the storage
SharedPreferencesHelper().importAstroIDWallet(disco, password);
final CesiumCard card = SharedPreferencesHelper().buildCesiumCard(
seed: astroIDWallet.seed.toHexString(), pubKey: astroIDWallet.pubkey);
// Select the AstroID wallet as the current wallet
SharedPreferencesHelper().selectCurrentWallet(card);
// Make a payment from the AstroID wallet to the current wallet
final PayResult result = await payWithGVA(
to: [currentWallet.pubkey],
to: <String>[currentWallet.pubkey],
amount: 100.0, // Specify the amount to transfer
comment: 'Payment from AstroID',
);
......@@ -76,9 +119,6 @@ class _SecondScreenState extends State<SecondScreen> {
showAlertDialog(
context, 'Error', 'Payment from AstroID failed: ${result.message}');
}
// Discard the AstroID wallet instance
astroIDWallet.dispose();
} catch (e, stacktrace) {
logger('Error during AstroID payment: $e');
logger(stacktrace.toString());
......
......@@ -404,9 +404,16 @@ packages:
durt:
dependency: "direct main"
description:
<<<<<<< HEAD
path: "../durt"
relative: true
source: path
=======
name: durt
sha256: "29e4a1adaea1dfedff4d9237580b414ca5fe621a7a131b5fa129b9824365c938"
url: "https://pub.dev"
source: hosted
>>>>>>> 84e05b9aa8f4188ec9d24643d9d17d37deb02e10
version: "0.1.8"
easy_debounce:
dependency: "direct main"
......
......@@ -38,9 +38,9 @@ dependencies:
qr_flutter: ^4.0.0
introduction_screen: ^3.1.6
responsive_framework: ^0.2.0
#durt: ^0.1.7
durt:
path: ../durt
durt: ^0.1.7
# durt:
# path: ../durt
#git:
# url: https://git.duniter.org/vjrj/durt
flutter_neumorphic:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment