   (when f
     (utils/set-timeout f 500)))
 
+(defn pin-error []
+  #js {:code    "EUNSPECIFIED"
+       :message (str "Unexpected error SW, 0x63C" (get-in @state [:application-info :pin-retry-counter]))})
+
+(defn puk-error []
+  #js {:code    "EUNSPECIFIED"
+       :message (str "Unexpected error SW, 0x63C" (get-in @state [:application-info :puk-retry-counter]))})
+
+(defn with-pin [pin on-failure on-valid]
+  (if (= pin (get @state :pin))
+    (do
+      (swap! state update :application-info assoc
+             :pin-retry-counter 3
+             :puk-retry-counter 5)
+      (later on-valid))
+    (do
+      (swap! state update-in
+             [:application-info :pin-retry-counter]
+             (fnil dec 3))
+      (later #(on-failure (pin-error))))))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defn start-nfc [{:keys [on-success]}]


(defn install-applet-and-init-card [_])

(def kk1-pair "ADEol+GCD67EO7zU6ko0DNK7XrNs9w2+h9GxcibNY4yf")

(def derived-acc (atom nil))

(defn multiaccount->keys [pin data]
  (let [{:keys [selected-id multiaccounts root-key derived]}
        data


          :pin-retry-counter      3
          :puk-retry-counter      5
          :key-uid                (get-in @re-frame.db/app-db [:multiaccounts/login :key-uid])})
  (swap! state assoc :pin default-pin :puk default-puk :password kk1-password)
  (connect-card))

(def initialization (atom false))
