feat: add passphrase session support#1
Open
redsh4de wants to merge 3 commits into
Open
Conversation
Add TrezorClient.cancel() so the host can abort a prompt the device is showing (e.g. on-device passphrase entry) and send it back to its home screen
ad6bea3 to
cc156c9
Compare
Author
|
@konstantinullrich Would appreciate a look when you have a chance. This adds on-device entry support and NFKD normalization for passphrases to match trezor-suite's reference implementation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds passphrase support to both protocol clients.
Previously the package hardcoded an empty passphrase: V1 auto-ACKED every
PassphraseRequestwith"", and THP sentThpCreateNewSession(passphrase: "")during pairing.How
New
TrezorPassphrasetype with three cases.empty()selects the standard wallet.value()carries a passphrase typed in the app.onDevice()requests entry on the Trezor itself. Typed passphrases are NFKD-normalized and limited to 50 bytes, matching trezor-connect.New
TrezorClient.createSession(passphrase)on both clients. Connecting and creating a session are now separate steps.createChannel()only sets up the connection and pairing.createSession()then ties a passphrase to it. On V1 the device asks for the passphrase at the first call that needs the seed. The client answers from what was given tocreateSession. V1 sessions can also be resumed with a previously returned session id. The user is then not asked again after a reconnect.The clients now read the device's
Featuresand exposepassphraseAlwaysOnDevice. V1 gets them fromInitialize. THP requests them after connecting. When the setting is on, the session request is sent without a passphrase field. That is the only form the firmware accepts.THP error frames now throw a typed
TrezorChannelExceptioninstead of plainExceptionstrings. Apps can tell the connection died and reconnect.A passphrase typed in the app stays in memory only until used once. If the device asks again later, the client throws
TrezorSessionExpiredExceptionand the app must ask the user again. Only the session id, which contains no secret, may be kept.Notes
createSessionaftercreateChannel(see example app).