mirror of
https://github.com/status-im/status-react.git
synced 2025-01-10 02:56:07 +00:00
6a7f04a5a8
* chore: update private-key validation * chore: add native module bindings * chore: add translation labels * chore: add size-12 for password icon * fix: ensure we use feature-flag namespace when using feature-flags * fix: blur styles for icon-avatar in missing key-pairs * fix: blur styles for accounts in missing key-pairs * fix: blur styles for bottom-sheet * fix: adjust blur background color for bottom-sheets * chore: add support for private-keys for missing key-pair component * chore: add definitions for events and effects * feature: implement private-key import for missing key-pair * tidy: remove debugging * tidy: distinguish to import for missing-keypair * tidy: remove unneeded function * tidy: refactor layout to use floating-button-page * tidy: remove unused effect bindings * tidy: refactor event bindings for importing-missing-keypair-by-private-key * tweak: add error logging * tidy: refactor helper to re-frame utils * tweak: group partially operable and fully operable keypairs together * chore: add documentation for call-continuation * tweak: refactor documentation * tweak: throw exception when not given a compatible continuation * fix: update least-operability when making key-pair fully operable
245 lines
8.8 KiB
Objective-C
245 lines
8.8 KiB
Objective-C
#import "AccountManager.h"
|
|
#import "React/RCTBridge.h"
|
|
#import "React/RCTEventDispatcher.h"
|
|
#import "Statusgo.h"
|
|
#import "Utils.h"
|
|
|
|
@implementation AccountManager
|
|
|
|
RCT_EXPORT_MODULE();
|
|
|
|
RCT_EXPORT_METHOD(createAccountAndLogin:(NSString *)request) {
|
|
#if DEBUG
|
|
NSLog(@"createAccountAndLogin() method called");
|
|
#endif
|
|
StatusgoCreateAccountAndLogin(request);
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(restoreAccountAndLogin:(NSString *)request) {
|
|
#if DEBUG
|
|
NSLog(@"restoreAccountAndLogin() method called");
|
|
#endif
|
|
StatusgoRestoreAccountAndLogin(request);
|
|
}
|
|
|
|
-(NSString *) prepareDirAndUpdateConfig:(NSString *)config
|
|
withKeyUID:(NSString *)keyUID {
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
NSError *error = nil;
|
|
NSURL *rootUrl =[[fileManager
|
|
URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]
|
|
lastObject];
|
|
NSURL *absTestnetFolderName = [rootUrl URLByAppendingPathComponent:@"ethereum/testnet"];
|
|
|
|
if (![fileManager fileExistsAtPath:absTestnetFolderName.path])
|
|
[fileManager createDirectoryAtPath:absTestnetFolderName.path withIntermediateDirectories:YES attributes:nil error:&error];
|
|
|
|
NSURL *flagFolderUrl = [rootUrl URLByAppendingPathComponent:@"ropsten_flag"];
|
|
|
|
if(![fileManager fileExistsAtPath:flagFolderUrl.path]){
|
|
NSLog(@"remove lightchaindata");
|
|
NSURL *absLightChainDataUrl = [absTestnetFolderName URLByAppendingPathComponent:@"StatusIM/lightchaindata"];
|
|
if([fileManager fileExistsAtPath:absLightChainDataUrl.path]) {
|
|
[fileManager removeItemAtPath:absLightChainDataUrl.path
|
|
error:nil];
|
|
}
|
|
[fileManager createDirectoryAtPath:flagFolderUrl.path
|
|
withIntermediateDirectories:NO
|
|
attributes:nil
|
|
error:&error];
|
|
}
|
|
|
|
NSLog(@"after remove lightchaindata");
|
|
|
|
NSString *keystore = @"keystore";
|
|
NSURL *absTestnetKeystoreUrl = [absTestnetFolderName URLByAppendingPathComponent:keystore];
|
|
NSURL *absKeystoreUrl = [rootUrl URLByAppendingPathComponent:keystore];
|
|
if([fileManager fileExistsAtPath:absTestnetKeystoreUrl.path]){
|
|
NSLog(@"copy keystore");
|
|
[fileManager copyItemAtPath:absTestnetKeystoreUrl.path toPath:absKeystoreUrl.path error:nil];
|
|
[fileManager removeItemAtPath:absTestnetKeystoreUrl.path error:nil];
|
|
}
|
|
|
|
NSLog(@"after lightChainData");
|
|
|
|
NSLog(@"preconfig: %@", config);
|
|
NSData *configData = [config dataUsingEncoding:NSUTF8StringEncoding];
|
|
NSDictionary *configJSON = [NSJSONSerialization JSONObjectWithData:configData options:NSJSONReadingMutableContainers error:nil];
|
|
NSString *relativeDataDir = [configJSON objectForKey:@"DataDir"];
|
|
if (relativeDataDir == nil) {
|
|
relativeDataDir = @"";
|
|
}
|
|
NSString *absDataDir = [rootUrl.path stringByAppendingString:relativeDataDir];
|
|
NSURL *absDataDirUrl = [NSURL fileURLWithPath:absDataDir];
|
|
NSString *keystoreDir = [@"/keystore/" stringByAppendingString:keyUID];
|
|
[configJSON setValue:keystoreDir forKey:@"KeyStoreDir"];
|
|
[configJSON setValue:@"" forKey:@"LogDir"];
|
|
[configJSON setValue:@"geth.log" forKey:@"LogFile"];
|
|
NSString *resultingConfig = [Utils jsonStringWithPrettyPrint:NO fromDictionary:configJSON];
|
|
|
|
NSLog(@"node config %@", resultingConfig);
|
|
|
|
if(![fileManager fileExistsAtPath:absDataDir]) {
|
|
[fileManager createDirectoryAtPath:absDataDir
|
|
withIntermediateDirectories:YES attributes:nil error:nil];
|
|
}
|
|
|
|
NSLog(@"logUrlPath %@ rootDir %@", @"geth.log", rootUrl.path);
|
|
NSURL *absLogUrl = [absDataDirUrl URLByAppendingPathComponent:@"geth.log"];
|
|
if(![fileManager fileExistsAtPath:absLogUrl.path]) {
|
|
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
|
|
[dict setObject:[NSNumber numberWithInt:511] forKey:NSFilePosixPermissions];
|
|
[fileManager createFileAtPath:absLogUrl.path contents:nil attributes:dict];
|
|
}
|
|
|
|
return resultingConfig;
|
|
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(deleteMultiaccount:(NSString *)keyUID
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
#if DEBUG
|
|
NSLog(@"DeleteMultiaccount() method called");
|
|
#endif
|
|
NSURL *multiaccountKeystoreDir = [Utils getKeyStoreDirForKeyUID:keyUID];
|
|
NSString *result = StatusgoDeleteMultiaccount(keyUID, multiaccountKeystoreDir.path);
|
|
callback(@[result]);
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(prepareDirAndUpdateConfig:(NSString *)keyUID
|
|
config:(NSString *)config
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
#if DEBUG
|
|
NSLog(@"PrepareDirAndUpdateConfig() method called");
|
|
#endif
|
|
NSString *updatedConfig = [self prepareDirAndUpdateConfig:config
|
|
withKeyUID:keyUID];
|
|
callback(@[updatedConfig]);
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(saveAccountAndLoginWithKeycard:(NSString *)multiaccountData
|
|
password:(NSString *)password
|
|
settings:(NSString *)settings
|
|
config:(NSString *)config
|
|
accountsData:(NSString *)accountsData
|
|
chatKey:(NSString *)chatKey) {
|
|
#if DEBUG
|
|
NSLog(@"SaveAccountAndLoginWithKeycard() method called");
|
|
#endif
|
|
[Utils getExportDbFilePath];
|
|
NSString *keyUID = [Utils getKeyUID:multiaccountData];
|
|
NSString *finalConfig = [self prepareDirAndUpdateConfig:config
|
|
withKeyUID:keyUID];
|
|
NSString *result = StatusgoSaveAccountAndLoginWithKeycard(multiaccountData, password, settings, finalConfig, accountsData, chatKey);
|
|
NSLog(@"%@", result);
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(loginWithKeycard:(NSString *)accountData
|
|
password:(NSString *)password
|
|
chatKey:(NSString *)chatKey
|
|
nodeConfigJSON:(NSString *)nodeConfigJSON) {
|
|
#if DEBUG
|
|
NSLog(@"LoginWithKeycard() method called");
|
|
#endif
|
|
[Utils getExportDbFilePath];
|
|
[Utils migrateKeystore:accountData password:password];
|
|
|
|
NSString *result = StatusgoLoginWithKeycard(accountData, password, chatKey, nodeConfigJSON);
|
|
|
|
NSLog(@"%@", result);
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(loginWithConfig:(NSString *)accountData
|
|
password:(NSString *)password
|
|
configJSON:(NSString *)configJSON) {
|
|
#if DEBUG
|
|
NSLog(@"LoginWithConfig() method called");
|
|
#endif
|
|
[Utils getExportDbFilePath];
|
|
[Utils migrateKeystore:accountData password:password];
|
|
NSString *result = StatusgoLoginWithConfig(accountData, password, configJSON);
|
|
NSLog(@"%@", result);
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(loginAccount:(NSString *)request) {
|
|
#if DEBUG
|
|
NSLog(@"LoginAccount() method called");
|
|
#endif
|
|
NSString *result = StatusgoLoginAccount(request);
|
|
NSLog(@"%@", result);
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(verify:(NSString *)address
|
|
password:(NSString *)password
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
#if DEBUG
|
|
NSLog(@"VerifyAccountPassword() 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);
|
|
callback(@[result]);
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(verifyDatabasePassword:(NSString *)keyUID
|
|
password:(NSString *)password
|
|
callback:(RCTResponseSenderBlock)callback) {
|
|
#if DEBUG
|
|
NSLog(@"VerifyDatabasePassword() method called");
|
|
#endif
|
|
NSString *result = StatusgoVerifyDatabasePassword(keyUID, password);
|
|
callback(@[result]);
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(openAccounts:(RCTResponseSenderBlock)callback) {
|
|
#if DEBUG
|
|
NSLog(@"OpenAccounts() method called");
|
|
#endif
|
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
NSURL *rootUrl =[[fileManager
|
|
URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]
|
|
lastObject];
|
|
|
|
NSString *result = StatusgoOpenAccounts(rootUrl.path);
|
|
callback(@[result]);
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(logout) {
|
|
#if DEBUG
|
|
NSLog(@"Logout() method called");
|
|
#endif
|
|
NSString *result = StatusgoLogout();
|
|
|
|
NSLog(@"%@", result);
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(getRandomMnemonic:(RCTResponseSenderBlock)callback) {
|
|
#if DEBUG
|
|
NSLog(@"GetRandomMnemonic() method called");
|
|
#endif
|
|
NSString *result = StatusgoGetRandomMnemonic();
|
|
callback(@[result]);
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(createAccountFromMnemonicAndDeriveAccountsForPaths:(NSString *)mnemonic callback:(RCTResponseSenderBlock)callback) {
|
|
#if DEBUG
|
|
NSLog(@"createAccountFromMnemonicAndDeriveAccountsForPaths() method called");
|
|
#endif
|
|
NSString *result = StatusgoCreateAccountFromMnemonicAndDeriveAccountsForPaths(mnemonic);
|
|
callback(@[result]);
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(createAccountFromPrivateKey:(NSString *)configJSON callback:(RCTResponseSenderBlock)callback) {
|
|
#if DEBUG
|
|
NSLog(@"createAccountFromPrivateKey() method called");
|
|
#endif
|
|
NSString *result = StatusgoCreateAccountFromPrivateKey(configJSON);
|
|
callback(@[result]);
|
|
}
|
|
|
|
@end
|