Skip to content

Commit

Permalink
save wallet private key hex
Browse files Browse the repository at this point in the history
bumped windows version
  • Loading branch information
oliverbytes committed Aug 4, 2022
1 parent 18d3d82 commit d60290a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/core/persistence/persistence.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Persistence extends GetxController with ConsoleMixin {
final wallet = ''.val('wallet');
final walletPassword = ''.val('wallet-password');
final walletSignature = ''.val('wallet-signature');
final walletPrivateKeyHex = ''.val('wallet-private-key-hex');
final walletAddress = ''.val('wallet-address');
// GENERAL
final localeCode = 'en'.val('locale-code');
Expand Down
8 changes: 5 additions & 3 deletions lib/features/unlock/unlock_screen.controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,19 @@ class UnlockScreenController extends GetxController
return Get.offNamedUntil(Routes.main, (route) => false);
}

if (Persistence.to.walletSignature.val.isNotEmpty) {
if (Persistence.to.walletSignature.val.isNotEmpty &&
Persistence.to.walletPrivateKeyHex.val.isNotEmpty) {
return _done();
}

// temporary to migrate users from prior v0.6.0
Timer.periodic(1.seconds, (timer) async {
if (Persistence.to.walletSignature.val.isNotEmpty) {
if (Persistence.to.walletSignature.val.isNotEmpty &&
Persistence.to.walletPrivateKeyHex.val.isNotEmpty) {
timer.cancel();
return _done();
} else {
console.info('wallet signature still not present');
console.info('wallet still not saved to persistence');
}
});
}
Expand Down
12 changes: 8 additions & 4 deletions lib/features/wallet/wallet.service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class WalletService extends GetxService with ConsoleMixin {

bool get isSaved => Persistence.to.wallet.val.isNotEmpty;

Uint8List get privateKey => wallet!.privateKey.privateKey;
String get privateKeyHex => HEX.encode(privateKey);
// Uint8List get privateKey => wallet!.privateKey.privateKey;
// String get privateKeyHex => HEX.encode(privateKey);

EthereumAddress get address => wallet!.privateKey.address;

Expand Down Expand Up @@ -136,7 +136,9 @@ class WalletService extends GetxService with ConsoleMixin {
Uint8List? privateKey_,
}) async {
final messageBytes = Uint8List.fromList(utf8.encode(message));
final privateKeyHex = HEX.encode(privateKey_ ?? privateKey);
final privateKeyHex = privateKey_ != null
? HEX.encode(privateKey_)
: Persistence.to.walletPrivateKeyHex.val;
// console.info('message: $message');

final signature = await compute(signMessage, {
Expand Down Expand Up @@ -192,6 +194,8 @@ class WalletService extends GetxService with ConsoleMixin {
// generate cipher key
final signature = await sign(kCipherKeySignatureMessage);
Persistence.to.walletSignature.val = signature;
Persistence.to.walletPrivateKeyHex.val =
HEX.encode(wallet!.privateKey.privateKey);
// // from the first 32 bits of the signature
// cipherKey = Uint8List.fromList(utf8.encode(signature).sublist(0, 32));

Expand Down Expand Up @@ -235,7 +239,7 @@ class WalletService extends GetxService with ConsoleMixin {
e.readOnly = true;
return e;
} else if (e.identifier == 'private_key') {
e.data.value = privateKeyHex;
e.data.value = Persistence.to.walletPrivateKeyHex.val;
e.readOnly = true;
return e;
} else if (e.identifier == 'address') {
Expand Down
8 changes: 6 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ dependencies:
# CRYTPOGRAPHY + SECURITY
secrets:
path: ../secrets
alchemy_web3:
git: https://github.com/oliverbytes/alchemy_web3.git
# alchemy_web3:
# git: https://github.com/oliverbytes/alchemy_web3.git
alchemy_web3:
git:
url: https://github.com/oliverbytes/alchemy_web3.git
ref: ee496edc0bc0a1d64d7cc5c7ea8662b4b8d4f0fc
web3dart: ^2.3.5 # Ethereum
eth_sig_util: ^0.0.9 # Ethereum signature
bip39: ^1.0.6 # Mnemonic Seed Phrases
Expand Down
4 changes: 2 additions & 2 deletions windows/runner/Runner.rc
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ IDI_APP_ICON ICON "resources\\app_icon.ico"
#ifdef FLUTTER_BUILD_NUMBER
#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
#else
#define VERSION_AS_NUMBER 0,6,032,0
#define VERSION_AS_NUMBER 0,6,033,0
#endif

#ifdef FLUTTER_BUILD_NAME
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME
#else
#define VERSION_AS_STRING "0.6.0+32"
#define VERSION_AS_STRING "0.6.0+33"
#endif

VS_VERSION_INFO VERSIONINFO
Expand Down

0 comments on commit d60290a

Please sign in to comment.