From 73db641b163c16639bb179460bcd116e3a3e5b19 Mon Sep 17 00:00:00 2001 From: frank Date: Thu, 17 Oct 2024 17:00:47 +0800 Subject: [PATCH] chore_: use status.go v2 endpoint https://github.com/status-im/status-go/compare/39511298...e255fb8b --- .../status/ethereum/module/AccountManager.kt | 20 ++++- .../status/ethereum/module/DatabaseManager.kt | 57 ++++++++++--- .../ethereum/module/EncryptionUtils.java | 46 +++++++++-- .../status/ethereum/module/NetworkManager.kt | 27 +++++-- .../im/status/ethereum/module/StatusModule.kt | 24 ++++-- .../java/im/status/ethereum/module/Utils.kt | 11 ++- .../ios/RCTStatus/AccountManager.m | 38 +++++++-- .../ios/RCTStatus/DatabaseManager.m | 39 ++++++++- .../ios/RCTStatus/EncryptionUtils.m | 79 +++++++++++++++++-- .../ios/RCTStatus/NetworkManager.m | 53 ++++++++++++- .../ios/RCTStatus/RCTStatus.m | 45 +++++++++-- .../react-native-status/ios/RCTStatus/Utils.m | 39 +++++++-- status-go-version.json | 6 +- 13 files changed, 420 insertions(+), 64 deletions(-) diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/AccountManager.kt b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/AccountManager.kt index 4ad0aee3b67..6dc78e637ba 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/AccountManager.kt +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/AccountManager.kt @@ -224,16 +224,25 @@ class AccountManager(private val reactContext: ReactApplicationContext) : ReactC val absRootDirPath = utils.getNoBackupDirectory() val newKeystoreDir = utils.pathCombine(absRootDirPath, "keystore") + val jsonParams = JSONObject() + jsonParams.put("keyStoreDir", newKeystoreDir) + jsonParams.put("address", address) + jsonParams.put("password", password) + utils.executeRunnableStatusGoMethod( - { Statusgo.verifyAccountPassword(newKeystoreDir, address, password) }, + { Statusgo.verifyAccountPasswordV2(jsonParams.toString()) }, callback ) } @ReactMethod fun verifyDatabasePassword(keyUID: String, password: String, callback: Callback) { + val jsonParams = JSONObject() + jsonParams.put("keyUID", keyUID) + jsonParams.put("password", password) + utils.executeRunnableStatusGoMethod( - { Statusgo.verifyDatabasePassword(keyUID, password) }, + { Statusgo.verifyDatabasePasswordV2(jsonParams.toString()) }, callback ) } @@ -311,7 +320,12 @@ class AccountManager(private val reactContext: ReactApplicationContext) : ReactC @ReactMethod fun deleteMultiaccount(keyUID: String, callback: Callback) { val keyStoreDir = utils.getKeyStorePath(keyUID) - utils.executeRunnableStatusGoMethod({ Statusgo.deleteMultiaccount(keyUID, keyStoreDir) }, callback) + val params = JSONObject().apply { + put("keyUID", keyUID) + put("keyStoreDir", keyStoreDir) + } + val jsonString = params.toString() + utils.executeRunnableStatusGoMethod({ Statusgo.deleteMultiaccountV2(jsonString) }, callback) } @ReactMethod diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/DatabaseManager.kt b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/DatabaseManager.kt index a0a21d2b3b1..737edea60a5 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/DatabaseManager.kt +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/DatabaseManager.kt @@ -9,6 +9,8 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReactMethod import statusgo.Statusgo import java.io.File +import org.json.JSONObject +import org.json.JSONException class DatabaseManager(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { @@ -23,16 +25,34 @@ class DatabaseManager(private val reactContext: ReactApplicationContext) : React @ReactMethod fun exportUnencryptedDatabase(accountData: String, password: String, callback: Callback) { - Log.d(TAG, "login") + Log.d(TAG, "exportUnencryptedDatabase") val newFile = getExportDBFile() utils.migrateKeyStoreDir(accountData, password) - val result = Statusgo.exportUnencryptedDatabase(accountData, password, newFile.absolutePath) - if (result.startsWith("{\"error\":\"\"")) { - Log.d(TAG, "Login result: $result") - } else { - Log.e(TAG, "Login failed: $result") + + try { + val accountJson = JSONObject(accountData) + + val params = JSONObject().apply { + put("account", accountJson) + put("password", password) + put("databasePath", newFile.absolutePath) + } + + val jsonParams = params.toString() + + val result = Statusgo.exportUnencryptedDatabaseV2(jsonParams) + if (result.startsWith("{\"error\":\"\"")) { + Log.d(TAG, "Export result: $result") + } else { + Log.e(TAG, "Export failed: $result") + } + + callback.invoke(newFile.absolutePath) + + } catch (e: JSONException) { + Log.e(TAG, "Error parsing account data: ${e.message}") } } @@ -43,11 +63,26 @@ class DatabaseManager(private val reactContext: ReactApplicationContext) : React val newFile = getExportDBFile() utils.migrateKeyStoreDir(accountData, password) - val result = Statusgo.importUnencryptedDatabase(accountData, password, newFile.absolutePath) - if (result.startsWith("{\"error\":\"\"")) { - Log.d(TAG, "import result: $result") - } else { - Log.e(TAG, "import failed: $result") + + try { + val accountJson = JSONObject(accountData) + + val params = JSONObject().apply { + put("account", accountJson) + put("password", password) + put("databasePath", newFile.absolutePath) + } + + val jsonParams = params.toString() + + val result = Statusgo.importUnencryptedDatabaseV2(jsonParams) + if (result.startsWith("{\"error\":\"\"")) { + Log.d(TAG, "Import result: $result") + } else { + Log.e(TAG, "Import failed: $result") + } + } catch (e: JSONException) { + Log.e(TAG, "Error parsing account data: ${e.message}") } } diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/EncryptionUtils.java b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/EncryptionUtils.java index 66990f1503d..024f26b1c6d 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/EncryptionUtils.java +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/EncryptionUtils.java @@ -7,6 +7,7 @@ import android.util.Log; import statusgo.Statusgo; import org.json.JSONException; +import org.json.JSONObject; import java.util.function.Function; import android.app.Activity; import android.view.WindowManager; @@ -44,27 +45,58 @@ private void initKeystore(final String keyUID, final Callback callback) throws J @ReactMethod public void reEncryptDbAndKeystore(final String keyUID, final String password, final String newPassword, final Callback callback) throws JSONException { - this.utils.executeRunnableStatusGoMethod(() -> Statusgo.changeDatabasePassword(keyUID, password, newPassword), callback); + JSONObject params = new JSONObject(); + params.put("keyUID", keyUID); + params.put("oldPassword", password); + params.put("newPassword", newPassword); + String jsonParams = params.toString(); + this.utils.executeRunnableStatusGoMethod(() -> Statusgo.changeDatabasePasswordV2(jsonParams), callback); } @ReactMethod public void convertToKeycardAccount(final String keyUID, final String accountData, final String options, final String keycardUID, final String password, final String newPassword, final Callback callback) throws JSONException { final String keyStoreDir = this.utils.getKeyStorePath(keyUID); + JSONObject params = new JSONObject(); + params.put("keyUID", keyUID); + params.put("account", new JSONObject(accountData)); + params.put("settings", new JSONObject(options)); + params.put("keycardUID", keycardUID); + params.put("oldPassword", password); + params.put("newPassword", newPassword); + final String jsonParams = params.toString(); this.utils.executeRunnableStatusGoMethod(() -> { Statusgo.initKeystore(keyStoreDir); - return Statusgo.convertToKeycardAccount(accountData, options, keycardUID, password, newPassword); + return Statusgo.convertToKeycardAccountV2(jsonParams); }, callback); } @ReactMethod(isBlockingSynchronousMethod = true) public String encodeTransfer(final String to, final String value) { - return Statusgo.encodeTransfer(to, value); + try { + JSONObject params = new JSONObject(); + params.put("to", to); + params.put("value", value); + String jsonParams = params.toString(); + return Statusgo.encodeTransferV2(jsonParams); + } catch (JSONException e) { + Log.e(TAG, "Error creating JSON for encodeTransfer: " + e.getMessage()); + return null; + } } @ReactMethod(isBlockingSynchronousMethod = true) public String encodeFunctionCall(final String method, final String paramsJSON) { - return Statusgo.encodeFunctionCall(method, paramsJSON); + try { + JSONObject params = new JSONObject(); + params.put("method", method); + params.put("paramsJSON", new JSONObject(paramsJSON)); + String jsonString = params.toString(); + return Statusgo.encodeFunctionCallV2(jsonString); + } catch (JSONException e) { + Log.e(TAG, "Error creating JSON for encodeFunctionCall: " + e.getMessage()); + return null; + } } @ReactMethod(isBlockingSynchronousMethod = true) @@ -140,7 +172,11 @@ public void hashMessage(final String message, final Callback callback) throws JS @ReactMethod public void multiformatDeserializePublicKey(final String multiCodecKey, final String base58btc, final Callback callback) throws JSONException { - this.utils.executeRunnableStatusGoMethod(() -> Statusgo.multiformatDeserializePublicKey(multiCodecKey,base58btc), callback); + JSONObject params = new JSONObject(); + params.put("key", multiCodecKey); + params.put("outBase", base58btc); + String jsonParams = params.toString(); + this.utils.executeRunnableStatusGoMethod(() -> Statusgo.multiformatDeserializePublicKeyV2(jsonParams), callback); } @ReactMethod diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/NetworkManager.kt b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/NetworkManager.kt index c566fe78f5c..484e2ac0bc5 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/NetworkManager.kt +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/NetworkManager.kt @@ -35,9 +35,14 @@ class NetworkManager(private val reactContext: ReactApplicationContext) : ReactC @ReactMethod fun inputConnectionStringForBootstrapping(connectionString: String, configJSON: String, callback: Callback) { - val jsonConfig = JSONObject(configJSON) + val receiverClientConfig = JSONObject(configJSON) + val params = JSONObject().apply { + put("connectionString", connectionString) + put("receiverClientConfig", receiverClientConfig) + } + val jsonString = params.toString() utils.executeRunnableStatusGoMethod( - { Statusgo.inputConnectionStringForBootstrapping(connectionString, jsonConfig.toString()) }, + { Statusgo.inputConnectionStringForBootstrappingV2(jsonString) }, callback ) } @@ -52,7 +57,12 @@ class NetworkManager(private val reactContext: ReactApplicationContext) : ReactC @ReactMethod fun sendTransaction(txArgsJSON: String, password: String, callback: Callback) { - utils.executeRunnableStatusGoMethod({ Statusgo.sendTransaction(txArgsJSON, password) }, callback) + val jsonParams = JSONObject().apply { + put("txArgs", JSONObject(txArgsJSON)) + put("password", password) + } + val jsonString = jsonParams.toString() + utils.executeRunnableStatusGoMethod({ Statusgo.sendTransactionV2(jsonString) }, callback) } @ReactMethod @@ -85,13 +95,18 @@ class NetworkManager(private val reactContext: ReactApplicationContext) : ReactC @ReactMethod fun inputConnectionStringForImportingKeypairsKeystores(connectionString: String, configJSON: String, callback: Callback) { - val jsonConfig = JSONObject(configJSON) - val receiverConfig = jsonConfig.getJSONObject("receiverConfig") + val keystoreFilesReceiverClientConfig = JSONObject(configJSON) + val receiverConfig = keystoreFilesReceiverClientConfig.getJSONObject("receiverConfig") val keyStorePath = utils.pathCombine(utils.getNoBackupDirectory(), "/keystore") receiverConfig.put("keystorePath", keyStorePath) + val params = JSONObject().apply { + put("connectionString", connectionString) + put("keystoreFilesReceiverClientConfig", keystoreFilesReceiverClientConfig) + } + utils.executeRunnableStatusGoMethod( - { Statusgo.inputConnectionStringForImportingKeypairsKeystores(connectionString, jsonConfig.toString()) }, + { Statusgo.inputConnectionStringForImportingKeypairsKeystoresV2(params.toString()) }, callback ) } diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.kt b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.kt index 7cbf56f30f3..ddd8e77bdf6 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.kt +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.kt @@ -9,6 +9,7 @@ import statusgo.SignalHandler import statusgo.Statusgo import org.json.JSONException import android.view.WindowManager +import org.json.JSONObject class StatusModule(private val reactContext: ReactApplicationContext, private val rootedDevice: Boolean) : ReactContextBaseJavaModule(reactContext), LifecycleEventListener, SignalHandler { @@ -56,13 +57,20 @@ class StatusModule(private val reactContext: ReactApplicationContext, private va @ReactMethod fun connectionChange(type: String, isExpensive: Boolean) { Log.d(TAG, "ConnectionChange: $type, is expensive $isExpensive") - Statusgo.connectionChange(type, if (isExpensive) 1 else 0) + val params = JSONObject().apply { + put("type", type) + put("expensive", isExpensive) + } + Statusgo.connectionChangeV2(params.toString()) } @ReactMethod - fun appStateChange(type: String) { - Log.d(TAG, "AppStateChange: $type") - Statusgo.appStateChange(type) + fun appStateChange(state: String) { + Log.d(TAG, "AppStateChange: $state") + val params = JSONObject().apply { + put("state", state) + } + Statusgo.appStateChangeV2(params.toString()) } @ReactMethod @@ -89,7 +97,13 @@ class StatusModule(private val reactContext: ReactApplicationContext, private va @ReactMethod fun deleteImportedKey(keyUID: String, address: String, password: String, callback: Callback) { val keyStoreDir = utils.getKeyStorePath(keyUID) - utils.executeRunnableStatusGoMethod({ Statusgo.deleteImportedKey(address, password, keyStoreDir) }, callback) + val params = JSONObject().apply { + put("address", address) + put("password", password) + put("keyStoreDir", keyStoreDir) + } + val jsonString = params.toString() + utils.executeRunnableStatusGoMethod({ Statusgo.deleteImportedKeyV2(jsonString) }, callback) } @ReactMethod(isBlockingSynchronousMethod = true) diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/Utils.kt b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/Utils.kt index 5333266fb4e..94689f3cd47 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/Utils.kt +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/Utils.kt @@ -69,7 +69,12 @@ class Utils(private val reactContext: ReactApplicationContext) : ReactContextBas val keydirFile = File(keydir) if (!keydirFile.exists() || keydirFile.list().isEmpty()) { Log.d(TAG, "migrateKeyStoreDir") - Statusgo.migrateKeyStoreDir(accountData, password, commonKeydir, keydir) + val jsonParams = JSONObject() + jsonParams.put("account", JSONObject(accountData)) // Remove 'new' keyword + jsonParams.put("password", password) + jsonParams.put("oldDir", commonKeydir) + jsonParams.put("newDir", keydir) + Statusgo.migrateKeyStoreDirV2(jsonParams.toString()) Statusgo.initKeystore(keydir) } } catch (e: JSONException) { @@ -115,7 +120,9 @@ class Utils(private val reactContext: ReactApplicationContext) : ReactContextBas @ReactMethod fun validateMnemonic(seed: String, callback: Callback) { - executeRunnableStatusGoMethod({ Statusgo.validateMnemonic(seed) }, callback) + val jsonParams = JSONObject() + jsonParams.put("mnemonic", seed) + executeRunnableStatusGoMethod({ Statusgo.validateMnemonicV2(jsonParams.toString()) }, callback) } fun is24Hour(): Boolean { diff --git a/modules/react-native-status/ios/RCTStatus/AccountManager.m b/modules/react-native-status/ios/RCTStatus/AccountManager.m index da7ab6d5f47..fc0ab3cd0be 100644 --- a/modules/react-native-status/ios/RCTStatus/AccountManager.m +++ b/modules/react-native-status/ios/RCTStatus/AccountManager.m @@ -102,7 +102,18 @@ -(NSString *) prepareDirAndUpdateConfig:(NSString *)config NSLog(@"DeleteMultiaccount() method called"); #endif NSURL *multiaccountKeystoreDir = [Utils getKeyStoreDirForKeyUID:keyUID]; - NSString *result = StatusgoDeleteMultiaccount(keyUID, multiaccountKeystoreDir.path); + NSDictionary *params = @{ + @"keyUID": keyUID, + @"keyStoreDir": multiaccountKeystoreDir.path + }; + NSError *error; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error]; + if (error) { + NSLog(@"Error creating JSON: %@", error); + return; + } + NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + NSString *result = StatusgoDeleteMultiaccountV2(jsonString); callback(@[result]); } @@ -173,15 +184,23 @@ -(NSString *) prepareDirAndUpdateConfig:(NSString *)config password:(NSString *)password callback:(RCTResponseSenderBlock)callback) { #if DEBUG - NSLog(@"VerifyAccountPassword() method called"); + NSLog(@"VerifyAccountPasswordV2() method called"); #endif NSFileManager *fileManager = [NSFileManager defaultManager]; NSURL *rootUrl =[[fileManager URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject]; NSURL *absKeystoreUrl = [rootUrl URLByAppendingPathComponent:@"keystore"]; - - NSString *result = StatusgoVerifyAccountPassword(absKeystoreUrl.path, address, password); + + NSDictionary *params = @{ + @"keyStoreDir": absKeystoreUrl.path, + @"address": address, + @"password": password + }; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:nil]; + NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + + NSString *result = StatusgoVerifyAccountPasswordV2(jsonString); callback(@[result]); } @@ -189,9 +208,16 @@ -(NSString *) prepareDirAndUpdateConfig:(NSString *)config password:(NSString *)password callback:(RCTResponseSenderBlock)callback) { #if DEBUG - NSLog(@"VerifyDatabasePassword() method called"); + NSLog(@"VerifyDatabasePasswordV2() method called"); #endif - NSString *result = StatusgoVerifyDatabasePassword(keyUID, password); + NSDictionary *params = @{ + @"keyUID": keyUID, + @"password": password + }; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:nil]; + NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + + NSString *result = StatusgoVerifyDatabasePasswordV2(jsonString); callback(@[result]); } diff --git a/modules/react-native-status/ios/RCTStatus/DatabaseManager.m b/modules/react-native-status/ios/RCTStatus/DatabaseManager.m index 69581bee070..c815212c4c3 100644 --- a/modules/react-native-status/ios/RCTStatus/DatabaseManager.m +++ b/modules/react-native-status/ios/RCTStatus/DatabaseManager.m @@ -16,8 +16,26 @@ @implementation DatabaseManager #endif NSString *filePath = [Utils getExportDbFilePath]; - StatusgoExportUnencryptedDatabase(accountData, password, filePath); - + + NSDictionary *params = @{ + @"account": [NSJSONSerialization JSONObjectWithData:[accountData dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil], + @"password": password, + @"databasePath": filePath + }; + + NSError *error; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error]; + + if (error) { + NSLog(@"Error creating JSON: %@", [error localizedDescription]); + callback(@[filePath]); + return; + } + + NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + + StatusgoExportUnencryptedDatabaseV2(jsonString); + callback(@[filePath]); } @@ -26,7 +44,22 @@ @implementation DatabaseManager #if DEBUG NSLog(@"importUnencryptedDatabase() method called"); #endif - ""; + NSDictionary *params = @{ + @"account": [NSJSONSerialization JSONObjectWithData:[accountData dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil], + @"password": password + }; + + NSError *error; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error]; + + if (error) { + NSLog(@"Error creating JSON: %@", [error localizedDescription]); + return; + } + + NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + + StatusgoImportUnencryptedDatabaseV2(jsonString); } diff --git a/modules/react-native-status/ios/RCTStatus/EncryptionUtils.m b/modules/react-native-status/ios/RCTStatus/EncryptionUtils.m index d580dea59f4..d100c908667 100644 --- a/modules/react-native-status/ios/RCTStatus/EncryptionUtils.m +++ b/modules/react-native-status/ios/RCTStatus/EncryptionUtils.m @@ -39,8 +39,22 @@ @implementation EncryptionUtils #if DEBUG NSLog(@"reEncryptDbAndKeystore() method called"); #endif - // changes password and re-encrypts keystore - NSString *result = StatusgoChangeDatabasePassword(keyUID, currentPassword, newPassword); + // Construct params into JSON string + NSDictionary *params = @{ + @"keyUID": keyUID, + @"oldPassword": currentPassword, + @"newPassword": newPassword + }; + NSError *error; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error]; + if (error) { + NSLog(@"Error creating JSON: %@", error); + return; + } + NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + + // Call ChangeDatabasePasswordV2 with JSON string param + NSString *result = StatusgoChangeDatabasePasswordV2(jsonString); callback(@[result]); } @@ -56,18 +70,60 @@ @implementation EncryptionUtils #endif NSURL *multiaccountKeystoreDir = [Utils getKeyStoreDirForKeyUID:keyUID]; StatusgoInitKeystore(multiaccountKeystoreDir.path); - NSString *result = StatusgoConvertToKeycardAccount(accountData, settings, keycardUID, currentPassword, newPassword); + + NSDictionary *params = @{ + @"keyUID": keyUID, + @"account": [NSJSONSerialization JSONObjectWithData:[accountData dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil], + @"settings": [NSJSONSerialization JSONObjectWithData:[settings dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil], + @"keycardUID": keycardUID, + @"oldPassword": currentPassword, + @"newPassword": newPassword + }; + + NSError *error; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error]; + + if (error) { + NSLog(@"Error creating JSON: %@", [error localizedDescription]); + return; + } + + NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + + NSString *result = StatusgoConvertToKeycardAccountV2(jsonString); callback(@[result]); } RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(encodeTransfer:(NSString *)to value:(NSString *)value) { - return StatusgoEncodeTransfer(to,value); + NSDictionary *params = @{ + @"to": to, + @"value": value + }; + NSError *error; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error]; + if (error) { + NSLog(@"Error creating JSON: %@", [error localizedDescription]); + return nil; + } + NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + return StatusgoEncodeTransferV2(jsonString); } RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(encodeFunctionCall:(NSString *)method paramsJSON:(NSString *)paramsJSON) { - return StatusgoEncodeFunctionCall(method,paramsJSON); + NSDictionary *params = @{ + @"method": method, + @"paramsJSON": paramsJSON + }; + NSError *error; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error]; + if (error) { + NSLog(@"Error creating JSON: %@", [error localizedDescription]); + return nil; + } + NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + return StatusgoEncodeFunctionCallV2(jsonString); } RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(decodeParameters:(NSString *)decodeParamJSON) { @@ -136,7 +192,18 @@ @implementation EncryptionUtils RCT_EXPORT_METHOD(multiformatDeserializePublicKey:(NSString *)multiCodecKey base58btc:(NSString *)base58btc callback:(RCTResponseSenderBlock)callback) { - NSString *result = StatusgoMultiformatDeserializePublicKey(multiCodecKey,base58btc); + NSDictionary *params = @{ + @"key": multiCodecKey, + @"outBase": base58btc + }; + NSError *error; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error]; + if (error) { + NSLog(@"Error creating JSON: %@", error); + return; + } + NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + NSString *result = StatusgoMultiformatDeserializePublicKeyV2(jsonString); callback(@[result]); } diff --git a/modules/react-native-status/ios/RCTStatus/NetworkManager.m b/modules/react-native-status/ios/RCTStatus/NetworkManager.m index 142ff15ba69..a9b653277ab 100644 --- a/modules/react-native-status/ios/RCTStatus/NetworkManager.m +++ b/modules/react-native-status/ios/RCTStatus/NetworkManager.m @@ -35,7 +35,26 @@ @implementation NetworkManager configJSON:(NSString *)configJSON callback:(RCTResponseSenderBlock)callback) { - NSString *result = StatusgoInputConnectionStringForBootstrapping(cs, configJSON); + NSData *configData = [configJSON dataUsingEncoding:NSUTF8StringEncoding]; + NSError *jsonError; + NSDictionary *configDict = [NSJSONSerialization JSONObjectWithData:configData options:0 error:&jsonError]; + if (jsonError) { + NSLog(@"Error parsing JSON: %@", jsonError); + return; + } + + NSDictionary *params = @{ + @"connectionString": cs, + @"receiverClientConfig": configDict + }; + NSError *error; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error]; + if (error) { + NSLog(@"Error creating JSON: %@", error); + return; + } + NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + NSString *result = StatusgoInputConnectionStringForBootstrappingV2(jsonString); callback(@[result]); } @@ -55,9 +74,28 @@ @implementation NetworkManager password:(NSString *)password callback:(RCTResponseSenderBlock)callback) { #if DEBUG - NSLog(@"SendTransaction() method called"); + NSLog(@"SendTransactionV2() method called"); #endif - NSString *result = StatusgoSendTransaction(txArgsJSON, password); + NSData *txArgsData = [txArgsJSON dataUsingEncoding:NSUTF8StringEncoding]; + NSError *jsonError; + NSDictionary *txArgsDict = [NSJSONSerialization JSONObjectWithData:txArgsData options:0 error:&jsonError]; + if (jsonError) { + NSLog(@"Error parsing JSON: %@", jsonError); + return; + } + + NSDictionary *params = @{ + @"txArgs": txArgsDict, + @"password": password + }; + NSError *error; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error]; + if (error) { + NSLog(@"Error creating JSON: %@", error); + return; + } + NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + NSString *result = StatusgoSendTransactionV2(jsonString); callback(@[result]); } @@ -125,7 +163,14 @@ @implementation NetworkManager [receiverConfig setValue:keystoreDir forKey:@"keystorePath"]; NSString *modifiedConfigJSON = [Utils jsonStringWithPrettyPrint:NO fromDictionary:configDict]; - NSString *result = StatusgoInputConnectionStringForImportingKeypairsKeystores(cs, modifiedConfigJSON); + + NSDictionary *params = @{ + @"connectionString": cs, + @"keystoreFilesReceiverClientConfig": modifiedConfigJSON + }; + NSString *paramsJSON = [Utils jsonStringWithPrettyPrint:NO fromDictionary:params]; + + NSString *result = StatusgoInputConnectionStringForImportingKeypairsKeystoresV2(paramsJSON); callback(@[result]); } diff --git a/modules/react-native-status/ios/RCTStatus/RCTStatus.m b/modules/react-native-status/ios/RCTStatus/RCTStatus.m index 71494405340..83d08d2ab25 100644 --- a/modules/react-native-status/ios/RCTStatus/RCTStatus.m +++ b/modules/react-native-status/ios/RCTStatus/RCTStatus.m @@ -73,10 +73,12 @@ - (void)handleSignal:(NSString *)signal password:(NSString *)password callback:(RCTResponseSenderBlock)callback) { #if DEBUG - NSLog(@"DeleteImportedKey() method called"); + NSLog(@"DeleteImportedKeyV2() method called"); #endif NSURL *multiaccountKeystoreDir = [Utils getKeyStoreDirForKeyUID:keyUID]; - NSString *result = StatusgoDeleteImportedKey(address, password, multiaccountKeystoreDir.path); + NSString *jsonParams = [NSString stringWithFormat:@"{\"address\":\"%@\",\"password\":\"%@\",\"keyStoreDir\":\"%@\"}", + address, password, multiaccountKeystoreDir.path]; + NSString *result = StatusgoDeleteImportedKeyV2(jsonParams); callback(@[result]); } @@ -166,14 +168,47 @@ - (void)handleSignal:(NSString *)signal #if DEBUG NSLog(@"ConnectionChange() method called"); #endif - StatusgoConnectionChange(type, isExpensive ? 1 : 0); + NSDictionary *params = @{ + @"type": type, + @"expensive": @(isExpensive) + }; + NSError *error; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params + options:0 + error:&error]; + if (error) { + NSLog(@"Error creating JSON: %@", error); + return; + } + + if (jsonData) { + NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + StatusgoConnectionChangeV2(jsonString); + } else { + NSLog(@"Failed to create JSON data"); + } } -RCT_EXPORT_METHOD(appStateChange:(NSString *)type) { +RCT_EXPORT_METHOD(appStateChange:(NSString *)state) { #if DEBUG NSLog(@"AppStateChange() method called"); #endif - StatusgoAppStateChange(type); + NSDictionary *params = @{@"state": state}; + NSError *error; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params + options:0 + error:&error]; + if (error) { + NSLog(@"Error creating JSON: %@", error); + return; + } + + if (jsonData) { + NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + StatusgoAppStateChangeV2(jsonString); + } else { + NSLog(@"Failed to create JSON data"); + } } RCT_EXPORT_METHOD(addCentralizedMetric:(NSString *)request diff --git a/modules/react-native-status/ios/RCTStatus/Utils.m b/modules/react-native-status/ios/RCTStatus/Utils.m index 6f0f35e1fa4..10ef504abfd 100644 --- a/modules/react-native-status/ios/RCTStatus/Utils.m +++ b/modules/react-native-status/ios/RCTStatus/Utils.m @@ -74,13 +74,34 @@ + (void) migrateKeystore:(NSString *)accountData URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject]; - NSURL *keyUID = [self getKeyStoreDirForKeyUID:accountData]; + NSData *jsonData = [accountData dataUsingEncoding:NSUTF8StringEncoding]; + NSError *error; + NSDictionary *accountJson = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error]; + if (error) { + NSLog(@"Error parsing accountData: %@", error); + return; + } + + NSString *keyUID = [self getKeyUID:accountData]; NSURL *oldKeystoreDir = [rootUrl URLByAppendingPathComponent:@"keystore"]; - NSURL *multiaccountKeystoreDir = [self getKeyStoreDirForKeyUID:keyUID.path]; + NSURL *multiaccountKeystoreDir = [self getKeyStoreDirForKeyUID:keyUID]; NSArray *keys = [fileManager contentsOfDirectoryAtPath:multiaccountKeystoreDir.path error:nil]; if (keys.count == 0) { - NSString *migrationResult = StatusgoMigrateKeyStoreDir(accountData, password, oldKeystoreDir.path, multiaccountKeystoreDir.path); + NSDictionary *params = @{ + @"account": accountJson, + @"password": password, + @"oldDir": oldKeystoreDir.path, + @"newDir": multiaccountKeystoreDir.path + }; + NSData *paramsJsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error]; + if (error) { + NSLog(@"Error creating params JSON: %@", error); + return; + } + NSString *jsonString = [[NSString alloc] initWithData:paramsJsonData encoding:NSUTF8StringEncoding]; + + NSString *migrationResult = StatusgoMigrateKeyStoreDirV2(jsonString); NSLog(@"keystore migration result %@", migrationResult); NSString *initKeystoreResult = StatusgoInitKeystore(multiaccountKeystoreDir.path); @@ -110,9 +131,17 @@ + (void) migrateKeystore:(NSString *)accountData RCT_EXPORT_METHOD(validateMnemonic:(NSString *)seed callback:(RCTResponseSenderBlock)callback) { #if DEBUG - NSLog(@"validateMnemonic() method called"); + NSLog(@"validateMnemonicV2() method called"); #endif - NSString *result = StatusgoValidateMnemonic(seed); + NSDictionary *params = @{@"mnemonic": seed}; + NSError *error; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error]; + if (error) { + NSLog(@"Error creating JSON: %@", error); + return; + } + NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + NSString *result = StatusgoValidateMnemonicV2(jsonString); callback(@[result]); } diff --git a/status-go-version.json b/status-go-version.json index 59995be78f3..7492b0af388 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "owner": "status-im", "repo": "status-go", - "version": "v3.6.0", - "commit-sha1": "00a8a72ac2cc0933503cdf88cc5eafa45ab5e182", - "src-sha256": "0ka6c7bg8mnwqpyn8rv15cba537vp2fm8yxlyl5s17lwai5hqnk5" + "version": "chore/create_v2_endpoint", + "commit-sha1": "e255fb8b1d588f1030fc3db4f123081c58814984", + "src-sha256": "05h1hg3944wg1wnz0wkslvxs27sz9h7aqb882m4ilbkagklfs0nz" }