Skip to content

Commit 447945f

Browse files
fix: transaction fails when signed from auto-restored derived account after seed phrase recovery with biometric authentication enabled (#22040)
Signed-off-by: Brian Sztamfater <[email protected]>
1 parent 16b2c90 commit 447945f

File tree

4 files changed

+52
-42
lines changed

4 files changed

+52
-42
lines changed

src/status_im/common/standard_authentication/events.cljs

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,35 @@
1010
[utils.re-frame :as rf]
1111
[utils.security.core :as security]))
1212

13+
(defn- partially-operable-accounts?
14+
[accounts]
15+
(->> accounts
16+
vals
17+
(some #(= :partially (:operable %)))
18+
boolean))
19+
20+
(rf/reg-event-fx :standard-auth/migrate-partially-operable-accounts
21+
(fn [{:keys [db]} [{:keys [masked-password on-success]}]]
22+
(let [on-auth-success-callback #(on-success masked-password)
23+
has-partially-operable-accounts? (-> (get-in db [:wallet :accounts])
24+
partially-operable-accounts?)]
25+
{:fx [(if has-partially-operable-accounts?
26+
[:dispatch
27+
[:wallet/make-partially-operable-accounts-fully-operable
28+
{:password masked-password
29+
:on-success on-auth-success-callback
30+
:on-error on-auth-success-callback}]]
31+
[:effects.standard-auth/on-auth-success on-auth-success-callback])]})))
32+
1333
(defn- handle-password-success
14-
[has-partially-operable-accounts? on-auth-success masked-password]
34+
[{:keys [migrate-partially-operable-accounts? on-auth-success masked-password]}]
1535
(let [on-auth-success-callback #(on-auth-success masked-password)]
1636
(rf/dispatch [:standard-auth/set-success true])
1737
(rf/dispatch [:standard-auth/reset-login-password])
18-
(if has-partially-operable-accounts?
19-
(rf/dispatch [:wallet/make-partially-operable-accounts-fully-operable
20-
{:password masked-password
21-
:on-success on-auth-success-callback
22-
:on-error on-auth-success-callback}])
38+
(if migrate-partially-operable-accounts?
39+
(rf/dispatch [:standard-auth/migrate-partially-operable-accounts
40+
{:masked-password masked-password
41+
:on-success on-auth-success}])
2342
(on-auth-success-callback))))
2443

2544
(defn authorize
@@ -42,9 +61,10 @@
4261
{:pin pin
4362
:on-success (fn [{:keys [encryption-public-key]}]
4463
(rf/dispatch [:keycard/disconnect])
45-
(handle-password-success false
46-
on-auth-success
47-
(security/mask-data encryption-public-key)))
64+
(handle-password-success {:migrate-partially-operable-accounts? false
65+
:on-auth-success on-auth-success
66+
:masked-password (security/mask-data
67+
encryption-public-key)}))
4868
:on-failure #(rf/dispatch [:keycard/on-action-with-pin-error
4969
%])}]))}]))}]]
5070
[:effects.biometric/check-if-available
@@ -85,7 +105,12 @@
85105
keycard? (get-in db [:profile/profile :keycard-pairing])]
86106
{:fx [(if keycard?
87107
[:keychain/get-keycard-keys [key-uid on-auth-success]]
88-
[:keychain/get-user-password [key-uid on-auth-success]])
108+
[:keychain/get-user-password
109+
[key-uid
110+
(fn [masked-password]
111+
(rf/dispatch [:standard-auth/migrate-partially-operable-accounts
112+
{:masked-password masked-password
113+
:on-success on-auth-success}]))]])
89114
[:dispatch [:standard-auth/set-success true]]
90115
[:dispatch [:standard-auth/reset-login-password]]]}))
91116

@@ -108,15 +133,14 @@
108133
(defn- bottom-sheet-password-view
109134
[{:keys [on-press-biometric on-auth-success auth-button-icon-left auth-button-label]}]
110135
(fn []
111-
(let [has-partially-operable-accounts? (rf/sub [:wallet/has-partially-operable-accounts?])]
112-
[enter-password/view
113-
{:on-enter-password #(handle-password-success
114-
has-partially-operable-accounts?
115-
on-auth-success
116-
(security/hash-masked-password %))
117-
:on-press-biometrics on-press-biometric
118-
:button-icon-left auth-button-icon-left
119-
:button-label auth-button-label}])))
136+
[enter-password/view
137+
{:on-enter-password #(handle-password-success {:migrate-partially-operable-accounts? true
138+
:on-auth-success on-auth-success
139+
:masked-password (security/hash-masked-password
140+
%)})
141+
:on-press-biometrics on-press-biometric
142+
:button-icon-left auth-button-icon-left
143+
:button-label auth-button-label}]))
120144

121145
(defn authorize-with-keycard
122146
[_ [{:keys [on-complete]}]]
@@ -155,6 +179,12 @@
155179
(when on-close
156180
(on-close success?))))
157181

182+
(rf/reg-fx
183+
:effects.standard-auth/on-auth-success
184+
(fn [on-auth-success]
185+
(when on-auth-success
186+
(on-auth-success))))
187+
158188
(rf/reg-event-fx
159189
:standard-auth/close
160190
(fn [{:keys [db]} [on-close]]

src/status_im/subs/wallet/wallet.cljs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -861,14 +861,6 @@
861861
fee-in-fiat)]
862862
fee-formatted))))
863863

864-
(rf/reg-sub
865-
:wallet/has-partially-operable-accounts?
866-
:<- [:wallet/accounts]
867-
(fn [accounts]
868-
(->> accounts
869-
(some #(= :partially (:operable %)))
870-
boolean)))
871-
872864
(rf/reg-sub
873865
:wallet/accounts-names
874866
:<- [:wallet/accounts]

src/status_im/subs/wallet/wallet_test.cljs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -942,20 +942,6 @@
942942
result (rf/sub [sub-name token-symbol-for-fees])]
943943
(is (match? result "$0.20")))))
944944

945-
(h/deftest-sub :wallet/has-partially-operable-accounts?
946-
[sub-name]
947-
(testing "returns false if there are no partially operable accounts"
948-
(swap! rf-db/app-db
949-
#(assoc-in % [:wallet :accounts] accounts))
950-
(is (false? (rf/sub [sub-name]))))
951-
952-
(testing "returns true if there are partially operable accounts"
953-
(swap! rf-db/app-db
954-
#(assoc-in %
955-
[:wallet :accounts]
956-
(update accounts "0x2" assoc :operable :partially)))
957-
(is (true? (rf/sub [sub-name])))))
958-
959945
(h/deftest-sub :wallet/zero-balance-in-all-non-watched-accounts?
960946
[sub-name]
961947
(testing "returns true if the balance is zero in all non-watched accounts"

src/tests/integration_test/standard_auth_test.cljs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
(defn auth-success-fixtures
1919
[]
20+
(rf/reg-fx :effects.standard-auth/on-auth-success
21+
(fn [on-auth-success] (on-auth-success)))
2022
(rf/reg-fx :effects.biometric/check-if-available
2123
(fn [{:keys [on-success]}] (on-success)))
2224
(rf/reg-event-fx :biometric/authenticate
@@ -32,7 +34,7 @@
3234
(let [on-success-called? (atom false)
3335
args (assoc default-args :on-auth-success #(reset! on-success-called? true))]
3436
(rf/dispatch [:standard-auth/authorize args])
35-
(rf-test/wait-for [:standard-auth/on-biometric-success]
37+
(rf-test/wait-for [:standard-auth/migrate-partially-operable-accounts]
3638
(is @on-success-called?))))))
3739

3840
(defn auth-cancel-fixtures

0 commit comments

Comments
 (0)