stack_wallet/lib/wallets/wallet/wallet_mixin_interfaces/mnemonic_interface.dart

35 lines
997 B
Dart
Raw Normal View History

2023-09-18 21:28:31 +00:00
import 'package:stackwallet/exceptions/sw_exception.dart';
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
2023-09-18 21:28:31 +00:00
import 'package:stackwallet/wallets/wallet/wallet.dart';
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(
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;
}
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(
key: Wallet.mnemonicPassphraseKey(walletId: info.walletId),
2023-09-18 21:28:31 +00:00
);
if (mnemonicPassphrase == null) {
throw SWException("mnemonicPassphrase has not been set");
}
return mnemonicPassphrase;
}
}