Skip to content

Commit

Permalink
move status native module
Browse files Browse the repository at this point in the history
  • Loading branch information
flexsurfer committed Apr 26, 2023
1 parent 0ca6ee3 commit c227fea
Show file tree
Hide file tree
Showing 52 changed files with 197 additions and 322 deletions.
10 changes: 5 additions & 5 deletions .carve_ignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ status-im.chat.models.message-content/actions
status-im.chat.models.message-content/blank-string
status-im.chat.models.message-content/sorted-ranges
status-im.ethereum.mnemonic/words->passphrase
status-im.native-module.core/listener
status-im.native-module.core/multiaccount-reset
status-im.native-module.core/extract-group-membership-signatures
status-im.native-module.core/sign-group-membership
status-im.native-module.core/update-mailservers
native-module.core/listener
native-module.core/multiaccount-reset
native-module.core/extract-group-membership-signatures
native-module.core/sign-group-membership
native-module.core/update-mailservers
status-im.ethereum.abi-spec/bytes-to-hex
status-im.android.core/init
status-im.chat.models.message/transport-keys
Expand Down
127 changes: 12 additions & 115 deletions src/status_im/native_module/core.cljs → src/native_module/core.cljs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
(ns status-im.native-module.core
(ns native-module.core
(:require ["react-native" :as react-native]
[re-frame.core :as re-frame]
[status-im2.utils.validators :as validators]
[status-im.utils.platform :as platform]
[status-im.utils.react-native :as react-native-utils]
[status-im.utils.types :as types]
[utils.validators :as validators]
[taoensso.timbre :as log]
[status-im2.constants :as constants]))
[react-native.platform :as platform]
[react-native.core :as rn]
[utils.transforms :as types]))

(defn status
[]
(when (exists? (.-NativeModules react-native))
(.-Status ^js (.-NativeModules react-native))))

(def adjust-resize 16)
(defn init
[handler]
(.addListener ^js rn/device-event-emitter "gethEvent" #(handler (.-jsonEvent ^js %))))

(defn clear-web-data
[]
Expand Down Expand Up @@ -72,15 +72,6 @@
accounts-data
chat-key)))

(defn login
"NOTE: beware, the password has to be sha3 hashed"
[key-uid account-data hashed-password]
(log/debug "[native-module] login")
(clear-web-data)
(init-keystore
key-uid
#(.login ^js (status) account-data hashed-password)))

(defn login-with-config
"NOTE: beware, the password has to be sha3 hashed"
[key-uid account-data hashed-password config]
Expand Down Expand Up @@ -123,11 +114,6 @@
(clear-web-data)
(.logout ^js (status)))

(defonce listener
(.addListener ^js react-native-utils/device-event-emitter
"gethEvent"
#(re-frame/dispatch [:signals/signal-received (.-jsonEvent ^js %)])))

(defn multiaccount-load-account
"NOTE: beware, the password has to be sha3 hashed
Expand All @@ -141,14 +127,6 @@
:password hashed-password})
callback))

(defn multiaccount-reset
"TODO: this function is not used anywhere
if usage isn't planned, remove"
[callback]
(log/debug "[native-module] multiaccount-reset")
(.multiAccountReset ^js (status)
callback))

(defn multiaccount-derive-addresses
"NOTE: this should be named derive-accounts
this only derive addresses, they still need to be stored
Expand Down Expand Up @@ -298,43 +276,13 @@
:key key})
(.deserializeAndCompressKey ^js (status) key callback))


(defn public-key->compressed-key
"Provides public key to status-go and gets back a compressed key via serialization"
[public-key callback]
(let [serialization-key constants/serialization-key
multi-code-prefix constants/multi-code-prefix
multi-code-key (str multi-code-prefix (subs public-key 2))]
(log/info "[native-module] Serializing public key"
{:fn :public-key->compressed-key
:public-key public-key
:multi-code-key multi-code-key})
(.multiformatSerializePublicKey ^js (status) multi-code-key serialization-key callback)))

(defn compressed-key->public-key
"Provides compressed key to status-go and gets back the uncompressed public key via deserialization"
[public-key callback]
(let [deserialization-key constants/deserialization-key]
(log/info "[native-module] Deserializing compressed key"
{:fn :compressed-key->public-key
:public-key public-key})
(.multiformatDeserializePublicKey ^js (status) public-key deserialization-key callback)))

(defn decompress-public-key
"Provides compressed key to status-go and gets back the uncompressed public key"
[public-key callback]
(log/info "[native-module] Decompressing public key"
{:fn :decompress-public-key
[public-key deserialization-key callback]
(log/info "[native-module] Deserializing compressed key"
{:fn :compressed-key->public-key
:public-key public-key})
(.decompressPublicKey ^js (status) public-key callback))

(defn compress-public-key
"Provides a public key to status-go and gets back a 33bit compressed key back"
[public-key callback]
(log/info "[native-module] Compressing public key"
{:fn :compress-public-key
:public-key public-key})
(.compressPublicKey ^js (status) public-key callback))
(.multiformatDeserializePublicKey ^js (status) public-key deserialization-key callback))

(defn hash-typed-data
"used for keycard"
Expand Down Expand Up @@ -388,11 +336,6 @@
(log/debug "[native-module] send-logs")
(.sendLogs ^js (status) dbJson js-logs callback))

(defn add-peer
[enode on-result]
(log/debug "[native-module] add-peer")
(.addPeer ^js (status) enode on-result))

(defn close-application
[]
(log/debug "[native-module] close-application")
Expand All @@ -408,11 +351,6 @@
(log/debug "[native-module] app-state-change")
(.appStateChange ^js (status) state))

(defn stop-local-notifications
[]
(log/debug "[native-module] stop-local-notifications")
(.stopLocalNotifications ^js (status)))

(defn start-local-notifications
[]
(log/debug "[native-module] start-local-notifications")
Expand All @@ -433,26 +371,11 @@
:build-id (.-buildId status)
:device-id (.-deviceId status)}))

(defn extract-group-membership-signatures
[signature-pairs callback]
(log/debug "[native-module] extract-group-membership-signatures")
(.extractGroupMembershipSignatures ^js (status) signature-pairs callback))

(defn sign-group-membership
[content callback]
(log/debug "[native-module] sign-group-membership")
(.signGroupMembership ^js (status) content callback))

(defn get-node-config
[callback]
(log/debug "[native-module] get-node-config")
(.getNodeConfig ^js (status) callback))

(defn update-mailservers
[enodes on-result]
(log/debug "[native-module] update-mailservers")
(.updateMailservers ^js (status) enodes on-result))

(defn toggle-webview-debug
[on]
(log/debug "[native-module] toggle-webview-debug" on)
Expand Down Expand Up @@ -483,12 +406,6 @@
(when (validators/valid-public-key? public-key)
(.generateAlias ^js (status) public-key)))

(defn generate-gfycat-async
"Generate a 3 words random name based on the user public-key, asynchronously"
[public-key callback]
(when (validators/valid-public-key? public-key)
(.generateAliasAsync ^js (status) public-key callback)))

(defn identicon
"Generate a icon based on a string, synchronously"
[seed]
Expand All @@ -500,11 +417,6 @@
(log/debug "[native-module] encode-transfer")
(.encodeTransfer ^js (status) to-norm amount-hex))

(defn encode-function-call
[method params]
(log/debug "[native-module] encode-function-call")
(.encodeFunctionCall ^js (status) method (types/clj->json params)))

(defn decode-parameters
[bytes-string types]
(log/debug "[native-module] decode-parameters")
Expand Down Expand Up @@ -555,11 +467,6 @@
(log/debug "[native-module] to-checksum-address")
(.toChecksumAddress ^js (status) address))

(defn identicon-async
"Generate a icon based on a string, asynchronously"
[seed callback]
(.identiconAsync ^js (status) seed callback))

(defn gfycat-identicon-async
"Generate an icon based on a string and 3 words random name asynchronously"
[seed callback]
Expand All @@ -585,16 +492,6 @@
(log/debug "[native-module] delete-imported-key")
(.deleteImportedKey ^js (status) key-uid address hashed-password callback))

(defn activate-keep-awake
[]
(log/debug "[native-module] activateKeepAwake")
(.activateKeepAwake ^js (status)))

(defn deactivate-keep-awake
[]
(log/debug "[native-module] deactivateKeepAwake")
(.deactivateKeepAwake ^js (status)))

(defn reset-keyboard-input
[input selection]
(log/debug "[native-module] resetKeyboardInput")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(ns status-im.native-module.core-test
(ns native-module.core-test
(:require [cljs.test :refer [deftest is testing]]
[status-im.native-module.core :as status]))
[native-module.core :as native-module]))

(deftest identicon-test
(testing "check if identicon test works"
(is
(=
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAjklEQVR4nOzXsQmAMBQGYRV3cUAdQwd0Gm2sJIWSBI6f+0oR8XjwSKYhhCE0htAYQmMITUzI/PXF49yv0vN12cYWP1L7/ZiJGEJjCE31xvm7bXptv5iJGEJjCE31WasVz1oPQ2gMoWlyuyvpfaN8i5mIITSG0BhCYwiNIeokZiKG0BhCYwiNITR3AAAA//+A3RtWaKqXgQAAAABJRU5ErkJggg=="
(status/identicon "a")))))
(native-module/identicon "a")))))
2 changes: 2 additions & 0 deletions src/react_native/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

(def dismiss-keyboard! #(.dismiss keyboard))

(def device-event-emitter (.-DeviceEventEmitter ^js react-native))

(defn hide-splash-screen
[]
(.hide ^js (-> react-native .-NativeModules .-SplashScreen)))
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/add_new/db.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns status-im.add-new.db
(:require [cljs.spec.alpha :as spec]
[status-im.ethereum.ens :as ens]
[status-im2.utils.validators :as validators]))
[utils.validators :as validators]))

(defn own-public-key?
[{:keys [multiaccount]} public-key]
Expand Down
6 changes: 3 additions & 3 deletions src/status_im/browser/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[status-im.ethereum.ens :as ens]
[utils.i18n :as i18n]
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.native-module.core :as status]
[native-module.core :as native-module]
[status-im.signing.core :as signing]
[status-im.ui.components.list-selection :as list-selection]
[utils.re-frame :as rf]
Expand Down Expand Up @@ -537,7 +537,7 @@
(re-frame/reg-fx
:browser/call-rpc
(fn [[payload callback]]
(status/call-rpc
(native-module/call-rpc
(types/clj->json payload)
(fn [response]
(if (= "" response)
Expand All @@ -559,7 +559,7 @@
(re-frame/reg-fx
:browser/clear-web-data
(fn []
(status/clear-web-data)))
(native-module/clear-web-data)))

(defn share-link
[url]
Expand Down
8 changes: 4 additions & 4 deletions src/status_im/chat/models/mentions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[utils.re-frame :as rf]
[status-im.utils.platform :as platform]
[taoensso.timbre :as log]
[status-im.native-module.core :as status]))
[native-module.core :as native-module]))

(defn- transfer-input-segments
[segments]
Expand Down Expand Up @@ -56,8 +56,8 @@
:ensVerified :ens-verified
:added :added?
:displayName :display-name
:searchedText :searched-text
})))
:searchedText :searched-text})))

{}
mentionable-users))
(defn- transfer-mention-result
Expand Down Expand Up @@ -237,7 +237,7 @@
::reset-text-input-cursor
(fn [[ref cursor]]
(when ref
(status/reset-keyboard-input
(native-module/reset-keyboard-input
(rn/find-node-handle (react/current-ref ref))
cursor))))

Expand Down
10 changes: 5 additions & 5 deletions src/status_im/ethereum/core.cljs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
(ns status-im.ethereum.core
(:require [clojure.string :as string]
[status-im.ethereum.eip55 :as eip55]
[status-im.native-module.core :as status]))
[native-module.core :as native-module]))

(defn sha3
[s]
(when s
(status/sha3 (str s))))
(native-module/sha3 (str s))))

(defn utf8-to-hex
[s]
(let [hex (status/utf8-to-hex (str s))]
(let [hex (native-module/utf8-to-hex (str s))]
(if (empty? hex)
nil
hex)))

(defn hex-to-utf8
[s]
(let [utf8 (status/hex-to-utf8 s)]
(let [utf8 (native-module/hex-to-utf8 s)]
(if (empty? utf8)
nil
utf8)))
Expand Down Expand Up @@ -118,7 +118,7 @@
(defn address?
[s]
(when s
(status/address? s)))
(native-module/address? s)))

(defn network->chain-id
[network]
Expand Down
6 changes: 3 additions & 3 deletions src/status_im/ethereum/eip55.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
e.g. 0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"
(:require [clojure.string :as string]
[status-im.native-module.core :as status]))
[native-module.core :as native-module]))

(def hex-prefix "0x")

(defn address->checksum
"Converts an arbitrary case address to one with correct checksum case."
[address]
(when address
(status/to-checksum-address
(native-module/to-checksum-address
(if (string/starts-with? address hex-prefix)
address
(str hex-prefix address)))))

(defn valid-address-checksum?
"Checks address checksum validity."
[address]
(status/check-address-checksum address))
(native-module/check-address-checksum address))
4 changes: 2 additions & 2 deletions src/status_im/ethereum/encode.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns status-im.ethereum.encode
(:require [status-im.native-module.core :as status]))
(:require [native-module.core :as native-module]))

(defn uint
[x]
(str "0x" (status/number-to-hex x)))
(str "0x" (native-module/number-to-hex x)))
Loading

0 comments on commit c227fea

Please sign in to comment.