mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-08 03:49:43 +00:00
add support for weird polyseed
This commit is contained in:
parent
d5decd2406
commit
312e2859c7
9 changed files with 159 additions and 13 deletions
|
@ -46,7 +46,7 @@ abstract class WalletBase<BalanceType extends Balance, HistoryType extends Trans
|
||||||
|
|
||||||
String? get hexSeed => null;
|
String? get hexSeed => null;
|
||||||
|
|
||||||
String get passphrase => "";
|
String? get passphrase => null;
|
||||||
|
|
||||||
Object get keys;
|
Object get keys;
|
||||||
|
|
||||||
|
|
|
@ -34,16 +34,22 @@ String getSeed() {
|
||||||
final cakepolyseed =
|
final cakepolyseed =
|
||||||
monero.Wallet_getCacheAttribute(wptr!, key: "cakewallet.seed");
|
monero.Wallet_getCacheAttribute(wptr!, key: "cakewallet.seed");
|
||||||
final cakepassphrase = getPassphrase();
|
final cakepassphrase = getPassphrase();
|
||||||
if (cakepassphrase != "") {
|
|
||||||
final lang = PolyseedLang.getByPhrase(cakepassphrase);
|
final weirdPolyseed = monero.Wallet_getPolyseed(wptr!, passphrase: cakepassphrase);
|
||||||
final coin = PolyseedCoin.POLYSEED_MONERO;
|
if (weirdPolyseed != "") return weirdPolyseed;
|
||||||
final ps = Polyseed.decode(cakepolyseed, lang, coin);
|
|
||||||
if (ps.isEncrypted) return ps.encode(lang, coin);
|
|
||||||
}
|
|
||||||
if (cakepolyseed != "") {
|
if (cakepolyseed != "") {
|
||||||
|
if (cakepassphrase != "") {
|
||||||
|
final lang = PolyseedLang.getByPhrase(cakepassphrase);
|
||||||
|
final coin = PolyseedCoin.POLYSEED_MONERO;
|
||||||
|
final ps = Polyseed.decode(cakepolyseed, lang, coin);
|
||||||
|
if (ps.isEncrypted) return ps.encode(lang, coin);
|
||||||
|
ps.crypt(getPassphrase());
|
||||||
|
return ps.encode(lang, coin);
|
||||||
|
}
|
||||||
return cakepolyseed;
|
return cakepolyseed;
|
||||||
}
|
}
|
||||||
final legacy = getSeedLegacy("English");
|
final legacy = getSeedLegacy(null);
|
||||||
return legacy;
|
return legacy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,6 +157,47 @@ void restoreWalletFromKeysSync(
|
||||||
openedWalletsByPath[path] = wptr!;
|
openedWalletsByPath[path] = wptr!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// English only, because normalization.
|
||||||
|
void restoreWalletFromPolyseedWithOffset(
|
||||||
|
{required String path,
|
||||||
|
required String password,
|
||||||
|
required String seed,
|
||||||
|
required String seedOffset,
|
||||||
|
required String language,
|
||||||
|
int nettype = 0}) {
|
||||||
|
|
||||||
|
txhistory = null;
|
||||||
|
final newWptr = monero.WalletManager_createWalletFromPolyseed(
|
||||||
|
wmPtr,
|
||||||
|
path: path,
|
||||||
|
password: password,
|
||||||
|
networkType: nettype,
|
||||||
|
mnemonic: seed,
|
||||||
|
seedOffset: seedOffset,
|
||||||
|
newWallet: true, // safe to remove
|
||||||
|
restoreHeight: 0,
|
||||||
|
kdfRounds: 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
final status = monero.Wallet_status(newWptr);
|
||||||
|
|
||||||
|
if (status != 0) {
|
||||||
|
final err = monero.Wallet_errorString(newWptr);
|
||||||
|
print("err: $err");
|
||||||
|
throw WalletRestoreFromKeysException(message: err);
|
||||||
|
}
|
||||||
|
|
||||||
|
wptr = newWptr;
|
||||||
|
|
||||||
|
monero.Wallet_setCacheAttribute(wptr!, key: "cakewallet.seed", value: seed);
|
||||||
|
|
||||||
|
storeSync();
|
||||||
|
|
||||||
|
openedWalletsByPath[path] = wptr!;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void restoreWalletFromSpendKeySync(
|
void restoreWalletFromSpendKeySync(
|
||||||
{required String path,
|
{required String path,
|
||||||
required String password,
|
required String password,
|
||||||
|
|
|
@ -332,6 +332,28 @@ class MoneroWalletService extends WalletService<
|
||||||
{PolyseedCoin coin = PolyseedCoin.POLYSEED_MONERO,
|
{PolyseedCoin coin = PolyseedCoin.POLYSEED_MONERO,
|
||||||
int? overrideHeight,
|
int? overrideHeight,
|
||||||
String? passphrase}) async {
|
String? passphrase}) async {
|
||||||
|
|
||||||
|
if (polyseed.isEncrypted == false &&
|
||||||
|
(passphrase??'') != "") {
|
||||||
|
// Fallback to the different passphrase offset method, when a passphrase
|
||||||
|
// was provided but the polyseed is not encrypted.
|
||||||
|
monero_wallet_manager.restoreWalletFromPolyseedWithOffset(
|
||||||
|
path: path,
|
||||||
|
password: password,
|
||||||
|
seed: polyseed.encode(lang, coin),
|
||||||
|
seedOffset: passphrase??'',
|
||||||
|
language: "English");
|
||||||
|
|
||||||
|
final wallet = MoneroWallet(
|
||||||
|
walletInfo: walletInfo,
|
||||||
|
unspentCoinsInfo: unspentCoinsInfoSource,
|
||||||
|
password: password,
|
||||||
|
);
|
||||||
|
await wallet.init();
|
||||||
|
|
||||||
|
return wallet;
|
||||||
|
}
|
||||||
|
|
||||||
if (polyseed.isEncrypted) polyseed.crypt(passphrase ?? '');
|
if (polyseed.isEncrypted) polyseed.crypt(passphrase ?? '');
|
||||||
|
|
||||||
final height = overrideHeight ??
|
final height = overrideHeight ??
|
||||||
|
|
|
@ -6,6 +6,7 @@ import 'package:cw_wownero/api/account_list.dart';
|
||||||
import 'package:cw_wownero/api/exceptions/setup_wallet_exception.dart';
|
import 'package:cw_wownero/api/exceptions/setup_wallet_exception.dart';
|
||||||
import 'package:monero/wownero.dart' as wownero;
|
import 'package:monero/wownero.dart' as wownero;
|
||||||
import 'package:mutex/mutex.dart';
|
import 'package:mutex/mutex.dart';
|
||||||
|
import 'package:polyseed/polyseed.dart';
|
||||||
|
|
||||||
int getSyncingHeight() {
|
int getSyncingHeight() {
|
||||||
// final height = wownero.WOWNERO_cw_WalletListener_height(getWlptr());
|
// final height = wownero.WOWNERO_cw_WalletListener_height(getWlptr());
|
||||||
|
@ -31,10 +32,23 @@ bool isNewTransactionExist() {
|
||||||
String getFilename() => wownero.Wallet_filename(wptr!);
|
String getFilename() => wownero.Wallet_filename(wptr!);
|
||||||
|
|
||||||
String getSeed() {
|
String getSeed() {
|
||||||
// wownero.Wallet_setCacheAttribute(wptr!, key: "cakewallet.seed", value: seed);
|
// monero.Wallet_setCacheAttribute(wptr!, key: "cakewallet.seed", value: seed);
|
||||||
final cakepolyseed =
|
final cakepolyseed =
|
||||||
wownero.Wallet_getCacheAttribute(wptr!, key: "cakewallet.seed");
|
wownero.Wallet_getCacheAttribute(wptr!, key: "cakewallet.seed");
|
||||||
|
final cakepassphrase = getPassphrase();
|
||||||
|
|
||||||
|
final weirdPolyseed = wownero.Wallet_getPolyseed(wptr!, passphrase: cakepassphrase);
|
||||||
|
if (weirdPolyseed != "") return weirdPolyseed;
|
||||||
|
|
||||||
if (cakepolyseed != "") {
|
if (cakepolyseed != "") {
|
||||||
|
if (cakepassphrase != "") {
|
||||||
|
final lang = PolyseedLang.getByPhrase(cakepassphrase);
|
||||||
|
final coin = PolyseedCoin.POLYSEED_MONERO;
|
||||||
|
final ps = Polyseed.decode(cakepolyseed, lang, coin);
|
||||||
|
if (ps.isEncrypted) return ps.encode(lang, coin);
|
||||||
|
ps.crypt(getPassphrase());
|
||||||
|
return ps.encode(lang, coin);
|
||||||
|
}
|
||||||
return cakepolyseed;
|
return cakepolyseed;
|
||||||
}
|
}
|
||||||
final legacy = getSeedLegacy(null);
|
final legacy = getSeedLegacy(null);
|
||||||
|
|
|
@ -175,6 +175,47 @@ void restoreWalletFromKeysSync(
|
||||||
openedWalletsByPath[path] = wptr!;
|
openedWalletsByPath[path] = wptr!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// English only, because normalization.
|
||||||
|
void restoreWalletFromPolyseedWithOffset(
|
||||||
|
{required String path,
|
||||||
|
required String password,
|
||||||
|
required String seed,
|
||||||
|
required String seedOffset,
|
||||||
|
required String language,
|
||||||
|
int nettype = 0}) {
|
||||||
|
|
||||||
|
txhistory = null;
|
||||||
|
final newWptr = wownero.WalletManager_createWalletFromPolyseed(
|
||||||
|
wmPtr,
|
||||||
|
path: path,
|
||||||
|
password: password,
|
||||||
|
networkType: nettype,
|
||||||
|
mnemonic: seed,
|
||||||
|
seedOffset: seedOffset,
|
||||||
|
newWallet: true, // safe to remove
|
||||||
|
restoreHeight: 0,
|
||||||
|
kdfRounds: 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
final status = wownero.Wallet_status(newWptr);
|
||||||
|
|
||||||
|
if (status != 0) {
|
||||||
|
final err = wownero.Wallet_errorString(newWptr);
|
||||||
|
print("err: $err");
|
||||||
|
throw WalletRestoreFromKeysException(message: err);
|
||||||
|
}
|
||||||
|
|
||||||
|
wptr = newWptr;
|
||||||
|
|
||||||
|
wownero.Wallet_setCacheAttribute(wptr!, key: "cakewallet.seed", value: seed);
|
||||||
|
|
||||||
|
storeSync();
|
||||||
|
|
||||||
|
openedWalletsByPath[path] = wptr!;
|
||||||
|
}
|
||||||
|
|
||||||
void restoreWalletFromSpendKeySync(
|
void restoreWalletFromSpendKeySync(
|
||||||
{required String path,
|
{required String path,
|
||||||
required String password,
|
required String password,
|
||||||
|
|
|
@ -112,9 +112,8 @@ abstract class WowneroWalletBase
|
||||||
|
|
||||||
String get password => _password;
|
String get password => _password;
|
||||||
|
|
||||||
String? passphrase() {
|
@override
|
||||||
return wownero_wallet.getPassphrase();
|
String get passphrase => wownero_wallet.getPassphrase();
|
||||||
}
|
|
||||||
|
|
||||||
String _password;
|
String _password;
|
||||||
|
|
||||||
|
|
|
@ -303,6 +303,29 @@ class WowneroWalletService extends WalletService<
|
||||||
Future<WowneroWallet> _restoreFromPolyseed(
|
Future<WowneroWallet> _restoreFromPolyseed(
|
||||||
String path, String password, Polyseed polyseed, WalletInfo walletInfo, PolyseedLang lang,
|
String path, String password, Polyseed polyseed, WalletInfo walletInfo, PolyseedLang lang,
|
||||||
{PolyseedCoin coin = PolyseedCoin.POLYSEED_WOWNERO, int? overrideHeight, String? passphrase}) async {
|
{PolyseedCoin coin = PolyseedCoin.POLYSEED_WOWNERO, int? overrideHeight, String? passphrase}) async {
|
||||||
|
|
||||||
|
|
||||||
|
if (polyseed.isEncrypted == false &&
|
||||||
|
(passphrase??'') != "") {
|
||||||
|
// Fallback to the different passphrase offset method, when a passphrase
|
||||||
|
// was provided but the polyseed is not encrypted.
|
||||||
|
wownero_wallet_manager.restoreWalletFromPolyseedWithOffset(
|
||||||
|
path: path,
|
||||||
|
password: password,
|
||||||
|
seed: polyseed.encode(lang, coin),
|
||||||
|
seedOffset: passphrase??'',
|
||||||
|
language: "English");
|
||||||
|
|
||||||
|
final wallet = WowneroWallet(
|
||||||
|
walletInfo: walletInfo,
|
||||||
|
unspentCoinsInfo: unspentCoinsInfoSource,
|
||||||
|
password: password,
|
||||||
|
);
|
||||||
|
await wallet.init();
|
||||||
|
|
||||||
|
return wallet;
|
||||||
|
}
|
||||||
|
|
||||||
if (polyseed.isEncrypted) polyseed.crypt(passphrase ?? '');
|
if (polyseed.isEncrypted) polyseed.crypt(passphrase ?? '');
|
||||||
|
|
||||||
final height = overrideHeight ??
|
final height = overrideHeight ??
|
||||||
|
|
|
@ -167,7 +167,7 @@ abstract class WalletKeysViewModelBase with Store {
|
||||||
value: wownero!.getLegacySeed(_appStore.wallet!, lang.nameEnglish)));
|
value: wownero!.getLegacySeed(_appStore.wallet!, lang.nameEnglish)));
|
||||||
}
|
}
|
||||||
|
|
||||||
final passphrase = (_appStore.wallet as WowneroWalletBase).passphrase();
|
final passphrase = _appStore.wallet?.passphrase;
|
||||||
if (passphrase != null && passphrase != "") {
|
if (passphrase != null && passphrase != "") {
|
||||||
items.add(StandartListItem(
|
items.add(StandartListItem(
|
||||||
title: S.current.passphrase_view_keys,
|
title: S.current.passphrase_view_keys,
|
||||||
|
|
Loading…
Reference in a new issue