2024-05-23 00:37:06 +00:00
|
|
|
import '../../../exceptions/sw_exception.dart';
|
|
|
|
import '../../crypto_currency/crypto_currency.dart';
|
|
|
|
import '../wallet.dart';
|
2023-09-18 21:28:31 +00:00
|
|
|
|
2023-11-16 22:25:20 +00:00
|
|
|
mixin MnemonicInterface<T extends CryptoCurrency> on Wallet<T> {
|
2023-09-18 21:28:31 +00:00
|
|
|
Future<String> getMnemonic() async {
|
|
|
|
final mnemonic = await secureStorageInterface.read(
|
2023-11-03 19:46:55 +00:00
|
|
|
key: Wallet.mnemonicKey(walletId: info.walletId),
|
2023-09-18 21:28:31 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if (mnemonic == null) {
|
|
|
|
throw SWException("mnemonic has not been set");
|
|
|
|
}
|
|
|
|
|
|
|
|
return mnemonic;
|
|
|
|
}
|
|
|
|
|
2023-11-03 19:46:55 +00:00
|
|
|
Future<List<String>> getMnemonicAsWords() async {
|
|
|
|
final mnemonic = await getMnemonic();
|
|
|
|
return mnemonic.split(" ");
|
|
|
|
}
|
|
|
|
|
2023-09-18 21:28:31 +00:00
|
|
|
Future<String> getMnemonicPassphrase() async {
|
|
|
|
final mnemonicPassphrase = await secureStorageInterface.read(
|
2023-11-03 19:46:55 +00:00
|
|
|
key: Wallet.mnemonicPassphraseKey(walletId: info.walletId),
|
2023-09-18 21:28:31 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if (mnemonicPassphrase == null) {
|
2024-01-14 22:09:48 +00:00
|
|
|
// some really old wallets may not have this set so for legacy reasons do
|
|
|
|
// not throw here for now
|
|
|
|
return "";
|
|
|
|
//throw SWException("mnemonicPassphrase has not been set");
|
2023-09-18 21:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return mnemonicPassphrase;
|
|
|
|
}
|
|
|
|
}
|