Skip to content

Commit b66fbd9

Browse files
committed
fix(mwc): write .api_secret for default node authentication
1 parent ed5a671 commit b66fbd9

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

crypto_plugins/flutter_libmwc

lib/wallets/wallet/impl/mimblewimblecoin_wallet.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ class MimblewimblecoinWallet extends Bip39Wallet {
582582
final String nodeApiAddress = uri.toString();
583583
final walletDir = await _currentWalletDirPath();
584584

585+
await _ensureApiSecret(walletDir, nodeApiAddress);
586+
585587
final Map<String, dynamic> config = {};
586588
config["wallet_dir"] = walletDir;
587589
config["check_node_api_http_addr"] = nodeApiAddress;
@@ -591,6 +593,21 @@ class MimblewimblecoinWallet extends Bip39Wallet {
591593
return stringConfig;
592594
}
593595

596+
/// Write the node API secret to .api_secret in the wallet directory so that
597+
/// the Rust HTTPNodeClient can authenticate to the MWC node.
598+
Future<void> _ensureApiSecret(String walletDir, String nodeUrl) async {
599+
const defaultNodeHost = 'mwc713.mwc.mw';
600+
const defaultNodeSecret = '11ne3EAUtOXVKwhxm84U';
601+
602+
final file = File('$walletDir/.api_secret');
603+
if (nodeUrl.contains(defaultNodeHost)) {
604+
await Directory(walletDir).create(recursive: true);
605+
await file.writeAsString(defaultNodeSecret);
606+
} else if (await file.exists()) {
607+
await file.delete();
608+
}
609+
}
610+
594611
Future<String> _currentWalletDirPath() async {
595612
final Directory appDir = await StackFileSystem.applicationRootDirectory();
596613

0 commit comments

Comments
 (0)