mirror of
https://github.com/status-im/status-mobile.git
synced 2025-01-13 02:04:28 +00:00
Encrypt contacts to send
Former-commit-id: 56f249e9fb1d1e52dfec833e15c49cff7f75f06f
This commit is contained in:
parent
c5a8f41ffa
commit
f62c2fab9a
35
src/messenger/android/contacts.cljs
Normal file
35
src/messenger/android/contacts.cljs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
(ns messenger.android.contacts
|
||||||
|
(:require [messenger.state :as state]
|
||||||
|
[messenger.android.utils :refer [log toast http-post]]))
|
||||||
|
|
||||||
|
(def fake-contacts? false)
|
||||||
|
|
||||||
|
(def react-native-contacts (js/require "react-native-contacts"))
|
||||||
|
|
||||||
|
(defn generate-contact [n]
|
||||||
|
{:name (str "Contact " n)
|
||||||
|
:photo ""
|
||||||
|
:phone-numbers [{:label "mobile" :number "121212"}]
|
||||||
|
:delivery-status (if (< (rand) 0.5) :delivered :seen)
|
||||||
|
:datetime "15:30"
|
||||||
|
:new-messages-count (rand-int 3)
|
||||||
|
:online (< (rand) 0.5)})
|
||||||
|
|
||||||
|
(defn generate-contacts [n]
|
||||||
|
(map generate-contact (range 1 (inc n))))
|
||||||
|
|
||||||
|
(defn load-contacts [on-success on-error]
|
||||||
|
(if fake-contacts?
|
||||||
|
(on-success (generate-contacts 100))
|
||||||
|
(.getAll react-native-contacts
|
||||||
|
(fn [error raw-contacts]
|
||||||
|
(if (not error)
|
||||||
|
(let [contacts (map (fn [contact]
|
||||||
|
(merge (generate-contact 1)
|
||||||
|
{:name (:givenName contact)
|
||||||
|
:photo (:thumbnailPath contact)
|
||||||
|
:phone-numbers (:phoneNumbers contact)}))
|
||||||
|
(js->clj raw-contacts :keywordize-keys true))]
|
||||||
|
(on-success contacts))
|
||||||
|
(when on-error
|
||||||
|
(on-error error)))))))
|
@ -8,7 +8,9 @@
|
|||||||
(:require [om.next :as om :refer-macros [defui]]
|
(:require [om.next :as om :refer-macros [defui]]
|
||||||
[re-natal.support :as sup]
|
[re-natal.support :as sup]
|
||||||
[messenger.state :as state]
|
[messenger.state :as state]
|
||||||
|
[messenger.android.utils :refer [log toast http-post]]
|
||||||
[messenger.android.resources :as res]
|
[messenger.android.resources :as res]
|
||||||
|
[messenger.android.contacts :as contacts]
|
||||||
[messenger.android.chat :refer [chat]]))
|
[messenger.android.chat :refer [chat]]))
|
||||||
|
|
||||||
(def fake-contacts? true)
|
(def fake-contacts? true)
|
||||||
@ -134,32 +136,13 @@
|
|||||||
(contact (om/computed (js->clj row :keywordize-keys true)
|
(contact (om/computed (js->clj row :keywordize-keys true)
|
||||||
{:nav nav})))
|
{:nav nav})))
|
||||||
|
|
||||||
(defn generate-contact [n]
|
|
||||||
{:name (str "Contact " n)
|
|
||||||
:photo ""
|
|
||||||
:delivery-status (if (< (rand) 0.5) :delivered :seen)
|
|
||||||
:datetime "15:30"
|
|
||||||
:new-messages-count (rand-int 3)
|
|
||||||
:online (< (rand) 0.5)})
|
|
||||||
|
|
||||||
(defn generate-contacts [n]
|
|
||||||
(map generate-contact (range 1 (inc n))))
|
|
||||||
|
|
||||||
(defn load-contacts []
|
(defn load-contacts []
|
||||||
(if fake-contacts?
|
(contacts/load-contacts
|
||||||
(swap! state/app-state update :contacts-ds
|
(fn [contacts]
|
||||||
#(clone-with-rows %
|
(swap! state/app-state update :contacts-ds
|
||||||
(vec (generate-contacts 100))))
|
#(clone-with-rows % contacts)))
|
||||||
(.getAll react-native-contacts
|
(fn [error]
|
||||||
(fn [error raw-contacts]
|
(toast (str error)))))
|
||||||
(when (not error)
|
|
||||||
(let [contacts (map (fn [contact]
|
|
||||||
(merge (generate-contact 1)
|
|
||||||
{:name (:givenName contact)
|
|
||||||
:photo (:thumbnailPath contact)}))
|
|
||||||
(js->clj raw-contacts :keywordize-keys true))]
|
|
||||||
(swap! state/app-state update :contacts-ds
|
|
||||||
#(clone-with-rows % contacts))))))))
|
|
||||||
|
|
||||||
(defui ContactsList
|
(defui ContactsList
|
||||||
static om/IQuery
|
static om/IQuery
|
||||||
|
19
src/messenger/android/crypt.cljs
Normal file
19
src/messenger/android/crypt.cljs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
(ns messenger.android.crypt
|
||||||
|
(:require [goog.crypt :refer [byteArrayToHex]])
|
||||||
|
(:import goog.crypt.Sha256))
|
||||||
|
|
||||||
|
(def base-64 (js/require "base-64"))
|
||||||
|
|
||||||
|
(def sha-256 (Sha256.))
|
||||||
|
|
||||||
|
(defn bytes-to-str [arr]
|
||||||
|
(apply str (map char arr)))
|
||||||
|
|
||||||
|
(defn str-to-bytes [s]
|
||||||
|
(map (comp int) s))
|
||||||
|
|
||||||
|
(defn encrypt [s]
|
||||||
|
(.reset sha-256)
|
||||||
|
(.update sha-256 s)
|
||||||
|
(-> (.digest sha-256)
|
||||||
|
byteArrayToHex))
|
@ -11,7 +11,9 @@
|
|||||||
[syng-im.protocol.whisper :as whisper]
|
[syng-im.protocol.whisper :as whisper]
|
||||||
[messenger.state :as state]
|
[messenger.state :as state]
|
||||||
[messenger.android.utils :refer [log toast http-post]]
|
[messenger.android.utils :refer [log toast http-post]]
|
||||||
|
[messenger.android.crypt :refer [encrypt]]
|
||||||
[messenger.android.resources :as res]
|
[messenger.android.resources :as res]
|
||||||
|
[messenger.android.contacts :as contacts]
|
||||||
[messenger.android.contacts-list :refer [contacts-list]]))
|
[messenger.android.contacts-list :refer [contacts-list]]))
|
||||||
|
|
||||||
(def nav-atom (atom nil))
|
(def nav-atom (atom nil))
|
||||||
@ -21,11 +23,29 @@
|
|||||||
(.replace @nav-atom (clj->js {:component contacts-list
|
(.replace @nav-atom (clj->js {:component contacts-list
|
||||||
:name "contacts-list"}))))
|
:name "contacts-list"}))))
|
||||||
|
|
||||||
(defn handle-send-check-contacts-response []
|
(defn handle-load-contacts-identities-response [identities]
|
||||||
(show-home-view))
|
(show-home-view))
|
||||||
|
|
||||||
(defn send-check-contacts []
|
(defn get-contacts-by-hash [contacts]
|
||||||
)
|
(reduce (fn [m contact]
|
||||||
|
(let [number (get-in contact [:phone-numbers :number])
|
||||||
|
hash (encrypt number)]
|
||||||
|
(assoc m hash number)))
|
||||||
|
contacts))
|
||||||
|
|
||||||
|
(defn send-load-contacts-identities [contacts]
|
||||||
|
(let [contacts-by-hash (get-contacts-by-hash contacts)
|
||||||
|
data (keys contacts-by-hash)]
|
||||||
|
(http-post "get-contacts" data
|
||||||
|
handle-load-contacts-identities-response
|
||||||
|
(fn [error]
|
||||||
|
(toast (str error))))))
|
||||||
|
|
||||||
|
(defn load-contacts []
|
||||||
|
(contacts/load-contacts
|
||||||
|
send-load-contacts-identities
|
||||||
|
(fn [error]
|
||||||
|
(toast (str error)))))
|
||||||
|
|
||||||
(defn handle-send-code-response [body]
|
(defn handle-send-code-response [body]
|
||||||
(log body)
|
(log body)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user