diff --git a/key-manager-test/src/test/scala/org/bitcoins/keymanager/config/KeyManagerAppConfigTest.scala b/key-manager-test/src/test/scala/org/bitcoins/keymanager/config/KeyManagerAppConfigTest.scala index a6dd9e21c0..22d49b3b77 100644 --- a/key-manager-test/src/test/scala/org/bitcoins/keymanager/config/KeyManagerAppConfigTest.scala +++ b/key-manager-test/src/test/scala/org/bitcoins/keymanager/config/KeyManagerAppConfigTest.scala @@ -214,4 +214,18 @@ class KeyManagerAppConfigTest extends BitcoinSAsyncTest { appConfig1.toBip39KeyManager } } + + it must "validate a wallet name" in { + assert(KeyManagerAppConfig.validateWalletName("")) + assert(KeyManagerAppConfig.validateWalletName("old-wallet")) + + //weird whitespace + assert(!KeyManagerAppConfig.validateWalletName(" ")) + assert(!KeyManagerAppConfig.validateWalletName(" old-wallet")) + + //no non alpha-numeric + assert(!KeyManagerAppConfig.validateWalletName("@@@")) + assert(!KeyManagerAppConfig.validateWalletName("old-wallet.")) + + } } diff --git a/key-manager/src/main/scala/org/bitcoins/keymanager/config/KeyManagerAppConfig.scala b/key-manager/src/main/scala/org/bitcoins/keymanager/config/KeyManagerAppConfig.scala index 4d26c7dd2e..4765539dc6 100644 --- a/key-manager/src/main/scala/org/bitcoins/keymanager/config/KeyManagerAppConfig.scala +++ b/key-manager/src/main/scala/org/bitcoins/keymanager/config/KeyManagerAppConfig.scala @@ -30,7 +30,10 @@ case class KeyManagerAppConfig( lazy val networkParameters: NetworkParameters = chain.network lazy val walletNameOpt: Option[String] = { - config.getStringOrNone(s"bitcoin-s.wallet.walletName") + val nameOpt = config.getStringOrNone(s"bitcoin-s.wallet.walletName") + require(nameOpt.map(KeyManagerAppConfig.validateWalletName).getOrElse(true), + s"Invalid wallet name, only alphanumeric with _, got=$nameOpt") + nameOpt } lazy val seedFolder: Path = baseDatadir @@ -215,4 +218,10 @@ object KeyManagerAppConfig extends AppConfigFactory[KeyManagerAppConfig] { override def fromDatadir(datadir: Path, confs: Vector[Config])(implicit ec: ExecutionContext): KeyManagerAppConfig = KeyManagerAppConfig(datadir, confs) + + def validateWalletName(walletName: String): Boolean = { + walletName.forall { char => + char.isLetterOrDigit || char == '-' || char == '_' + } + } } diff --git a/wallet/src/main/scala/org/bitcoins/wallet/config/WalletAppConfig.scala b/wallet/src/main/scala/org/bitcoins/wallet/config/WalletAppConfig.scala index 358c1705be..2c75be1a8a 100644 --- a/wallet/src/main/scala/org/bitcoins/wallet/config/WalletAppConfig.scala +++ b/wallet/src/main/scala/org/bitcoins/wallet/config/WalletAppConfig.scala @@ -404,5 +404,4 @@ object WalletAppConfig () } } - }