0

I'm using BIP39 plugin for Java to create a mnemonic. So I've converted (well mostly IDEA did) this Java code to a function in Kotlin syntax which looks like this:

fun mnemonicBuilder(): String {
  val sb = StringBuilder()
  val entropy = ByteArray(Words.TWELVE.byteLength())
  SecureRandom().nextBytes(entropy)
  MnemonicGenerator(English.INSTANCE)
      .createMnemonic(entropy, sb::append)
  return sb.toString()
}

IntelliJ IDEA keeps telling me that "None of the following functions can be called with the arguments supplied." for sb::append.

My quess is that .createMnemonic requires the second argument to have no return value (given by Target interface) but all appenders return the StringBuilder as a value.

Please, can somebody help me?

1
  • 1
    There is a concise Kotlin implementation of bip-39 that you might find helpful so that you're not having to rely on IntelliJ to convert Java to Kotlin. I created it to support Android wallet work and it is mainly based off a Rust-implementation from one of our in-house cryptographers who is a co-author on the BIP-39 spec. The library has also passed review by our security team. So hopefully it is useful. If not, file an issue :) Commented Sep 1, 2020 at 16:58

1 Answer 1

2

Indeed, argument signatures do not match. You can solve it by using lambda instead of the method reference:

MnemonicGenerator(English.INSTANCE)
    .createMnemonic(entropy) { sb.append(it) }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.