Skip to content

Return an error from NodeEntropy::from_bip39_mnemonic in bindings - #1058

Open
kaloudis wants to merge 1 commit into
lightningdevkit:mainfrom
ZeusLN:entropy-invalid-mnemonic-error
Open

Return an error from NodeEntropy::from_bip39_mnemonic in bindings#1058
kaloudis wants to merge 1 commit into
lightningdevkit:mainfrom
ZeusLN:entropy-invalid-mnemonic-error

Conversation

@kaloudis

Copy link
Copy Markdown

The uniffi-exposed from_bip39_mnemonic constructor was infallible and took the Mnemonic custom type, which parses the string during argument lifting. An invalid mnemonic would fail the lift and surface as an unexpected-error call status. The generated Swift wrapper for an infallible function wraps the call in try!, so passing an invalid mnemonic (eg. a user typo during wallet restore) aborts the process with an uncatchable EXC_BREAKPOINT. Kotlin and Python raise their generic internal exceptions instead.

Following the from_seed_bytes precedent, give the constructor a uniffi-specific signature that takes the mnemonic as a plain string and returns Result<NodeEntropy, EntropyError>, parsing inside the function and reporting failures via a new
EntropyError::InvalidMnemonic variant. The non-uniffi Rust API is unchanged.

Discovered in an ZEUS iOS user crash report.

The uniffi-exposed `from_bip39_mnemonic` constructor was infallible
and took the `Mnemonic` custom type, which parses the string during
argument lifting. An invalid mnemonic would fail the lift and surface
as an unexpected-error call status. The generated Swift wrapper for an
infallible function wraps the call in `try!`, so passing an invalid
mnemonic (e.g., a user typo during wallet restore) aborts the process
with an uncatchable EXC_BREAKPOINT. Kotlin and Python raise their
generic internal exceptions instead.

Following the `from_seed_bytes` precedent, give the constructor a
uniffi-specific signature that takes the mnemonic as a plain string
and returns `Result<NodeEntropy, EntropyError>`, parsing inside the
function and reporting failures via a new
`EntropyError::InvalidMnemonic` variant. The non-uniffi Rust API is
unchanged.
@ldk-reviews-bot

ldk-reviews-bot commented Aug 19, 2026

Copy link
Copy Markdown

I've assigned @tnull 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.

@ldk-reviews-bot
ldk-reviews-bot requested a review from tnull August 19, 2026 05:05
@tnull

tnull commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Ugh, sorry. We'll be working towards getting rid of all custom type to avoid these cases, seems we missed this so far :/

I think we should however do #1059, i.e., expose Mnemonic as a proper interface to bindings users, which also exposes more functionality and allows us to clean up some legacy code.

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