Skip to content

Expose Mnemonic as interface to bindings users - #1059

Open
tnull wants to merge 2 commits into
lightningdevkit:mainfrom
tnull:2026-08-uniffi-mnemonic
Open

Expose Mnemonic as interface to bindings users#1059
tnull wants to merge 2 commits into
lightningdevkit:mainfrom
tnull:2026-08-uniffi-mnemonic

Conversation

@tnull

@tnull tnull commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator
Invalid mnemonic strings currently fail during implicit custom-type
lifting, which leaves generated bindings without a catchable validation
error.

Parse mnemonic phrases through a fallible object constructor while
keeping bip39::Mnemonic in the native Rust API.

And, since we now expose Mnemonic::generate to bindings users directly, we can get rid of our global generate_entropy_mnemonic helper.

@tnull
tnull requested a review from benthecarman August 19, 2026 07:49
@ldk-reviews-bot

ldk-reviews-bot commented Aug 19, 2026

Copy link
Copy Markdown

👋 Thanks for assigning @benthecarman as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@benthecarman benthecarman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nits otherwise lgtm

Comment thread src/ffi/types.rs Outdated
#[uniffi::constructor]
pub fn generate(word_count: Option<WordCount>) -> Self {
let word_count = word_count.unwrap_or(WordCount::Words24).word_count();
let inner = Bip39Mnemonic::generate(word_count)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we do the same as #1013 here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, no, I'd prefer to just call through to bip39 here, though that should do it soon, see rust-bitcoin/rust-bip39#105 (we just need to get a release out)

Comment thread src/ffi/types.rs

/// Returns the number of words in the mnemonic.
pub fn word_count(&self) -> u8 {
self.inner.word_count() as u8

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

changing the type here is kinda weird

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, unfortunately no usize in uniffi. Would you prefer we just no expose the method?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Could also wait until after rust-bitcoin/rust-bip39#98 lands and ships, when we'll re-introduce WordCount (just seemed weird to keep it for bindings only for now)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is fine for now, we can move to that in the future. No reason we'd ever break the u8 here for any practical reason

benthecarman
benthecarman previously approved these changes Aug 19, 2026
tnull added 2 commits August 19, 2026 14:29
Invalid mnemonic strings currently fail during implicit custom-type
lifting, which leaves generated bindings without a catchable validation
error.

Parse mnemonic phrases through a fallible object constructor while
keeping bip39::Mnemonic in the native Rust API.

Co-Authored-By: HAL 9000
Mnemonic generation no longer needs a separate global entry point now
that bindings expose a real mnemonic object.

Use numeric word counts for both native and binding constructors so the
APIs stay aligned without a binding-specific enum.

Co-Authored-By: HAL 9000
@tnull

tnull commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Amended with some fixes to make CI pass.

@tnull
tnull requested a review from benthecarman August 19, 2026 12:31
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