Mask BIP39 password in the BIP39KeyManager (#2350)

* Mask BIP39 password in the BIP39KeyManager

* Add toString test
This commit is contained in:
Chris Stewart 2020-12-11 16:15:44 -06:00 committed by GitHub
parent 24c776e453
commit af4a0baf2d
2 changed files with 20 additions and 0 deletions

View file

@ -44,6 +44,13 @@ class BIP39KeyManagerApiTest extends KeyManagerApiUnitTest {
assert(km != dummy)
}
it must "not put the bip39 password in the toString" in {
val passpharse = "test-bip39-passpharse"
val km = withInitializedKeyManager(bip39PasswordOpt = Some(passpharse))
assert(!km.toString.contains(passpharse))
assert(km.toString.contains("Masked(bip39password)"))
}
it must "initialize the key manager" in {
val entropy = MnemonicCode.getEntropy256Bits
val aesPasswordOpt = KeyManagerTestUtil.aesPasswordOpt

View file

@ -76,6 +76,19 @@ case class BIP39KeyManager(
def getRootXPub: ExtPublicKey = {
rootExtPrivKey.extPublicKey
}
/** This is overriden because we do not have a type for bip39 passwords
* for which we can extend [[org.bitcoins.crypto.MaskedToString]]
*/
override def toString: String = {
s"""
|BIP39KeyManager(
| mnemonic=$mnemonic,
| kmParams=$kmParams,
| bip39PasswordOpt=${bip39PasswordOpt.map(_ =>
s"Masked(bip39password)")},
| creationTime=$creationTime)""".stripMargin
}
}
object BIP39KeyManager