faster keycard login

Signed-off-by: Michele Balistreri <michele@bitgamma.com>
This commit is contained in:
Michele Balistreri 2021-02-19 13:01:16 +03:00
parent a383cfa39a
commit 325a860916
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
10 changed files with 63 additions and 21 deletions

View File

@ -61,7 +61,7 @@
"react-native-screens": "^2.10.1",
"react-native-shake": "^3.3.1",
"react-native-splash-screen": "^3.2.0",
"react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#v2.5.30",
"react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#v2.5.31",
"react-native-svg": "^9.8.4",
"react-native-touch-id": "^4.4.1",
"react-native-webview": "git+https://github.com/status-im/react-native-webview.git#v10.9.2",

View File

@ -336,24 +336,43 @@
(re-frame/dispatch [:keycard.callback/on-delete-error
(error-object->map response)]))})))
(defn import-keys [{:keys [on-success] :as args}]
(log/debug "[keycard] import-keys")
(keycard/import-keys
card
(assoc
args
:on-success
(fn [response]
(log/debug "[keycard response succ] import-keys")
(re-frame/dispatch
[(or on-success :keycard.callback/on-generate-and-load-key-success)
response]))
:on-failure
(fn [response]
(log/warn "[keycard response fail] import-keys"
(error-object->map response))
(re-frame/dispatch [:keycard.callback/on-get-keys-error
(error-object->map response)])))))
(defn get-keys [{:keys [on-success] :as args}]
(log/debug "[keycard] get-keys")
(keycard/get-keys
card
(merge
(assoc
args
{:on-success
(fn [response]
(log/debug "[keycard response succ] get-keys")
(re-frame/dispatch
[(or on-success :keycard.callback/on-get-keys-success)
response]))
:on-failure
(fn [response]
(log/debug "[keycard response fail] get-keys"
(error-object->map response))
(re-frame/dispatch [:keycard.callback/on-get-keys-error
(error-object->map response)]))})))
:on-success
(fn [response]
(log/debug "[keycard response succ] get-keys")
(re-frame/dispatch
[(or on-success :keycard.callback/on-get-keys-success)
response]))
:on-failure
(fn [response]
(log/warn "[keycard response fail] get-keys"
(error-object->map response))
(re-frame/dispatch [:keycard.callback/on-get-keys-error
(error-object->map response)])))))
(defn sign [{:keys [on-success on-failure] :as args}]
(log/debug "[keycard] sign")

View File

@ -356,6 +356,9 @@
(-> db
(assoc-in [:keycard :pin :status] nil)
(assoc-in [:keycard :pin :login] [])
(update-in [:keycard :application-info] assoc
:puk-retry-counter 5
:pin-retry-counter 3)
(assoc-in [:keycard :multiaccount]
(update account-data :whisper-public-key ethereum/normalized-hex))
(assoc-in [:keycard :flow] nil)
@ -365,7 +368,6 @@
:identicon identicon
:name name))
:keycard/get-application-info {:pairing (get-pairing db key-uid)}
:keycard/login-with-keycard {:multiaccount-data multiaccount-data
:password encryption-public-key
:chat-key whisper-private-key

View File

@ -131,6 +131,10 @@
:keycard/unpair-and-delete
card/unpair-and-delete)
(re-frame/reg-fx
:keycard/import-keys
card/import-keys)
(re-frame/reg-fx
:keycard/get-keys
card/get-keys)

View File

@ -26,6 +26,7 @@
(remove-key-with-unpair [this args])
(export-key [this args])
(unpair-and-delete [this args])
(import-keys [this args])
(get-keys [this args])
(sign [this args])
(save-multiaccount-and-login [this args])

View File

@ -28,6 +28,7 @@
(remove-key-with-unpair [this args])
(export-key [this args])
(unpair-and-delete [this args])
(import-keys [this args])
(get-keys [this args])
(sign [this args])
(sign-typed-data [this args])

View File

@ -211,6 +211,14 @@
(then on-success)
(catch on-failure))))
(defn import-keys
[{:keys [pairing pin on-success on-failure]}]
(when (and pairing (not-empty pin))
(.. status-keycard
(importKeys pairing pin)
(then on-success)
(catch on-failure))))
(defn get-keys
[{:keys [pairing pin on-success on-failure]}]
(when (and pairing (not-empty pin))
@ -315,6 +323,8 @@
(export-key args))
(keycard/unpair-and-delete [this args]
(unpair-and-delete args))
(keycard/import-keys [this args]
(import-keys args))
(keycard/get-keys [this args]
(get-keys args))
(keycard/sign [this args]

View File

@ -250,9 +250,9 @@
(assoc-in [:keycard :pin :status] :verifying)
(assoc-in [:keycard :secrets] {:pairing pairing'
:paired-on (utils.datetime/timestamp)}))
:keycard/get-keys {:pairing pairing'
:pin pin
:on-success :keycard.callback/on-generate-and-load-key-success}})))
:keycard/import-keys {:pairing pairing'
:pin pin
:on-success :keycard.callback/on-generate-and-load-key-success}})))
(fx/defn load-recovering-key-screen
{:events [:keycard/load-recovering-key-screen]}

View File

@ -336,6 +336,8 @@
#js {:code "EUNSPECIFIED"
:message "Unexpected error SW, 0x63C2"})))))
(def import-keys get-keys)
(defn sign [{:keys [pin hash data path typed? on-success on-failure]}]
(if (= pin (get @state :pin))
(later
@ -483,6 +485,9 @@
(keycard/unpair-and-delete [this args]
(log/debug "simulated card unpair-and-delete")
(unpair-and-delete args))
(keycard/import-keys [this args]
(log/debug "simulated card import-keys")
(import-keys args))
(keycard/get-keys [this args]
(log/debug "simulated card get-keys")
(get-keys args))

View File

@ -6751,9 +6751,9 @@ react-native-splash-screen@^3.2.0:
resolved "https://registry.yarnpkg.com/react-native-splash-screen/-/react-native-splash-screen-3.2.0.tgz#d47ec8557b1ba988ee3ea98d01463081b60fff45"
integrity sha512-Ls9qiNZzW/OLFoI25wfjjAcrf2DZ975hn2vr6U9gyuxi2nooVbzQeFoQS5vQcbCt9QX5NY8ASEEAtlLdIa6KVg==
"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#v2.5.30":
version "2.5.30"
resolved "git+https://github.com/status-im/react-native-status-keycard.git#958adb1e72dea1db989b4bf4663efe04ed8b2c0c"
"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#v2.5.31":
version "2.5.31"
resolved "git+https://github.com/status-im/react-native-status-keycard.git#67ba4d5596ae3f7fd123c0f1c925e98e8def493f"
react-native-svg@^9.8.4:
version "9.13.6"