   (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]}]

             [:application-info :puk-retry-counter]
             (fnil dec 5))
      (later
       #(on-failure
         #js {:code    "EUNSPECIFIED"
              :message "Unexpected error SW, 0x63C2"})))))

(defn verify-pin [{:keys [pin on-success on-failure]}]
  (if (= pin (get @state :pin))
    (later #(on-success 3))
    (do
      (swap! state update-in
             [:application-info :pin-retry-counter]
             (fnil dec 3))
      (later #(on-failure
               #js {:code    "EUNSPECIFIED"
                    :message "Unexpected error SW, 0x63C2"})))))

(defn change-pin [args]
  (log/warn "change-pin not implemented" args))
(defn change-puk [args]
  (log/warn "change-puk not implemented" args))
(defn change-pairing [args]
  (log/warn "change-pairing not implemented" args))
(defn unpair [args]
  (log/warn "unpair not implemented" args))
(defn delete [args]

        whisper     (get derived constants/path-whisper-keyword)
        wallet      (get derived constants/path-default-wallet-keyword)
        wallet-root (get derived constants/path-wallet-root-keyword)
        password    account-password
        response    {:key-uid                key-uid
                     :encryption-public-key  password
                     :address                address
