Spawn isolate for unlocking Dewif: Very slower as non isolate, so discard for now
This commit is contained in:
parent
224016d39e
commit
31bfc87d00
|
@ -2,6 +2,7 @@ import 'dart:io';
|
||||||
import 'package:crypto/crypto.dart';
|
import 'package:crypto/crypto.dart';
|
||||||
import 'package:durt/durt.dart';
|
import 'package:durt/durt.dart';
|
||||||
import 'package:fast_base58/fast_base58.dart';
|
import 'package:fast_base58/fast_base58.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:gecko/globals.dart';
|
import 'package:gecko/globals.dart';
|
||||||
|
@ -25,57 +26,19 @@ class WalletOptionsProvider with ChangeNotifier {
|
||||||
|
|
||||||
Future<NewWallet> get badWallet => null;
|
Future<NewWallet> get badWallet => null;
|
||||||
|
|
||||||
String _getPubkeyFromDewif(
|
Future<String> readLocalWallet(
|
||||||
String _dewif, _pin, int _pinLenght, int derivation) {
|
context, WalletData _wallet, String _pin, int _pinLenght) async {
|
||||||
RegExp regExp = RegExp(
|
|
||||||
r'^[A-Z0-9]+$',
|
|
||||||
caseSensitive: false,
|
|
||||||
multiLine: false,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (regExp.hasMatch(_pin) == true && _pin.length == _pinLenght) {
|
|
||||||
} else {
|
|
||||||
return 'false';
|
|
||||||
}
|
|
||||||
if (derivation != -1) {
|
|
||||||
try {
|
|
||||||
final _wallet = HdWallet.fromDewif(_dewif, _pin);
|
|
||||||
pubkey.text = _wallet.getPubkey(derivation);
|
|
||||||
log.d(pubkey.text);
|
|
||||||
notifyListeners();
|
|
||||||
|
|
||||||
return pubkey.text;
|
|
||||||
} catch (e) {
|
|
||||||
log.w('Bad PIN code !\n' + e);
|
|
||||||
notifyListeners();
|
|
||||||
|
|
||||||
return 'false';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
pubkey.text = CesiumWallet.fromDewif(_dewif, _pin).pubkey;
|
|
||||||
notifyListeners();
|
|
||||||
return pubkey.text;
|
|
||||||
} catch (e) {
|
|
||||||
log.w('Bad PIN code !\n' + e);
|
|
||||||
notifyListeners();
|
|
||||||
|
|
||||||
return 'false';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String readLocalWallet(
|
|
||||||
context, WalletData _wallet, String _pin, int _pinLenght) {
|
|
||||||
isWalletUnlock = false;
|
isWalletUnlock = false;
|
||||||
try {
|
try {
|
||||||
String _localDewif = chestBox.get(_wallet.chest).dewif;
|
String _localDewif = chestBox.get(_wallet.chest).dewif;
|
||||||
String _localPubkey;
|
|
||||||
|
|
||||||
if ((_localPubkey = _getPubkeyFromDewif(
|
final _pubkey = await compute(
|
||||||
_localDewif, _pin, _pinLenght, _wallet.derivation)) !=
|
_getPubkeyFromDewif,
|
||||||
'false') {
|
GetPubkeyFromDewifArgs(
|
||||||
pubkey.text = _localPubkey;
|
_localDewif, _pin, _pinLenght, _wallet.derivation));
|
||||||
|
|
||||||
|
if (_pubkey != 'false') {
|
||||||
|
pubkey.text = _pubkey;
|
||||||
isWalletUnlock = true;
|
isWalletUnlock = true;
|
||||||
log.d(pubkey.text);
|
log.d(pubkey.text);
|
||||||
return _localDewif;
|
return _localDewif;
|
||||||
|
@ -239,3 +202,48 @@ class WalletOptionsProvider with ChangeNotifier {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String _getPubkeyFromDewif(GetPubkeyFromDewifArgs parseArgs) {
|
||||||
|
String pubkey;
|
||||||
|
RegExp regExp = RegExp(
|
||||||
|
r'^[A-Z0-9]+$',
|
||||||
|
caseSensitive: false,
|
||||||
|
multiLine: false,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (regExp.hasMatch(parseArgs.pin) == true &&
|
||||||
|
parseArgs.pin.length == parseArgs.pinLenght) {
|
||||||
|
} else {
|
||||||
|
return 'false';
|
||||||
|
}
|
||||||
|
if (parseArgs.derivation != -1) {
|
||||||
|
try {
|
||||||
|
final _wallet = HdWallet.fromDewif(parseArgs.dewif, parseArgs.pin);
|
||||||
|
pubkey = _wallet.getPubkey(parseArgs.derivation);
|
||||||
|
log.d(pubkey);
|
||||||
|
|
||||||
|
return pubkey;
|
||||||
|
} catch (e) {
|
||||||
|
log.w('Bad PIN code !\n' + e);
|
||||||
|
|
||||||
|
return 'false';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
pubkey = CesiumWallet.fromDewif(parseArgs.dewif, parseArgs.pin).pubkey;
|
||||||
|
return pubkey;
|
||||||
|
} catch (e) {
|
||||||
|
log.w('Bad PIN code !\n' + e);
|
||||||
|
|
||||||
|
return 'false';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GetPubkeyFromDewifArgs {
|
||||||
|
final String dewif;
|
||||||
|
final String pin;
|
||||||
|
final int pinLenght;
|
||||||
|
final int derivation;
|
||||||
|
GetPubkeyFromDewifArgs(this.dewif, this.pin, this.pinLenght, this.derivation);
|
||||||
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ class UnlockingWallet extends StatelessWidget {
|
||||||
onCompleted: (_pin) async {
|
onCompleted: (_pin) async {
|
||||||
log.d("Completed");
|
log.d("Completed");
|
||||||
_myWalletProvider.pinCode = _pin;
|
_myWalletProvider.pinCode = _pin;
|
||||||
final String resultWallet = _walletOptions.readLocalWallet(
|
final String resultWallet = await _walletOptions.readLocalWallet(
|
||||||
context, wallet, _pin.toUpperCase(), _pinLenght);
|
context, wallet, _pin.toUpperCase(), _pinLenght);
|
||||||
// _myWalletProvider.pinCode = _pin.toUpperCase();
|
// _myWalletProvider.pinCode = _pin.toUpperCase();
|
||||||
_myWalletProvider.pinLenght = _pinLenght;
|
_myWalletProvider.pinLenght = _pinLenght;
|
||||||
|
|
Loading…
Reference in New Issue