I would indeed expect something more robust like a security state machine where not all states can transition to any other state freely. The UI shouldn't even have a say in what transitions are allowed.
You might like this post on statig, an HSM library for Rust
https://old.reddit.com/r/rust/comments/yqp2cq/announcing_sta...