Skip to content

Conversation

@sstone
Copy link
Member

@sstone sstone commented Jun 3, 2025

We used kotlin's ULong type for the counter arguments which mangles method names when used from Scala. We also add an alternate method for nonce generation that includes new paramaters (message and additional data) and deprecate (but keep) the old one.

We used kotlin's ULong type for the counter arguments which mangles method names when used from Scala.
We also add an alternate method for nonce generation that includes new paramaters (message and additional data) and deprecate (but keep) the old one.
@sstone sstone requested a review from t-bast June 3, 2025 16:09
@sstone sstone added this to the 0.24.0 milestone Jun 3, 2025
@t-bast
Copy link
Member

t-bast commented Jun 3, 2025

We used kotlin's ULong type for the counter arguments which mangles method names when used from Scala.

Can you detail what you mean by that? What was the failure?

deprecate (but keep) the old one.

Why are we keeping the old function? Isn't it confusing? Since nobody uses it for now, isn't it better to just remove it?

@sstone
Copy link
Member Author

sstone commented Jun 3, 2025

We used kotlin's ULong type for the counter arguments which mangles method names when used from Scala.

Can you detail what you mean by that? What was the failure?

It was just unusable from Scala (name was mangled to generateWithCounter-R4QgNNg()

deprecate (but keep) the old one.

Why are we keeping the old function? Isn't it confusing? Since nobody uses it for now, isn't it better to just remove it?

It's used in lightning-kmp for swaproot but easy to upgrade, I'll remove it.

@sstone
Copy link
Member Author

sstone commented Jun 3, 2025

Kotlin's Ulong is an inline class, this is what caused the name mangling issue, so we should not use these types in methods that we want to call from Scala.

* @param extraInput (optional) additional random data.
*/
@JvmStatic
public fun generateNonce(sessionId: ByteVector32, privateKey: PrivateKey?, publicKey: PublicKey, publicKeys: List<PublicKey>, message: ByteVector32?, extraInput: ByteVector32?): Pair<SecretNonce, IndividualNonce> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to have a default null value for the optional parameters to simplify callers (message: ByteVector32? = null, extraInput: ByteVector32? = null)? Or do we rather want to strongly encourage providing those arguments and thus force callers to explicitly set them to null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional parameters are not understood by Scala so in Eclair we would have to provide them all anyway, but we could have another generateNonce() methods without these parameters.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional parameters are not understood by Scala

Damn, I didn't realize that! It's probably not worth having explicit methods without those, let's just keep the existing code to encourage people to provide as much randomness as possible 👍

@sstone sstone merged commit 95e66f6 into master Jun 4, 2025
2 checks passed
@sstone sstone deleted the fix-musig2-gen-counter-api branch June 4, 2025 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants