@@ -85,20 +85,27 @@ async fn process_api_btc(_request: &Request) -> Result<Response, Error> {
85
85
86
86
/// Checks if the device is ready to accept/handle an api endpoint.
87
87
fn can_call ( request : & Request ) -> bool {
88
- // We have three main states:
89
- // Creating a wallet on an uninitialized device goes through those states in order.
90
- // Restoring a backup skips the seeded state and goes straight to `initialized`.
88
+ // We have four main states:
89
+ // Creating a wallet on an uninitialized device goes from Uninitialized to Seeded, and when the
90
+ // backup is created to `Initialized*`.
91
+ // Restoring a backup skips the seeded state and goes straight to `Initialized*`.
91
92
// Each state has a set of valid api calls associated.
92
93
enum State {
93
94
// Uninitialized (reset).
94
95
Uninitialized ,
95
96
// Seeded (password defined, seed created/loaded).
96
97
Seeded ,
97
- // Initialized (seed backuped up on SD card).
98
- Initialized ,
98
+ // InitializedAndLocked (seed backuped up on SD card, keystore locked).
99
+ InitializedAndLocked ,
100
+ // InitializedAndUnlocked (seed backuped up on SD card, keystore unlocked).
101
+ InitializedAndUnlocked ,
99
102
}
100
103
let state: State = if bitbox02:: memory:: is_initialized ( ) {
101
- State :: Initialized
104
+ if bitbox02:: keystore:: is_locked ( ) {
105
+ State :: InitializedAndLocked
106
+ } else {
107
+ State :: InitializedAndUnlocked
108
+ }
102
109
} else if bitbox02:: memory:: is_seeded ( ) {
103
110
State :: Seeded
104
111
} else {
@@ -108,33 +115,38 @@ fn can_call(request: &Request) -> bool {
108
115
match request {
109
116
// Deprecated call, last used in v1.0.0.
110
117
Request :: PerformAttestation ( _) => false ,
111
- Request :: DeviceInfo ( _) => true ,
112
- Request :: Reboot ( _) => true ,
113
- Request :: DeviceName ( _) => true ,
114
- Request :: DeviceLanguage ( _) => true ,
115
- Request :: CheckSdcard ( _) => true ,
116
- Request :: InsertRemoveSdcard ( _) => true ,
117
- Request :: ListBackups ( _) => true ,
118
- Request :: SetPassword ( _) => matches ! ( state, State :: Uninitialized | State :: Seeded ) ,
119
- Request :: RestoreBackup ( _) => matches ! ( state, State :: Uninitialized | State :: Seeded ) ,
120
- Request :: RestoreFromMnemonic ( _) => matches ! ( state, State :: Uninitialized | State :: Seeded ) ,
121
- Request :: CreateBackup ( _) => matches ! ( state, State :: Seeded | State :: Initialized ) ,
122
- Request :: ShowMnemonic ( _) => matches ! ( state, State :: Seeded | State :: Initialized ) ,
123
- Request :: Fingerprint ( _) => matches ! ( state, State :: Initialized ) ,
124
- Request :: ElectrumEncryptionKey ( _) => matches ! ( state, State :: Initialized ) ,
125
- Request :: BtcPub ( _) | Request :: Btc ( _) | Request :: BtcSignInit ( _) => {
126
- matches ! ( state, State :: Initialized )
118
+ Request :: DeviceInfo ( _)
119
+ | Request :: Reboot ( _)
120
+ | Request :: DeviceName ( _)
121
+ | Request :: DeviceLanguage ( _)
122
+ | Request :: CheckSdcard ( _)
123
+ | Request :: InsertRemoveSdcard ( _)
124
+ | Request :: ListBackups ( _) => matches ! (
125
+ state,
126
+ State :: Uninitialized | State :: Seeded | State :: InitializedAndUnlocked
127
+ ) ,
128
+ Request :: SetPassword ( _) | Request :: RestoreBackup ( _) | Request :: RestoreFromMnemonic ( _) => {
129
+ matches ! ( state, State :: Uninitialized | State :: Seeded )
130
+ }
131
+ Request :: CreateBackup ( _) | Request :: ShowMnemonic ( _) => {
132
+ matches ! ( state, State :: Seeded | State :: InitializedAndUnlocked )
133
+ }
134
+ Request :: Fingerprint ( _)
135
+ | Request :: ElectrumEncryptionKey ( _)
136
+ | Request :: BtcPub ( _)
137
+ | Request :: Btc ( _)
138
+ | Request :: BtcSignInit ( _)
139
+ | Request :: CheckBackup ( _)
140
+ | Request :: SetMnemonicPassphraseEnabled ( _)
141
+ | Request :: Eth ( _)
142
+ | Request :: Reset ( _)
143
+ | Request :: Cardano ( _)
144
+ | Request :: Bip85 ( _) => {
145
+ matches ! ( state, State :: InitializedAndUnlocked )
127
146
}
128
147
// These are streamed asynchronously using the `next_request()` primitive in
129
148
// bitcoin/signtx.rs and are not handled directly.
130
149
Request :: BtcSignInput ( _) | Request :: BtcSignOutput ( _) => false ,
131
-
132
- Request :: CheckBackup ( _) => matches ! ( state, State :: Initialized ) ,
133
- Request :: SetMnemonicPassphraseEnabled ( _) => matches ! ( state, State :: Initialized ) ,
134
- Request :: Eth ( _) => matches ! ( state, State :: Initialized ) ,
135
- Request :: Reset ( _) => matches ! ( state, State :: Initialized ) ,
136
- Request :: Cardano ( _) => matches ! ( state, State :: Initialized ) ,
137
- Request :: Bip85 ( _) => matches ! ( state, State :: Initialized ) ,
138
150
}
139
151
}
140
152
0 commit comments