generate address from public key (#752)
This commit is contained in:
parent
7406b287ed
commit
5af0905f2f
|
@ -151,6 +151,7 @@ var TopLevel = {
|
||||||
"setTimeout" : function () {},
|
"setTimeout" : function () {},
|
||||||
"setValue" : function () {},
|
"setValue" : function () {},
|
||||||
"Sha256" : function () {},
|
"Sha256" : function () {},
|
||||||
|
"sha3" : function () {},
|
||||||
"shh" : function () {},
|
"shh" : function () {},
|
||||||
"show" : function () {},
|
"show" : function () {},
|
||||||
"showActionSheetWithOptions" : function () {},
|
"showActionSheetWithOptions" : function () {},
|
||||||
|
|
|
@ -189,6 +189,14 @@
|
||||||
(after save-contacts!)
|
(after save-contacts!)
|
||||||
add-new-contacts)
|
add-new-contacts)
|
||||||
|
|
||||||
|
(defn public-key->address [public-key]
|
||||||
|
(let [length (count public-key)
|
||||||
|
normalized-key (case length
|
||||||
|
132 (subs public-key 4)
|
||||||
|
130 (subs public-key 2)
|
||||||
|
128 public-key)]
|
||||||
|
(subs (.sha3 js/Web3.prototype normalized-key #js {:encoding "hex"}) 26)))
|
||||||
|
|
||||||
(defn add-new-contact [db [_ {:keys [whisper-identity] :as contact}]]
|
(defn add-new-contact [db [_ {:keys [whisper-identity] :as contact}]]
|
||||||
(-> db
|
(-> db
|
||||||
(update :contacts assoc whisper-identity contact)
|
(update :contacts assoc whisper-identity contact)
|
||||||
|
@ -198,7 +206,8 @@
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [_ [_ {:keys [whisper-identity] :as contact}]]
|
(fn [_ [_ {:keys [whisper-identity] :as contact}]]
|
||||||
(when-not (contacts/get-by-id whisper-identity)
|
(when-not (contacts/get-by-id whisper-identity)
|
||||||
(dispatch [::prepare-contact contact])
|
(let [contact (assoc contact :address (public-key->address whisper-identity))]
|
||||||
|
(dispatch [::prepare-contact contact]))
|
||||||
(dispatch [:start-chat whisper-identity {} :navigation-replace])))))
|
(dispatch [:start-chat whisper-identity {} :navigation-replace])))))
|
||||||
|
|
||||||
(register-handler ::prepare-contact
|
(register-handler ::prepare-contact
|
||||||
|
@ -216,9 +225,10 @@
|
||||||
(let [contact (if-let [contact-info (get-in chats [chat-id :contact-info])]
|
(let [contact (if-let [contact-info (get-in chats [chat-id :contact-info])]
|
||||||
(read-string contact-info)
|
(read-string contact-info)
|
||||||
(-> (get contacts chat-id)
|
(-> (get contacts chat-id)
|
||||||
(assoc :pending false)))]
|
(assoc :pending false)))
|
||||||
(dispatch [::prepare-contact contact])
|
contact' (assoc contact :address (public-key->address chat-id))]
|
||||||
(dispatch [:watch-contact contact])
|
(dispatch [::prepare-contact contact'])
|
||||||
|
(dispatch [:watch-contact contact'])
|
||||||
(dispatch [:discoveries-send-portions chat-id])))))
|
(dispatch [:discoveries-send-portions chat-id])))))
|
||||||
|
|
||||||
(defn set-contact-identity-from-qr
|
(defn set-contact-identity-from-qr
|
||||||
|
|
Loading…
Reference in New Issue