2023-04-26 16:14:14 +00:00
|
|
|
(ns native-module.core
|
2022-12-20 14:45:37 +00:00
|
|
|
(:require ["react-native" :as react-native]
|
2023-04-26 16:14:14 +00:00
|
|
|
[utils.validators :as validators]
|
2023-01-04 12:54:11 +00:00
|
|
|
[taoensso.timbre :as log]
|
2023-04-26 16:14:14 +00:00
|
|
|
[react-native.platform :as platform]
|
|
|
|
[react-native.core :as rn]
|
2023-06-29 08:35:38 +00:00
|
|
|
[utils.transforms :as types]
|
|
|
|
[clojure.string :as string]))
|
2019-09-04 18:59:41 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn status
|
|
|
|
[]
|
2019-09-07 12:57:22 +00:00
|
|
|
(when (exists? (.-NativeModules react-native))
|
|
|
|
(.-Status ^js (.-NativeModules react-native))))
|
2017-09-05 14:14:45 +00:00
|
|
|
|
2023-04-26 16:14:14 +00:00
|
|
|
(defn init
|
|
|
|
[handler]
|
|
|
|
(.addListener ^js rn/device-event-emitter "gethEvent" #(handler (.-jsonEvent ^js %))))
|
2017-09-05 14:14:45 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn clear-web-data
|
|
|
|
[]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] clear-web-data")
|
2019-09-04 18:59:41 +00:00
|
|
|
(when (status)
|
2019-09-07 12:57:22 +00:00
|
|
|
(.clearCookies ^js (status))
|
|
|
|
(.clearStorageAPIs ^js (status))))
|
2019-09-04 18:59:41 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn init-keystore
|
|
|
|
[key-uid callback]
|
2020-07-09 10:14:38 +00:00
|
|
|
(log/debug "[native-module] init-keystore" key-uid)
|
|
|
|
(.initKeystore ^js (status) key-uid callback))
|
2019-07-31 16:10:38 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn open-accounts
|
|
|
|
[callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] open-accounts")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.openAccounts ^js (status) #(callback (types/json->clj %))))
|
2017-08-21 14:49:31 +00:00
|
|
|
|
2019-09-04 18:59:41 +00:00
|
|
|
(defn prepare-dir-and-update-config
|
2020-07-09 10:14:38 +00:00
|
|
|
[key-uid config callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] prepare-dir-and-update-config")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.prepareDirAndUpdateConfig ^js (status)
|
2020-07-09 10:14:38 +00:00
|
|
|
key-uid
|
2019-09-04 18:59:41 +00:00
|
|
|
config
|
|
|
|
#(callback (types/json->clj %))))
|
2018-12-19 12:20:03 +00:00
|
|
|
|
2019-08-01 20:11:59 +00:00
|
|
|
(defn save-account-and-login
|
2019-09-04 20:59:44 +00:00
|
|
|
"NOTE: beware, the password has to be sha3 hashed"
|
2020-07-09 10:14:38 +00:00
|
|
|
[key-uid multiaccount-data hashed-password settings config accounts-data]
|
2019-12-05 06:02:31 +00:00
|
|
|
(log/debug "[native-module] save-account-and-login"
|
2022-12-20 14:45:37 +00:00
|
|
|
"multiaccount-data"
|
|
|
|
multiaccount-data)
|
2019-09-04 18:59:41 +00:00
|
|
|
(clear-web-data)
|
2020-07-09 10:14:38 +00:00
|
|
|
(init-keystore
|
|
|
|
key-uid
|
|
|
|
#(.saveAccountAndLogin
|
2022-12-20 14:45:37 +00:00
|
|
|
^js (status)
|
|
|
|
multiaccount-data
|
|
|
|
hashed-password
|
|
|
|
settings
|
|
|
|
config
|
|
|
|
accounts-data)))
|
2018-11-26 15:52:29 +00:00
|
|
|
|
2020-04-24 07:45:54 +00:00
|
|
|
(defn save-multiaccount-and-login-with-keycard
|
2019-08-15 14:44:25 +00:00
|
|
|
"NOTE: chat-key is a whisper private key sent from keycard"
|
2020-07-09 10:14:38 +00:00
|
|
|
[key-uid multiaccount-data password settings config accounts-data chat-key]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] save-account-and-login-with-keycard")
|
2020-07-09 10:14:38 +00:00
|
|
|
(init-keystore
|
|
|
|
key-uid
|
|
|
|
#(.saveAccountAndLoginWithKeycard
|
2022-12-20 14:45:37 +00:00
|
|
|
^js (status)
|
|
|
|
multiaccount-data
|
|
|
|
password
|
|
|
|
settings
|
|
|
|
config
|
|
|
|
accounts-data
|
|
|
|
chat-key)))
|
2019-08-15 14:44:25 +00:00
|
|
|
|
2022-06-09 12:42:36 +00:00
|
|
|
(defn login-with-config
|
|
|
|
"NOTE: beware, the password has to be sha3 hashed"
|
|
|
|
[key-uid account-data hashed-password config]
|
|
|
|
(log/debug "[native-module] loginWithConfig")
|
|
|
|
(clear-web-data)
|
|
|
|
(let [config (if config (types/clj->json config) "")]
|
|
|
|
(init-keystore
|
|
|
|
key-uid
|
|
|
|
#(.loginWithConfig ^js (status) account-data hashed-password config))))
|
|
|
|
|
2023-05-24 15:04:04 +00:00
|
|
|
(defn login-account
|
|
|
|
"NOTE: beware, the password has to be sha3 hashed"
|
|
|
|
[{:keys [keyUid] :as request}]
|
|
|
|
(log/debug "[native-module] loginWithConfig")
|
|
|
|
(clear-web-data)
|
|
|
|
(init-keystore
|
|
|
|
keyUid
|
|
|
|
#(.loginAccount ^js (status) (types/clj->json request))))
|
|
|
|
|
2023-03-22 13:51:38 +00:00
|
|
|
(defn create-account-and-login
|
|
|
|
[request]
|
|
|
|
(.createAccountAndLogin ^js (status) (types/clj->json request)))
|
|
|
|
|
2023-03-13 10:02:25 +00:00
|
|
|
(defn restore-account-and-login
|
|
|
|
[request]
|
|
|
|
(.restoreAccountAndLogin ^js (status) (types/clj->json request)))
|
|
|
|
|
2021-01-18 13:01:57 +00:00
|
|
|
(defn export-db
|
|
|
|
"NOTE: beware, the password has to be sha3 hashed"
|
2021-11-01 12:08:54 +00:00
|
|
|
[key-uid account-data hashed-password callback]
|
2021-01-18 13:01:57 +00:00
|
|
|
(log/debug "[native-module] export-db")
|
|
|
|
(clear-web-data)
|
|
|
|
(init-keystore
|
|
|
|
key-uid
|
2021-11-01 12:08:54 +00:00
|
|
|
#(.exportUnencryptedDatabase ^js (status) account-data hashed-password callback)))
|
2021-01-18 13:01:57 +00:00
|
|
|
|
|
|
|
(defn import-db
|
|
|
|
"NOTE: beware, the password has to be sha3 hashed"
|
|
|
|
[key-uid account-data hashed-password]
|
|
|
|
(log/debug "[native-module] import-db")
|
|
|
|
(clear-web-data)
|
|
|
|
(init-keystore
|
|
|
|
key-uid
|
|
|
|
#(.importUnencryptedDatabase ^js (status) account-data hashed-password)))
|
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn logout
|
|
|
|
[]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] logout")
|
2019-09-04 18:59:41 +00:00
|
|
|
(clear-web-data)
|
2019-09-07 12:57:22 +00:00
|
|
|
(.logout ^js (status)))
|
2019-09-04 18:59:41 +00:00
|
|
|
|
|
|
|
(defn multiaccount-load-account
|
2019-09-04 20:59:44 +00:00
|
|
|
"NOTE: beware, the password has to be sha3 hashed
|
|
|
|
|
|
|
|
this function is used after storing an account when you still want to
|
2019-09-04 18:59:41 +00:00
|
|
|
derive accounts from it, because saving an account flushes the loaded keys
|
|
|
|
from memory"
|
2019-09-04 20:59:44 +00:00
|
|
|
[address hashed-password callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] multiaccount-load-account")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.multiAccountLoadAccount ^js (status)
|
2022-12-20 14:45:37 +00:00
|
|
|
(types/clj->json {:address address
|
2019-09-04 20:59:44 +00:00
|
|
|
:password hashed-password})
|
2019-09-04 18:59:41 +00:00
|
|
|
callback))
|
|
|
|
|
|
|
|
(defn multiaccount-derive-addresses
|
|
|
|
"NOTE: this should be named derive-accounts
|
|
|
|
this only derive addresses, they still need to be stored
|
|
|
|
with `multiaccount-store-derived` if you want to be able to
|
|
|
|
reuse the derived addresses later"
|
|
|
|
[account-id paths callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] multiaccount-derive-addresses")
|
2019-09-04 18:59:41 +00:00
|
|
|
(when (status)
|
2019-09-07 12:57:22 +00:00
|
|
|
(.multiAccountDeriveAddresses ^js (status)
|
2019-09-04 18:59:41 +00:00
|
|
|
(types/clj->json {:accountID account-id
|
2022-12-20 14:45:37 +00:00
|
|
|
:paths paths})
|
2019-09-04 18:59:41 +00:00
|
|
|
callback)))
|
|
|
|
|
|
|
|
(defn multiaccount-store-account
|
2019-09-04 20:59:44 +00:00
|
|
|
"NOTE: beware, the password has to be sha3 hashed
|
|
|
|
|
|
|
|
this stores the account and flush keys in memory so
|
2019-09-04 18:59:41 +00:00
|
|
|
in order to also store derived accounts like initial wallet
|
|
|
|
and chat accounts, you need to load the account again with
|
|
|
|
`multiaccount-load-account` before using `multiaccount-store-derived`
|
|
|
|
and the id of the account stored will have changed"
|
2020-07-09 10:14:38 +00:00
|
|
|
[account-id key-uid hashed-password callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] multiaccount-store-account")
|
2019-09-04 18:59:41 +00:00
|
|
|
(when (status)
|
2020-07-09 10:14:38 +00:00
|
|
|
(init-keystore
|
|
|
|
key-uid
|
2022-12-20 14:45:37 +00:00
|
|
|
#(.multiAccountStoreAccount ^js (status)
|
|
|
|
(types/clj->json {:accountID account-id
|
|
|
|
:password hashed-password})
|
|
|
|
callback))))
|
2019-09-04 18:59:41 +00:00
|
|
|
|
|
|
|
(defn multiaccount-store-derived
|
2019-09-04 20:59:44 +00:00
|
|
|
"NOTE: beware, the password has to be sha3 hashed"
|
2020-07-09 10:14:38 +00:00
|
|
|
[account-id key-uid paths hashed-password callback]
|
|
|
|
(log/debug "[native-module] multiaccount-store-derived"
|
2022-12-20 14:45:37 +00:00
|
|
|
"account-id"
|
|
|
|
account-id)
|
2020-07-09 10:14:38 +00:00
|
|
|
(init-keystore
|
|
|
|
key-uid
|
2022-12-20 14:45:37 +00:00
|
|
|
#(.multiAccountStoreDerived ^js (status)
|
|
|
|
(types/clj->json {:accountID account-id
|
|
|
|
:paths paths
|
|
|
|
:password hashed-password})
|
|
|
|
callback)))
|
2019-09-04 18:59:41 +00:00
|
|
|
|
|
|
|
(defn multiaccount-generate-and-derive-addresses
|
|
|
|
"used to generate multiple multiaccounts for onboarding
|
|
|
|
NOTE: nothing is saved so you will need to use
|
|
|
|
`multiaccount-store-account` on the selected multiaccount
|
|
|
|
to store the key"
|
|
|
|
[n mnemonic-length paths callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] multiaccount-generate-and-derive-addresses")
|
2022-12-20 14:45:37 +00:00
|
|
|
(.multiAccountGenerateAndDeriveAddresses ^js (status)
|
|
|
|
(types/clj->json {:n n
|
|
|
|
:mnemonicPhraseLength mnemonic-length
|
|
|
|
:bip39Passphrase ""
|
|
|
|
:paths paths})
|
|
|
|
callback))
|
2019-09-04 18:59:41 +00:00
|
|
|
|
|
|
|
(defn multiaccount-import-mnemonic
|
|
|
|
[mnemonic password callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] multiaccount-import-mnemonic")
|
2022-12-20 14:45:37 +00:00
|
|
|
(.multiAccountImportMnemonic ^js (status)
|
|
|
|
(types/clj->json {:mnemonicPhrase mnemonic
|
|
|
|
;;NOTE this is not the multiaccount password
|
|
|
|
:Bip39Passphrase password})
|
|
|
|
callback))
|
2019-08-01 15:49:33 +00:00
|
|
|
|
2020-02-28 11:37:16 +00:00
|
|
|
(defn multiaccount-import-private-key
|
|
|
|
[private-key callback]
|
|
|
|
(log/debug "[native-module] multiaccount-import-private-key")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.multiAccountImportPrivateKey ^js (status)
|
2022-12-20 14:45:37 +00:00
|
|
|
(types/clj->json {:privateKey private-key})
|
2020-02-28 11:37:16 +00:00
|
|
|
callback))
|
|
|
|
|
2019-09-04 20:59:44 +00:00
|
|
|
(defn verify
|
|
|
|
"NOTE: beware, the password has to be sha3 hashed"
|
|
|
|
[address hashed-password callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] verify")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.verify ^js (status) address hashed-password callback))
|
2018-11-26 15:52:29 +00:00
|
|
|
|
2021-07-13 13:41:45 +00:00
|
|
|
(defn verify-database-password
|
|
|
|
"NOTE: beware, the password has to be sha3 hashed"
|
|
|
|
[key-uid hashed-password callback]
|
|
|
|
(log/debug "[native-module] verify-database-password")
|
|
|
|
(.verifyDatabasePassword ^js (status) key-uid hashed-password callback))
|
|
|
|
|
2018-12-04 13:49:09 +00:00
|
|
|
(defn login-with-keycard
|
2023-07-25 07:03:57 +00:00
|
|
|
[{:keys [key-uid multiaccount-data password chat-key node-config]}]
|
2019-11-28 09:57:58 +00:00
|
|
|
(log/debug "[native-module] login-with-keycard")
|
2019-09-04 18:59:41 +00:00
|
|
|
(clear-web-data)
|
2020-07-09 10:14:38 +00:00
|
|
|
(init-keystore
|
|
|
|
key-uid
|
2023-07-25 07:03:57 +00:00
|
|
|
#(.loginWithKeycard ^js (status) multiaccount-data password chat-key (types/clj->json node-config))))
|
2018-12-04 13:49:09 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn set-soft-input-mode
|
|
|
|
[mode]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] set-soft-input-mode")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.setSoftInputMode ^js (status) mode))
|
2017-09-05 14:14:45 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn call-rpc
|
|
|
|
[payload callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] call-rpc")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.callRPC ^js (status) payload callback))
|
2017-09-05 14:14:45 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn call-private-rpc
|
|
|
|
[payload callback]
|
2019-09-07 12:57:22 +00:00
|
|
|
(.callPrivateRPC ^js (status) payload callback))
|
2018-04-18 08:49:15 +00:00
|
|
|
|
2019-09-04 20:59:44 +00:00
|
|
|
(defn hash-transaction
|
|
|
|
"used for keycard"
|
|
|
|
[rpcParams callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] hash-transaction")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.hashTransaction ^js (status) rpcParams callback))
|
2019-02-28 15:09:21 +00:00
|
|
|
|
2019-09-04 20:59:44 +00:00
|
|
|
(defn hash-message
|
|
|
|
"used for keycard"
|
|
|
|
[message callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] hash-message")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.hashMessage ^js (status) message callback))
|
2019-04-03 08:46:53 +00:00
|
|
|
|
2023-07-28 09:52:58 +00:00
|
|
|
(defn start-searching-for-local-pairing-peers
|
|
|
|
"starts a UDP multicast beacon that both listens for and broadcasts to LAN peers"
|
|
|
|
[callback]
|
|
|
|
(log/info "[native-module] Start Searching for Local Pairing Peers"
|
|
|
|
{:fn :start-searching-for-local-pairing-peers})
|
|
|
|
(.startSearchForLocalPairingPeers ^js (status) callback))
|
|
|
|
|
2023-06-09 10:25:15 +00:00
|
|
|
(defn local-pairing-preflight-outbound-check
|
|
|
|
"Checks whether the device has allows connecting to the local server"
|
|
|
|
[callback]
|
|
|
|
(log/info "[native-module] Performing local pairing preflight check")
|
|
|
|
(when platform/ios?
|
|
|
|
(.localPairingPreflightOutboundCheck ^js (status) callback)))
|
|
|
|
|
2022-12-16 13:10:56 +00:00
|
|
|
(defn get-connection-string-for-bootstrapping-another-device
|
|
|
|
"Generates connection string form status-go for the purpose of local pairing on the sender end"
|
|
|
|
[config-json callback]
|
|
|
|
(log/info "[native-module] Fetching Connection String"
|
2022-12-20 14:45:37 +00:00
|
|
|
{:fn :get-connection-string-for-bootstrapping-another-device
|
2022-12-16 13:10:56 +00:00
|
|
|
:config-json config-json})
|
|
|
|
(.getConnectionStringForBootstrappingAnotherDevice ^js (status) config-json callback))
|
|
|
|
|
|
|
|
(defn input-connection-string-for-bootstrapping
|
|
|
|
"Provides connection string to status-go for the purpose of local pairing on the receiver end"
|
|
|
|
[connection-string config-json callback]
|
|
|
|
(log/info "[native-module] Sending Connection String"
|
2022-12-20 14:45:37 +00:00
|
|
|
{:fn :input-connection-string-for-bootstrapping
|
|
|
|
:config-json config-json
|
2022-12-16 13:10:56 +00:00
|
|
|
:connection-string connection-string})
|
|
|
|
(.inputConnectionStringForBootstrapping ^js (status) connection-string config-json callback))
|
|
|
|
|
2023-01-04 12:54:11 +00:00
|
|
|
(defn deserialize-and-compress-key
|
|
|
|
"Provides a community id (public key) to status-go which is first deserialized
|
|
|
|
and then compressed. Example input/output :
|
|
|
|
input key = zQ3shTAten2v9CwyQD1Kc7VXAqNPDcHZAMsfbLHCZEx6nFqk9 and
|
|
|
|
output key = 0x025596a7ff87da36860a84b0908191ce60a504afc94aac93c1abd774f182967ce6"
|
Lint & fix some shadowed core Clojure(Script) vars (#16500)
It's well known that shadowing core Clojure vars can lead to unexpected bugs. In
fact, it's a common source of bugs in other languages too. In the status-mobile
repository there are, in total, 562 shadowed vars, ~500 are core vars. Excluding
the "old code" we still have 285 offenders.
In status-mobile I've already seen two bugs caused by shadowed vars, both with
the shadowed var "name". But probably other problems happened in the past, and
others will happen in the future if we don't do something about this. This PR is
also my response to my frustration trying to review PRs and checking for
shadowed vars, humans were not meant for that!
In this commit we are enabling ":shadowed-var" to lint certain (not all) core
vars as errors (not warnings). In future PRs we can gradually unshadow more
vars. For the record, name is shadowed 40 times in the new code and 130 in
total, and type is shadowed 93 times in the new code and 124 in total!
What about non-core vars, should we allow shadowing? There are ~70 non-core
shadowed vars. In my opinion, we should also lint and disallow shadowing
non-core vars, since it may cause the same kind of bugs of shadowing core vars.
But this decision can be left for another moment/issue, after we have fixed the
most prominent problem of shadowing core vars.
Which vars are unshadowed in this PR? I fixed 62 errors and unshadowed
cljs.core/iter, cljs.core/time, cljs.core/count, cljs.core/key,
clojure.core/key.
Resources:
- [clj-kondo linter: shadowed-var](https://github.com/clj-kondo/clj-kondo/blob/master/doc/linters.md#shadowed-var)
2023-07-06 10:28:07 +00:00
|
|
|
[input-key callback]
|
2023-01-04 12:54:11 +00:00
|
|
|
(log/info "[native-module] Deserializing and then compressing public key"
|
|
|
|
{:fn :deserialize-and-compress-key
|
Lint & fix some shadowed core Clojure(Script) vars (#16500)
It's well known that shadowing core Clojure vars can lead to unexpected bugs. In
fact, it's a common source of bugs in other languages too. In the status-mobile
repository there are, in total, 562 shadowed vars, ~500 are core vars. Excluding
the "old code" we still have 285 offenders.
In status-mobile I've already seen two bugs caused by shadowed vars, both with
the shadowed var "name". But probably other problems happened in the past, and
others will happen in the future if we don't do something about this. This PR is
also my response to my frustration trying to review PRs and checking for
shadowed vars, humans were not meant for that!
In this commit we are enabling ":shadowed-var" to lint certain (not all) core
vars as errors (not warnings). In future PRs we can gradually unshadow more
vars. For the record, name is shadowed 40 times in the new code and 130 in
total, and type is shadowed 93 times in the new code and 124 in total!
What about non-core vars, should we allow shadowing? There are ~70 non-core
shadowed vars. In my opinion, we should also lint and disallow shadowing
non-core vars, since it may cause the same kind of bugs of shadowing core vars.
But this decision can be left for another moment/issue, after we have fixed the
most prominent problem of shadowing core vars.
Which vars are unshadowed in this PR? I fixed 62 errors and unshadowed
cljs.core/iter, cljs.core/time, cljs.core/count, cljs.core/key,
clojure.core/key.
Resources:
- [clj-kondo linter: shadowed-var](https://github.com/clj-kondo/clj-kondo/blob/master/doc/linters.md#shadowed-var)
2023-07-06 10:28:07 +00:00
|
|
|
:key input-key})
|
|
|
|
(.deserializeAndCompressKey ^js (status) input-key callback))
|
2023-01-04 12:54:11 +00:00
|
|
|
|
|
|
|
(defn compressed-key->public-key
|
|
|
|
"Provides compressed key to status-go and gets back the uncompressed public key via deserialization"
|
2023-04-26 16:14:14 +00:00
|
|
|
[public-key deserialization-key callback]
|
|
|
|
(log/info "[native-module] Deserializing compressed key"
|
|
|
|
{:fn :compressed-key->public-key
|
2023-01-04 12:54:11 +00:00
|
|
|
:public-key public-key})
|
2023-04-26 16:14:14 +00:00
|
|
|
(.multiformatDeserializePublicKey ^js (status) public-key deserialization-key callback))
|
2023-01-04 12:54:11 +00:00
|
|
|
|
2019-09-04 20:59:44 +00:00
|
|
|
(defn hash-typed-data
|
|
|
|
"used for keycard"
|
|
|
|
[data callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] hash-typed-data")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.hashTypedData ^js (status) data callback))
|
2019-09-04 18:59:41 +00:00
|
|
|
|
2021-05-12 08:13:41 +00:00
|
|
|
(defn hash-typed-data-v4
|
|
|
|
"used for keycard"
|
|
|
|
[data callback]
|
|
|
|
(log/debug "[native-module] hash-typed-data-v4")
|
|
|
|
(.hashTypedDataV4 ^js (status) data callback))
|
|
|
|
|
2019-09-04 20:59:44 +00:00
|
|
|
(defn send-transaction-with-signature
|
|
|
|
"used for keycard"
|
|
|
|
[rpcParams sig callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] send-transaction-with-signature")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.sendTransactionWithSignature ^js (status) rpcParams sig callback))
|
2019-09-04 18:59:41 +00:00
|
|
|
|
2019-09-04 20:59:44 +00:00
|
|
|
(defn sign-message
|
|
|
|
"NOTE: beware, the password in rpcParams has to be sha3 hashed"
|
|
|
|
[rpcParams callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] sign-message")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.signMessage ^js (status) rpcParams callback))
|
2019-09-04 18:59:41 +00:00
|
|
|
|
2022-01-06 13:54:18 +00:00
|
|
|
(defn recover-message
|
|
|
|
[rpcParams callback]
|
|
|
|
(log/debug "[native-module] recover")
|
|
|
|
(.recover ^js (status) rpcParams callback))
|
|
|
|
|
2019-09-04 20:59:44 +00:00
|
|
|
(defn send-transaction
|
|
|
|
"NOTE: beware, the password has to be sha3 hashed"
|
|
|
|
[rpcParams hashed-password callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] send-transaction")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.sendTransaction ^js (status) rpcParams hashed-password callback))
|
2019-04-03 08:46:53 +00:00
|
|
|
|
2019-09-04 20:59:44 +00:00
|
|
|
(defn sign-typed-data
|
|
|
|
"NOTE: beware, the password has to be sha3 hashed"
|
|
|
|
[data account hashed-password callback]
|
2021-04-06 07:42:01 +00:00
|
|
|
(log/debug "[native-module] sign-typed-data")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.signTypedData ^js (status) data account hashed-password callback))
|
2019-02-28 15:09:21 +00:00
|
|
|
|
2021-04-06 07:42:01 +00:00
|
|
|
(defn sign-typed-data-v4
|
|
|
|
"NOTE: beware, the password has to be sha3 hashed"
|
|
|
|
[data account hashed-password callback]
|
|
|
|
(log/debug "[native-module] sign-typed-data-v4")
|
|
|
|
(.signTypedDataV4 ^js (status) data account hashed-password callback))
|
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn send-logs
|
|
|
|
[dbJson js-logs callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] send-logs")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.sendLogs ^js (status) dbJson js-logs callback))
|
2018-12-15 18:57:00 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn close-application
|
|
|
|
[]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] close-application")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.closeApplication ^js (status)))
|
2018-02-26 02:27:29 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn connection-change
|
|
|
|
[type expensive?]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] connection-change")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.connectionChange ^js (status) type (boolean expensive?)))
|
2018-03-16 12:01:10 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn app-state-change
|
|
|
|
[state]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] app-state-change")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.appStateChange ^js (status) state))
|
2018-05-01 10:27:04 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn start-local-notifications
|
|
|
|
[]
|
2020-09-25 12:35:10 +00:00
|
|
|
(log/debug "[native-module] start-local-notifications")
|
|
|
|
(.startLocalNotifications ^js (status)))
|
2020-07-28 11:10:42 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn set-blank-preview-flag
|
|
|
|
[flag]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] set-blank-preview-flag")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.setBlankPreviewFlag ^js (status) flag))
|
2019-05-08 12:26:39 +00:00
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn get-device-model-info
|
|
|
|
[]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] get-device-model-info")
|
2019-09-04 18:59:41 +00:00
|
|
|
;;NOTE: we have to check for status module because of tests
|
2023-09-01 11:54:53 +00:00
|
|
|
(when-let [^js status-module (status)]
|
|
|
|
{:model (.-model status-module)
|
|
|
|
:brand (.-brand status-module)
|
|
|
|
:build-id (.-buildId status-module)
|
|
|
|
:device-id (.-deviceId status-module)}))
|
2019-09-04 18:59:41 +00:00
|
|
|
|
2023-06-29 08:35:38 +00:00
|
|
|
(defn get-installation-name
|
|
|
|
[]
|
|
|
|
;; NOTE(rasom): Only needed for android devices currently
|
|
|
|
(when platform/android?
|
|
|
|
(string/join " "
|
|
|
|
((juxt :model :device-id)
|
|
|
|
(get-device-model-info)))))
|
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn get-node-config
|
|
|
|
[callback]
|
2021-05-31 13:10:54 +00:00
|
|
|
(log/debug "[native-module] get-node-config")
|
|
|
|
(.getNodeConfig ^js (status) callback))
|
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn toggle-webview-debug
|
|
|
|
[on]
|
2020-08-06 13:49:35 +00:00
|
|
|
(log/debug "[native-module] toggle-webview-debug" on)
|
|
|
|
(.toggleWebviewDebug ^js (status) on))
|
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn rooted-device?
|
|
|
|
[callback]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] rooted-device?")
|
2019-09-04 18:59:41 +00:00
|
|
|
(cond
|
|
|
|
;; we assume that iOS is safe by default
|
|
|
|
platform/ios?
|
|
|
|
(callback false)
|
|
|
|
|
|
|
|
;; we check root on android
|
|
|
|
platform/android?
|
|
|
|
(if (status)
|
2019-09-07 12:57:22 +00:00
|
|
|
(.isDeviceRooted ^js (status) callback)
|
2019-09-04 18:59:41 +00:00
|
|
|
;; if module isn't initialized we return true to avoid degrading security
|
|
|
|
(callback true))
|
|
|
|
|
|
|
|
;; in unknown scenarios we also consider the device rooted to avoid degrading security
|
2023-02-17 12:10:00 +00:00
|
|
|
:else (callback true)))
|
2019-09-12 09:41:25 +00:00
|
|
|
|
|
|
|
(defn generate-gfycat
|
|
|
|
"Generate a 3 words random name based on the user public-key, synchronously"
|
|
|
|
[public-key]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] generate-gfycat")
|
2023-01-19 16:59:33 +00:00
|
|
|
(when (validators/valid-public-key? public-key)
|
2023-01-26 16:12:26 +00:00
|
|
|
(.generateAlias ^js (status) public-key)))
|
2019-09-12 09:41:25 +00:00
|
|
|
|
|
|
|
(defn identicon
|
|
|
|
"Generate a icon based on a string, synchronously"
|
|
|
|
[seed]
|
2019-11-15 08:09:17 +00:00
|
|
|
(log/debug "[native-module] identicon")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.identicon ^js (status) seed))
|
2019-11-28 10:00:29 +00:00
|
|
|
|
2022-08-26 08:43:04 +00:00
|
|
|
(defn encode-transfer
|
|
|
|
[to-norm amount-hex]
|
|
|
|
(log/debug "[native-module] encode-transfer")
|
|
|
|
(.encodeTransfer ^js (status) to-norm amount-hex))
|
|
|
|
|
|
|
|
(defn decode-parameters
|
|
|
|
[bytes-string types]
|
|
|
|
(log/debug "[native-module] decode-parameters")
|
2022-12-20 14:45:37 +00:00
|
|
|
(let [json-str (.decodeParameters ^js (status)
|
|
|
|
(types/clj->json {:bytesString bytes-string :types types}))]
|
2022-08-26 08:43:04 +00:00
|
|
|
(types/json->clj json-str)))
|
|
|
|
|
|
|
|
(defn hex-to-number
|
|
|
|
[hex]
|
|
|
|
(log/debug "[native-module] hex-to-number")
|
|
|
|
(let [json-str (.hexToNumber ^js (status) hex)]
|
|
|
|
(types/json->clj json-str)))
|
|
|
|
|
|
|
|
(defn number-to-hex
|
|
|
|
[num]
|
|
|
|
(log/debug "[native-module] number-to-hex")
|
|
|
|
(.numberToHex ^js (status) (str num)))
|
|
|
|
|
2022-10-18 16:05:07 +00:00
|
|
|
(defn sha3
|
Unshadow more Clojure core vars (#16777)
This is a continuation of https://github.com/status-im/status-mobile/pull/16500 (Lint
& fix some shadowed core Clojure(Script) vars).
Notes: As a reminder, the goal is to eventually disallow shadowing core Clojure
vars entirely, but to get there and avoid rebase hell and regressions, we need
to do in smaller steps, especially because we can't safely automate the process
of unshadowing vars.
We are already down from ~500 shadowed core vars to 350 in total.
Why is this PR is using names such as "s", "v" or "sym"? Names such as s or v
are the so called idiomatic names, and are listed in the Clojure Style Guide
https://guide.clojure.style/#idiomatic-names. I used them whenever I felt
appropriate. For the var cljs.core/symbol I opted to use sym, even though the
symbol in question is not necessarily a Clojure symbol, I think the alias
conveys the meaning well enough
(https://www.clojure.org/guides/learn/syntax#_symbols_and_idents).
New vars linted:
- comparator
- identity
- str
- symbol
- val
Outstanding shadowed vars include type, name, hash, comp.
2023-07-26 11:26:12 +00:00
|
|
|
[s]
|
2022-10-18 16:05:07 +00:00
|
|
|
(log/debug "[native-module] sha3")
|
Unshadow more Clojure core vars (#16777)
This is a continuation of https://github.com/status-im/status-mobile/pull/16500 (Lint
& fix some shadowed core Clojure(Script) vars).
Notes: As a reminder, the goal is to eventually disallow shadowing core Clojure
vars entirely, but to get there and avoid rebase hell and regressions, we need
to do in smaller steps, especially because we can't safely automate the process
of unshadowing vars.
We are already down from ~500 shadowed core vars to 350 in total.
Why is this PR is using names such as "s", "v" or "sym"? Names such as s or v
are the so called idiomatic names, and are listed in the Clojure Style Guide
https://guide.clojure.style/#idiomatic-names. I used them whenever I felt
appropriate. For the var cljs.core/symbol I opted to use sym, even though the
symbol in question is not necessarily a Clojure symbol, I think the alias
conveys the meaning well enough
(https://www.clojure.org/guides/learn/syntax#_symbols_and_idents).
New vars linted:
- comparator
- identity
- str
- symbol
- val
Outstanding shadowed vars include type, name, hash, comp.
2023-07-26 11:26:12 +00:00
|
|
|
(.sha3 ^js (status) s))
|
2022-10-18 16:05:07 +00:00
|
|
|
|
|
|
|
(defn utf8-to-hex
|
Unshadow more Clojure core vars (#16777)
This is a continuation of https://github.com/status-im/status-mobile/pull/16500 (Lint
& fix some shadowed core Clojure(Script) vars).
Notes: As a reminder, the goal is to eventually disallow shadowing core Clojure
vars entirely, but to get there and avoid rebase hell and regressions, we need
to do in smaller steps, especially because we can't safely automate the process
of unshadowing vars.
We are already down from ~500 shadowed core vars to 350 in total.
Why is this PR is using names such as "s", "v" or "sym"? Names such as s or v
are the so called idiomatic names, and are listed in the Clojure Style Guide
https://guide.clojure.style/#idiomatic-names. I used them whenever I felt
appropriate. For the var cljs.core/symbol I opted to use sym, even though the
symbol in question is not necessarily a Clojure symbol, I think the alias
conveys the meaning well enough
(https://www.clojure.org/guides/learn/syntax#_symbols_and_idents).
New vars linted:
- comparator
- identity
- str
- symbol
- val
Outstanding shadowed vars include type, name, hash, comp.
2023-07-26 11:26:12 +00:00
|
|
|
[s]
|
2022-10-18 16:05:07 +00:00
|
|
|
(log/debug "[native-module] utf8-to-hex")
|
Unshadow more Clojure core vars (#16777)
This is a continuation of https://github.com/status-im/status-mobile/pull/16500 (Lint
& fix some shadowed core Clojure(Script) vars).
Notes: As a reminder, the goal is to eventually disallow shadowing core Clojure
vars entirely, but to get there and avoid rebase hell and regressions, we need
to do in smaller steps, especially because we can't safely automate the process
of unshadowing vars.
We are already down from ~500 shadowed core vars to 350 in total.
Why is this PR is using names such as "s", "v" or "sym"? Names such as s or v
are the so called idiomatic names, and are listed in the Clojure Style Guide
https://guide.clojure.style/#idiomatic-names. I used them whenever I felt
appropriate. For the var cljs.core/symbol I opted to use sym, even though the
symbol in question is not necessarily a Clojure symbol, I think the alias
conveys the meaning well enough
(https://www.clojure.org/guides/learn/syntax#_symbols_and_idents).
New vars linted:
- comparator
- identity
- str
- symbol
- val
Outstanding shadowed vars include type, name, hash, comp.
2023-07-26 11:26:12 +00:00
|
|
|
(.utf8ToHex ^js (status) s))
|
2022-10-18 16:05:07 +00:00
|
|
|
|
|
|
|
(defn hex-to-utf8
|
Unshadow more Clojure core vars (#16777)
This is a continuation of https://github.com/status-im/status-mobile/pull/16500 (Lint
& fix some shadowed core Clojure(Script) vars).
Notes: As a reminder, the goal is to eventually disallow shadowing core Clojure
vars entirely, but to get there and avoid rebase hell and regressions, we need
to do in smaller steps, especially because we can't safely automate the process
of unshadowing vars.
We are already down from ~500 shadowed core vars to 350 in total.
Why is this PR is using names such as "s", "v" or "sym"? Names such as s or v
are the so called idiomatic names, and are listed in the Clojure Style Guide
https://guide.clojure.style/#idiomatic-names. I used them whenever I felt
appropriate. For the var cljs.core/symbol I opted to use sym, even though the
symbol in question is not necessarily a Clojure symbol, I think the alias
conveys the meaning well enough
(https://www.clojure.org/guides/learn/syntax#_symbols_and_idents).
New vars linted:
- comparator
- identity
- str
- symbol
- val
Outstanding shadowed vars include type, name, hash, comp.
2023-07-26 11:26:12 +00:00
|
|
|
[s]
|
2022-10-18 16:05:07 +00:00
|
|
|
(log/debug "[native-module] hex-to-utf8")
|
Unshadow more Clojure core vars (#16777)
This is a continuation of https://github.com/status-im/status-mobile/pull/16500 (Lint
& fix some shadowed core Clojure(Script) vars).
Notes: As a reminder, the goal is to eventually disallow shadowing core Clojure
vars entirely, but to get there and avoid rebase hell and regressions, we need
to do in smaller steps, especially because we can't safely automate the process
of unshadowing vars.
We are already down from ~500 shadowed core vars to 350 in total.
Why is this PR is using names such as "s", "v" or "sym"? Names such as s or v
are the so called idiomatic names, and are listed in the Clojure Style Guide
https://guide.clojure.style/#idiomatic-names. I used them whenever I felt
appropriate. For the var cljs.core/symbol I opted to use sym, even though the
symbol in question is not necessarily a Clojure symbol, I think the alias
conveys the meaning well enough
(https://www.clojure.org/guides/learn/syntax#_symbols_and_idents).
New vars linted:
- comparator
- identity
- str
- symbol
- val
Outstanding shadowed vars include type, name, hash, comp.
2023-07-26 11:26:12 +00:00
|
|
|
(.hexToUtf8 ^js (status) s))
|
2022-10-18 16:05:07 +00:00
|
|
|
|
|
|
|
(defn check-address-checksum
|
|
|
|
[address]
|
|
|
|
(log/debug "[native-module] check-address-checksum")
|
|
|
|
(let [result (.checkAddressChecksum ^js (status) address)]
|
|
|
|
(types/json->clj result)))
|
|
|
|
|
|
|
|
(defn address?
|
|
|
|
[address]
|
|
|
|
(log/debug "[native-module] address?")
|
|
|
|
(let [result (.isAddress ^js (status) address)]
|
|
|
|
(types/json->clj result)))
|
|
|
|
|
|
|
|
(defn to-checksum-address
|
|
|
|
[address]
|
|
|
|
(log/debug "[native-module] to-checksum-address")
|
|
|
|
(.toChecksumAddress ^js (status) address))
|
|
|
|
|
2019-11-28 10:00:29 +00:00
|
|
|
(defn gfycat-identicon-async
|
|
|
|
"Generate an icon based on a string and 3 words random name asynchronously"
|
|
|
|
[seed callback]
|
2019-12-11 15:25:25 +00:00
|
|
|
(log/debug "[native-module] gfycat-identicon-async")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.generateAliasAndIdenticonAsync ^js (status) seed callback))
|
2019-12-31 10:50:45 +00:00
|
|
|
|
|
|
|
(defn validate-mnemonic
|
|
|
|
"Validate that a mnemonic conforms to BIP39 dictionary/checksum standards"
|
|
|
|
[mnemonic callback]
|
|
|
|
(log/debug "[native-module] validate-mnemonic")
|
2019-09-07 12:57:22 +00:00
|
|
|
(.validateMnemonic ^js (status) mnemonic callback))
|
2020-07-14 13:33:59 +00:00
|
|
|
|
|
|
|
(defn delete-multiaccount
|
|
|
|
"Delete multiaccount from database, deletes multiaccount's database and
|
|
|
|
key files."
|
|
|
|
[key-uid callback]
|
|
|
|
(log/debug "[native-module] delete-multiaccount")
|
|
|
|
(.deleteMultiaccount ^js (status) key-uid callback))
|
2020-07-28 11:06:58 +00:00
|
|
|
|
2021-08-13 07:53:40 +00:00
|
|
|
(defn delete-imported-key
|
|
|
|
"Delete imported key file."
|
|
|
|
[key-uid address hashed-password callback]
|
|
|
|
(log/debug "[native-module] delete-imported-key")
|
|
|
|
(.deleteImportedKey ^js (status) key-uid address hashed-password callback))
|
|
|
|
|
2022-12-20 14:45:37 +00:00
|
|
|
(defn reset-keyboard-input
|
|
|
|
[input selection]
|
2020-09-28 10:37:03 +00:00
|
|
|
(log/debug "[native-module] resetKeyboardInput")
|
|
|
|
(when platform/android?
|
|
|
|
(.resetKeyboardInputCursor ^js (status) input selection)))
|
2021-05-26 08:55:01 +00:00
|
|
|
|
|
|
|
;; passwords are hashed
|
|
|
|
(defn reset-password
|
|
|
|
[key-uid current-password# new-password# callback]
|
|
|
|
(log/debug "[native-module] change-database-password")
|
|
|
|
(init-keystore
|
|
|
|
key-uid
|
|
|
|
#(.reEncryptDbAndKeystore ^js (status) key-uid current-password# new-password# callback)))
|
2021-07-13 13:41:45 +00:00
|
|
|
|
|
|
|
(defn convert-to-keycard-account
|
|
|
|
[{:keys [key-uid] :as multiaccount-data} settings current-password# new-password callback]
|
|
|
|
(log/debug "[native-module] convert-to-keycard-account")
|
|
|
|
(.convertToKeycardAccount ^js (status)
|
|
|
|
key-uid
|
|
|
|
(types/clj->json multiaccount-data)
|
|
|
|
(types/clj->json settings)
|
2023-05-09 12:51:08 +00:00
|
|
|
""
|
2021-07-13 13:41:45 +00:00
|
|
|
current-password#
|
|
|
|
new-password
|
|
|
|
callback))
|
2023-03-22 13:51:38 +00:00
|
|
|
|
|
|
|
(defn backup-disabled-data-dir
|
|
|
|
[]
|
|
|
|
(.backupDisabledDataDir ^js (status)))
|
|
|
|
|
|
|
|
(defn keystore-dir
|
|
|
|
[]
|
|
|
|
(.keystoreDir ^js (status)))
|
|
|
|
|
2023-03-28 14:53:16 +00:00
|
|
|
(defn log-file-directory
|
2023-03-22 13:51:38 +00:00
|
|
|
[]
|
2023-03-28 14:53:16 +00:00
|
|
|
(.logFileDirectory ^js (status)))
|
2023-06-21 23:45:55 +00:00
|
|
|
|
|
|
|
(defn init-status-go-logging
|
|
|
|
[{:keys [enable? mobile-system? log-level callback]}]
|
|
|
|
(.initLogging ^js (status) enable? mobile-system? log-level callback))
|