@functionland/react-native-fula 1.41.1 → 1.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +226 -226
  3. package/android/build.gradle +1 -1
  4. package/android/gradle.properties +5 -5
  5. package/android/src/main/AndroidManifest.xml +3 -3
  6. package/android/src/main/AndroidManifestNew.xml +2 -2
  7. package/android/src/main/java/land/fx/fula/ConfigRef.java +7 -7
  8. package/android/src/main/java/land/fx/fula/Cryptography.java +62 -62
  9. package/android/src/main/java/land/fx/fula/FulaModule.java +31 -0
  10. package/android/src/main/java/land/fx/fula/FulaPackage.java +32 -32
  11. package/android/src/main/java/land/fx/fula/SharedPreferenceHelper.java +65 -65
  12. package/android/src/main/java/land/fx/fula/StaticHelper.java +13 -13
  13. package/android/src/main/java/land/fx/fula/ThreadUtils.java +42 -42
  14. package/ios/Cryptography.swift +49 -49
  15. package/ios/Fula-Bridging-Header.h +3 -3
  16. package/ios/Fula.mm +9 -0
  17. package/ios/Fula.swift +27 -1
  18. package/ios/UserDataHelper.swift +143 -143
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/commonjs/interfaces/augment-api-errors.js.map +1 -1
  21. package/lib/commonjs/interfaces/augment-api-rpc.js.map +1 -1
  22. package/lib/commonjs/interfaces/augment-api-runtime.js.map +1 -1
  23. package/lib/commonjs/interfaces/augment-api.js.map +1 -1
  24. package/lib/commonjs/interfaces/augment-types.js.map +1 -1
  25. package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
  26. package/lib/commonjs/interfaces/index.js.map +1 -1
  27. package/lib/commonjs/interfaces/lookup.js +278 -278
  28. package/lib/commonjs/interfaces/lookup.js.map +1 -1
  29. package/lib/commonjs/interfaces/registry.js.map +1 -1
  30. package/lib/commonjs/interfaces/types-lookup.js.map +1 -1
  31. package/lib/commonjs/interfaces/types.js.map +1 -1
  32. package/lib/commonjs/protocols/blockchain.js +25 -2
  33. package/lib/commonjs/protocols/blockchain.js.map +1 -1
  34. package/lib/commonjs/protocols/chain-api.js.map +1 -1
  35. package/lib/commonjs/protocols/fula.js +106 -106
  36. package/lib/commonjs/protocols/fula.js.map +1 -1
  37. package/lib/commonjs/protocols/fxblox.js +23 -1
  38. package/lib/commonjs/protocols/fxblox.js.map +1 -1
  39. package/lib/commonjs/types/blockchain.js.map +1 -1
  40. package/lib/commonjs/types/fxblox.js.map +1 -1
  41. package/lib/module/index.js.map +1 -1
  42. package/lib/module/interfaces/augment-api-errors.js.map +1 -1
  43. package/lib/module/interfaces/augment-api-rpc.js.map +1 -1
  44. package/lib/module/interfaces/augment-api-runtime.js.map +1 -1
  45. package/lib/module/interfaces/augment-api.js.map +1 -1
  46. package/lib/module/interfaces/augment-types.js.map +1 -1
  47. package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
  48. package/lib/module/interfaces/index.js.map +1 -1
  49. package/lib/module/interfaces/lookup.js +278 -278
  50. package/lib/module/interfaces/lookup.js.map +1 -1
  51. package/lib/module/interfaces/registry.js.map +1 -1
  52. package/lib/module/interfaces/types-lookup.js.map +1 -1
  53. package/lib/module/interfaces/types.js.map +1 -1
  54. package/lib/module/protocols/blockchain.js +22 -0
  55. package/lib/module/protocols/blockchain.js.map +1 -1
  56. package/lib/module/protocols/chain-api.js.map +1 -1
  57. package/lib/module/protocols/fula.js +106 -106
  58. package/lib/module/protocols/fula.js.map +1 -1
  59. package/lib/module/protocols/fxblox.js +21 -0
  60. package/lib/module/protocols/fxblox.js.map +1 -1
  61. package/lib/module/types/blockchain.js.map +1 -1
  62. package/lib/module/types/fxblox.js.map +1 -1
  63. package/lib/typescript/interfaces/fulaNativeModule.d.ts +2 -0
  64. package/lib/typescript/interfaces/fulaNativeModule.d.ts.map +1 -1
  65. package/lib/typescript/protocols/blockchain.d.ts +1 -0
  66. package/lib/typescript/protocols/blockchain.d.ts.map +1 -1
  67. package/lib/typescript/protocols/fxblox.d.ts +1 -0
  68. package/lib/typescript/protocols/fxblox.d.ts.map +1 -1
  69. package/lib/typescript/types/blockchain.d.ts +5 -0
  70. package/lib/typescript/types/blockchain.d.ts.map +1 -1
  71. package/lib/typescript/types/fxblox.d.ts +4 -0
  72. package/lib/typescript/types/fxblox.d.ts.map +1 -1
  73. package/package.json +1 -1
  74. package/react-native-fula.podspec +47 -47
  75. package/src/index.tsx +4 -4
  76. package/src/interfaces/augment-api-errors.ts +449 -449
  77. package/src/interfaces/augment-api-rpc.ts +617 -617
  78. package/src/interfaces/augment-api-runtime.ts +224 -224
  79. package/src/interfaces/augment-api.ts +10 -10
  80. package/src/interfaces/augment-types.ts +1230 -1230
  81. package/src/interfaces/fulaNativeModule.ts +5 -1
  82. package/src/interfaces/index.ts +4 -4
  83. package/src/interfaces/lookup.ts +1889 -1889
  84. package/src/interfaces/registry.ts +152 -152
  85. package/src/interfaces/types-lookup.ts +2043 -2043
  86. package/src/interfaces/types.ts +3 -3
  87. package/src/protocols/blockchain.ts +26 -0
  88. package/src/protocols/fula.ts +427 -427
  89. package/src/protocols/fxblox.ts +26 -0
  90. package/src/types/blockchain.ts +6 -0
  91. package/src/types/fxblox.ts +5 -0
@@ -1,62 +1,62 @@
1
- package land.fx.fula;
2
-
3
- import android.util.Base64;
4
-
5
- import java.io.UnsupportedEncodingException;
6
- import java.nio.charset.StandardCharsets;
7
- import java.security.InvalidAlgorithmParameterException;
8
- import java.security.InvalidKeyException;
9
- import java.security.NoSuchAlgorithmException;
10
- import java.security.spec.InvalidKeySpecException;
11
- import java.security.SecureRandom;
12
- import java.nio.ByteBuffer;
13
- import java.security.spec.InvalidParameterSpecException;
14
-
15
- import javax.crypto.BadPaddingException;
16
- import javax.crypto.Cipher;
17
- import javax.crypto.IllegalBlockSizeException;
18
- import javax.crypto.NoSuchPaddingException;
19
- import javax.crypto.SecretKey;
20
- import javax.crypto.SecretKeyFactory;
21
- import javax.crypto.spec.PBEKeySpec;
22
- import javax.crypto.spec.SecretKeySpec;
23
- import javax.crypto.spec.GCMParameterSpec;
24
-
25
- public class Cryptography {
26
- public static String encryptMsg(String message, SecretKey secret, byte[] iv)
27
- throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException {
28
- Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
29
- if (iv == null || iv.length == 0) {
30
- iv = new byte[12]; // Ensure this is randomly generated for each encryption.
31
- new SecureRandom().nextBytes(iv);
32
- }
33
- GCMParameterSpec spec = new GCMParameterSpec(128, iv);
34
- cipher.init(Cipher.ENCRYPT_MODE, secret, spec);
35
- byte[] cipherText = cipher.doFinal(message.getBytes(StandardCharsets.UTF_8));
36
- ByteBuffer byteBuffer = ByteBuffer.allocate(iv.length + cipherText.length);
37
- byteBuffer.put(iv);
38
- byteBuffer.put(cipherText);
39
- return Base64.encodeToString(byteBuffer.array(), Base64.NO_WRAP);
40
- }
41
-
42
- public static String decryptMsg(String cipherText, SecretKey secret)
43
- throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
44
- ByteBuffer byteBuffer = ByteBuffer.wrap(Base64.decode(cipherText, Base64.NO_WRAP));
45
- byte[] iv = new byte[12];
46
- byteBuffer.get(iv);
47
- byte[] cipherBytes = new byte[byteBuffer.remaining()];
48
- byteBuffer.get(cipherBytes);
49
- Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
50
- GCMParameterSpec spec = new GCMParameterSpec(128, iv);
51
- cipher.init(Cipher.DECRYPT_MODE, secret, spec);
52
- String decryptString = new String(cipher.doFinal(cipherBytes), StandardCharsets.UTF_8);
53
- return decryptString;
54
- }
55
-
56
- public static SecretKey generateKey(byte[] key)
57
- throws NoSuchAlgorithmException, InvalidKeySpecException {
58
- PBEKeySpec pbeKeySpec = new PBEKeySpec(StaticHelper.bytesToBase64(key).toCharArray(), key, 1000, 128);
59
- SecretKey pbeKey = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256").generateSecret(pbeKeySpec);
60
- return new SecretKeySpec(pbeKey.getEncoded(), "AES");
61
- }
62
- }
1
+ package land.fx.fula;
2
+
3
+ import android.util.Base64;
4
+
5
+ import java.io.UnsupportedEncodingException;
6
+ import java.nio.charset.StandardCharsets;
7
+ import java.security.InvalidAlgorithmParameterException;
8
+ import java.security.InvalidKeyException;
9
+ import java.security.NoSuchAlgorithmException;
10
+ import java.security.spec.InvalidKeySpecException;
11
+ import java.security.SecureRandom;
12
+ import java.nio.ByteBuffer;
13
+ import java.security.spec.InvalidParameterSpecException;
14
+
15
+ import javax.crypto.BadPaddingException;
16
+ import javax.crypto.Cipher;
17
+ import javax.crypto.IllegalBlockSizeException;
18
+ import javax.crypto.NoSuchPaddingException;
19
+ import javax.crypto.SecretKey;
20
+ import javax.crypto.SecretKeyFactory;
21
+ import javax.crypto.spec.PBEKeySpec;
22
+ import javax.crypto.spec.SecretKeySpec;
23
+ import javax.crypto.spec.GCMParameterSpec;
24
+
25
+ public class Cryptography {
26
+ public static String encryptMsg(String message, SecretKey secret, byte[] iv)
27
+ throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException {
28
+ Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
29
+ if (iv == null || iv.length == 0) {
30
+ iv = new byte[12]; // Ensure this is randomly generated for each encryption.
31
+ new SecureRandom().nextBytes(iv);
32
+ }
33
+ GCMParameterSpec spec = new GCMParameterSpec(128, iv);
34
+ cipher.init(Cipher.ENCRYPT_MODE, secret, spec);
35
+ byte[] cipherText = cipher.doFinal(message.getBytes(StandardCharsets.UTF_8));
36
+ ByteBuffer byteBuffer = ByteBuffer.allocate(iv.length + cipherText.length);
37
+ byteBuffer.put(iv);
38
+ byteBuffer.put(cipherText);
39
+ return Base64.encodeToString(byteBuffer.array(), Base64.NO_WRAP);
40
+ }
41
+
42
+ public static String decryptMsg(String cipherText, SecretKey secret)
43
+ throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
44
+ ByteBuffer byteBuffer = ByteBuffer.wrap(Base64.decode(cipherText, Base64.NO_WRAP));
45
+ byte[] iv = new byte[12];
46
+ byteBuffer.get(iv);
47
+ byte[] cipherBytes = new byte[byteBuffer.remaining()];
48
+ byteBuffer.get(cipherBytes);
49
+ Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
50
+ GCMParameterSpec spec = new GCMParameterSpec(128, iv);
51
+ cipher.init(Cipher.DECRYPT_MODE, secret, spec);
52
+ String decryptString = new String(cipher.doFinal(cipherBytes), StandardCharsets.UTF_8);
53
+ return decryptString;
54
+ }
55
+
56
+ public static SecretKey generateKey(byte[] key)
57
+ throws NoSuchAlgorithmException, InvalidKeySpecException {
58
+ PBEKeySpec pbeKeySpec = new PBEKeySpec(StaticHelper.bytesToBase64(key).toCharArray(), key, 1000, 128);
59
+ SecretKey pbeKey = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256").generateSecret(pbeKeySpec);
60
+ return new SecretKeySpec(pbeKey.getEncoded(), "AES");
61
+ }
62
+ }
@@ -1236,6 +1236,21 @@ public class FulaModule extends ReactContextBaseJavaModule {
1236
1236
  });
1237
1237
  }
1238
1238
 
1239
+ @ReactMethod
1240
+ public void accountFund(String accountString, Promise promise) {
1241
+ ThreadUtils.runOnExecutor(() -> {
1242
+ Log.d("ReactNative", "accountFund: accountString = " + accountString);
1243
+ try {
1244
+ byte[] result = this.fula.accountFund(accountString);
1245
+ String resultString = toString(result);
1246
+ promise.resolve(resultString);
1247
+ } catch (Exception e) {
1248
+ Log.d("ReactNative", e.getMessage());
1249
+ promise.reject(e);
1250
+ }
1251
+ });
1252
+ }
1253
+
1239
1254
  @ReactMethod
1240
1255
  public void assetsBalance(String account, String assetId, String classId, Promise promise) {
1241
1256
  long assetIdLong = Long.parseLong(assetId);
@@ -1475,6 +1490,22 @@ public class FulaModule extends ReactContextBaseJavaModule {
1475
1490
  });
1476
1491
  }
1477
1492
 
1493
+ @ReactMethod
1494
+ public void fetchContainerLogs(Promise promise, String containerName, String tailCount) {
1495
+ ThreadUtils.runOnExecutor(() -> {
1496
+ Log.d("ReactNative", "fetchContainerLogs");
1497
+ try {
1498
+ byte[] result = this.fula.fetchContainerLogs(containerName, tailCount);
1499
+ String resultString = toString(result);
1500
+ Log.d("ReactNative", "result string="+resultString);
1501
+ promise.resolve(resultString);
1502
+ } catch (Exception e) {
1503
+ Log.d("ReactNative", e.getMessage());
1504
+ promise.reject(e);
1505
+ }
1506
+ });
1507
+ }
1508
+
1478
1509
  @ReactMethod
1479
1510
  public void reboot(Promise promise) {
1480
1511
  ThreadUtils.runOnExecutor(() -> {
@@ -1,32 +1,32 @@
1
- package land.fx.fula;
2
-
3
- import androidx.annotation.NonNull;
4
-
5
- import com.facebook.react.ReactPackage;
6
- import com.facebook.react.bridge.NativeModule;
7
- import com.facebook.react.bridge.ReactApplicationContext;
8
- import com.facebook.react.uimanager.ViewManager;
9
-
10
- import java.util.ArrayList;
11
- import java.util.Collections;
12
- import java.util.List;
13
-
14
- public class FulaPackage implements ReactPackage {
15
- @NonNull
16
- @Override
17
- public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
18
- List<NativeModule> modules = new ArrayList<>();
19
- try {
20
- modules.add(new FulaModule(reactContext));
21
- } catch (Exception e) {
22
- e.printStackTrace();
23
- }
24
- return modules;
25
- }
26
-
27
- @NonNull
28
- @Override
29
- public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
30
- return Collections.emptyList();
31
- }
32
- }
1
+ package land.fx.fula;
2
+
3
+ import androidx.annotation.NonNull;
4
+
5
+ import com.facebook.react.ReactPackage;
6
+ import com.facebook.react.bridge.NativeModule;
7
+ import com.facebook.react.bridge.ReactApplicationContext;
8
+ import com.facebook.react.uimanager.ViewManager;
9
+
10
+ import java.util.ArrayList;
11
+ import java.util.Collections;
12
+ import java.util.List;
13
+
14
+ public class FulaPackage implements ReactPackage {
15
+ @NonNull
16
+ @Override
17
+ public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
18
+ List<NativeModule> modules = new ArrayList<>();
19
+ try {
20
+ modules.add(new FulaModule(reactContext));
21
+ } catch (Exception e) {
22
+ e.printStackTrace();
23
+ }
24
+ return modules;
25
+ }
26
+
27
+ @NonNull
28
+ @Override
29
+ public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
30
+ return Collections.emptyList();
31
+ }
32
+ }
@@ -1,65 +1,65 @@
1
- package land.fx.fula;
2
-
3
- import static android.content.Context.MODE_PRIVATE;
4
-
5
- import android.content.Context;
6
- import android.content.SharedPreferences;
7
- import android.util.Log;
8
-
9
- public class SharedPreferenceHelper {
10
- private static SharedPreferenceHelper me;
11
- private static String sharedPrefName;
12
- private static Context context;
13
-
14
- private SharedPreferenceHelper() {
15
- }
16
-
17
- public static SharedPreferenceHelper getInstance(Context cntx) {
18
- if (me == null) {
19
- me = new SharedPreferenceHelper();
20
- }
21
- context = cntx;
22
- sharedPrefName = "APP_KEY_PAIR_VALUE";
23
- return me;
24
- }
25
-
26
- public String getValue(String key) {
27
- SharedPreferences prefs = context.getSharedPreferences(sharedPrefName, MODE_PRIVATE);
28
- return prefs.getString(key, null);
29
- }
30
-
31
- public boolean getBooleanValue(String key) {
32
- SharedPreferences prefs = context.getSharedPreferences(sharedPrefName, MODE_PRIVATE);
33
- return prefs.getBoolean(key, false);
34
- }
35
-
36
- public SharedPreferenceHelper add(String key, String value) {
37
- try {
38
- context.getSharedPreferences(sharedPrefName, MODE_PRIVATE).edit().putString(key, value).apply();
39
- return me;
40
- } catch (Exception ex) {
41
- Log.e("React-Native-Fula", "SharedPrefHandler: AddSharedPref: Exception: " + ex.getMessage(), ex);
42
- throw ex;
43
- }
44
- }
45
-
46
- public SharedPreferenceHelper add(String key, boolean value) {
47
- try {
48
- context.getSharedPreferences(sharedPrefName, MODE_PRIVATE).edit().putBoolean(key, value).apply();
49
- return me;
50
- } catch (Exception e) {
51
- Log.e("React-Native-Fula", "SharedPrefHandler: AddSharedPref: Exception: " + e.getMessage(), e);
52
- throw e;
53
- }
54
- }
55
-
56
- public SharedPreferenceHelper remove(String key) {
57
- try {
58
- context.getSharedPreferences(sharedPrefName, MODE_PRIVATE).edit().remove(key).apply();
59
- return me;
60
- } catch (Exception ex) {
61
- Log.e("React-Native-Fula", "SharedPrefHandler: AddSharedPref: Exception: " + ex.getMessage(), ex);
62
- throw ex;
63
- }
64
- }
65
- }
1
+ package land.fx.fula;
2
+
3
+ import static android.content.Context.MODE_PRIVATE;
4
+
5
+ import android.content.Context;
6
+ import android.content.SharedPreferences;
7
+ import android.util.Log;
8
+
9
+ public class SharedPreferenceHelper {
10
+ private static SharedPreferenceHelper me;
11
+ private static String sharedPrefName;
12
+ private static Context context;
13
+
14
+ private SharedPreferenceHelper() {
15
+ }
16
+
17
+ public static SharedPreferenceHelper getInstance(Context cntx) {
18
+ if (me == null) {
19
+ me = new SharedPreferenceHelper();
20
+ }
21
+ context = cntx;
22
+ sharedPrefName = "APP_KEY_PAIR_VALUE";
23
+ return me;
24
+ }
25
+
26
+ public String getValue(String key) {
27
+ SharedPreferences prefs = context.getSharedPreferences(sharedPrefName, MODE_PRIVATE);
28
+ return prefs.getString(key, null);
29
+ }
30
+
31
+ public boolean getBooleanValue(String key) {
32
+ SharedPreferences prefs = context.getSharedPreferences(sharedPrefName, MODE_PRIVATE);
33
+ return prefs.getBoolean(key, false);
34
+ }
35
+
36
+ public SharedPreferenceHelper add(String key, String value) {
37
+ try {
38
+ context.getSharedPreferences(sharedPrefName, MODE_PRIVATE).edit().putString(key, value).apply();
39
+ return me;
40
+ } catch (Exception ex) {
41
+ Log.e("React-Native-Fula", "SharedPrefHandler: AddSharedPref: Exception: " + ex.getMessage(), ex);
42
+ throw ex;
43
+ }
44
+ }
45
+
46
+ public SharedPreferenceHelper add(String key, boolean value) {
47
+ try {
48
+ context.getSharedPreferences(sharedPrefName, MODE_PRIVATE).edit().putBoolean(key, value).apply();
49
+ return me;
50
+ } catch (Exception e) {
51
+ Log.e("React-Native-Fula", "SharedPrefHandler: AddSharedPref: Exception: " + e.getMessage(), e);
52
+ throw e;
53
+ }
54
+ }
55
+
56
+ public SharedPreferenceHelper remove(String key) {
57
+ try {
58
+ context.getSharedPreferences(sharedPrefName, MODE_PRIVATE).edit().remove(key).apply();
59
+ return me;
60
+ } catch (Exception ex) {
61
+ Log.e("React-Native-Fula", "SharedPrefHandler: AddSharedPref: Exception: " + ex.getMessage(), ex);
62
+ throw ex;
63
+ }
64
+ }
65
+ }
@@ -1,13 +1,13 @@
1
- package land.fx.fula;
2
-
3
- import java.util.Base64;
4
-
5
- public class StaticHelper {
6
- public static String bytesToBase64(byte[] bytes) {
7
- return Base64.getEncoder().encodeToString(bytes);
8
- }
9
-
10
- public static byte[] base64ToBytes(String base64) {
11
- return Base64.getDecoder().decode(base64);
12
- }
13
- }
1
+ package land.fx.fula;
2
+
3
+ import java.util.Base64;
4
+
5
+ public class StaticHelper {
6
+ public static String bytesToBase64(byte[] bytes) {
7
+ return Base64.getEncoder().encodeToString(bytes);
8
+ }
9
+
10
+ public static byte[] base64ToBytes(String base64) {
11
+ return Base64.getDecoder().decode(base64);
12
+ }
13
+ }
@@ -1,42 +1,42 @@
1
- package land.fx.fula;
2
-
3
- import java.util.concurrent.Callable;
4
- import java.util.concurrent.ExecutorService;
5
- import java.util.concurrent.Executors;
6
- import java.util.concurrent.Future;
7
-
8
- final class ThreadUtils {
9
- /**
10
- * Thread which will be used to call all APIs. They
11
- * they don't run on the calling thread anyway, we are deferring the calls
12
- * to this thread to avoid (potentially) blocking the calling thread.
13
- */
14
- private static final ExecutorService executor
15
- = Executors.newSingleThreadExecutor();
16
-
17
- /**
18
- * Runs the given {@link Runnable} on the executor.
19
- * @param runnable
20
- */
21
- public static void runOnExecutor(Runnable runnable) {
22
- executor.execute(runnable);
23
- }
24
-
25
- /**
26
- * Submits the given {@link Callable} to be run on the executor.
27
- * @param callable
28
- * @return Future.
29
- */
30
- public static <T> Future<T> submitToExecutor(Callable<T> callable) {
31
- return executor.submit(callable);
32
- }
33
-
34
- /**
35
- * Submits the given {@link Runnable} to be run on the executor.
36
- * @param runnable
37
- * @return Future.
38
- */
39
- public static Future<?> submitToExecutor(Runnable runnable) {
40
- return executor.submit(runnable);
41
- }
42
- }
1
+ package land.fx.fula;
2
+
3
+ import java.util.concurrent.Callable;
4
+ import java.util.concurrent.ExecutorService;
5
+ import java.util.concurrent.Executors;
6
+ import java.util.concurrent.Future;
7
+
8
+ final class ThreadUtils {
9
+ /**
10
+ * Thread which will be used to call all APIs. They
11
+ * they don't run on the calling thread anyway, we are deferring the calls
12
+ * to this thread to avoid (potentially) blocking the calling thread.
13
+ */
14
+ private static final ExecutorService executor
15
+ = Executors.newSingleThreadExecutor();
16
+
17
+ /**
18
+ * Runs the given {@link Runnable} on the executor.
19
+ * @param runnable
20
+ */
21
+ public static void runOnExecutor(Runnable runnable) {
22
+ executor.execute(runnable);
23
+ }
24
+
25
+ /**
26
+ * Submits the given {@link Callable} to be run on the executor.
27
+ * @param callable
28
+ * @return Future.
29
+ */
30
+ public static <T> Future<T> submitToExecutor(Callable<T> callable) {
31
+ return executor.submit(callable);
32
+ }
33
+
34
+ /**
35
+ * Submits the given {@link Runnable} to be run on the executor.
36
+ * @param runnable
37
+ * @return Future.
38
+ */
39
+ public static Future<?> submitToExecutor(Runnable runnable) {
40
+ return executor.submit(runnable);
41
+ }
42
+ }
@@ -1,49 +1,49 @@
1
- import Foundation
2
- import CommonCrypto
3
- import CryptoSwift
4
- import os.log
5
-
6
-
7
-
8
- public class Cryptography: NSObject {
9
- public static func encryptMsg(_ message: Array<UInt8>, _ secretKey: Array<UInt8>)
10
- throws -> String {
11
- OSLog.viewCycle.info("ReactNative encryptMsg started for \(message)")
12
- let aes = try! AES(key: secretKey, blockMode: ECB(), padding: .pkcs5)
13
- OSLog.viewCycle.info("ReactNative encryptMsg aes")
14
- let encrypted = try! aes.encrypt(message)
15
- OSLog.viewCycle.info("ReactNative encryptMsg encrypted")
16
- do{
17
- let data = Data(encrypted).base64EncodedString()
18
- OSLog.viewCycle.info("ReactNative encryptMsg: \(data)")
19
- return data
20
- } catch let error {
21
- OSLog.viewCycle.info("ReactNative encryptMsg error: \(error.localizedDescription)")
22
- throw error
23
- }
24
- }
25
-
26
- public static func decryptMsg(_ cipherText: String, _ secretKey: Array<UInt8>)
27
- throws -> Array<UInt8> {
28
- let aes = try! AES(key: secretKey, blockMode: ECB(), padding: .pkcs5)
29
- let data = cipherText.fromBase64()!
30
- return try! aes.decrypt(data.bytes)
31
-
32
- }
33
-
34
- public static func generateKey(_ salt: Data)
35
- throws -> Array<UInt8> {
36
- let password: [UInt8] = Array("".utf8)
37
- let salt: [UInt8] = salt.bytes
38
-
39
- //TODO: Generate a key from a salt and an empty password
40
- let key = try PKCS5.PBKDF2(
41
- password: password,
42
- salt: salt,
43
- iterations: 4096,
44
- keyLength: 16, /* AES-128 */
45
- variant: .sha2(SHA2.Variant.sha256)
46
- ).calculate()
47
- return key
48
- }
49
- }
1
+ import Foundation
2
+ import CommonCrypto
3
+ import CryptoSwift
4
+ import os.log
5
+
6
+
7
+
8
+ public class Cryptography: NSObject {
9
+ public static func encryptMsg(_ message: Array<UInt8>, _ secretKey: Array<UInt8>)
10
+ throws -> String {
11
+ OSLog.viewCycle.info("ReactNative encryptMsg started for \(message)")
12
+ let aes = try! AES(key: secretKey, blockMode: ECB(), padding: .pkcs5)
13
+ OSLog.viewCycle.info("ReactNative encryptMsg aes")
14
+ let encrypted = try! aes.encrypt(message)
15
+ OSLog.viewCycle.info("ReactNative encryptMsg encrypted")
16
+ do{
17
+ let data = Data(encrypted).base64EncodedString()
18
+ OSLog.viewCycle.info("ReactNative encryptMsg: \(data)")
19
+ return data
20
+ } catch let error {
21
+ OSLog.viewCycle.info("ReactNative encryptMsg error: \(error.localizedDescription)")
22
+ throw error
23
+ }
24
+ }
25
+
26
+ public static func decryptMsg(_ cipherText: String, _ secretKey: Array<UInt8>)
27
+ throws -> Array<UInt8> {
28
+ let aes = try! AES(key: secretKey, blockMode: ECB(), padding: .pkcs5)
29
+ let data = cipherText.fromBase64()!
30
+ return try! aes.decrypt(data.bytes)
31
+
32
+ }
33
+
34
+ public static func generateKey(_ salt: Data)
35
+ throws -> Array<UInt8> {
36
+ let password: [UInt8] = Array("".utf8)
37
+ let salt: [UInt8] = salt.bytes
38
+
39
+ //TODO: Generate a key from a salt and an empty password
40
+ let key = try PKCS5.PBKDF2(
41
+ password: password,
42
+ salt: salt,
43
+ iterations: 4096,
44
+ keyLength: 16, /* AES-128 */
45
+ variant: .sha2(SHA2.Variant.sha256)
46
+ ).calculate()
47
+ return key
48
+ }
49
+ }
@@ -1,3 +1,3 @@
1
- #import <React/RCTBridgeModule.h>
2
- #import <React/RCTViewManager.h>
3
- #import <React/RCTConvert.h>
1
+ #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTViewManager.h>
3
+ #import <React/RCTConvert.h>
package/ios/Fula.mm CHANGED
@@ -113,6 +113,10 @@ RCT_EXTERN_METHOD(checkAccountExists:(NSString *)accountString
113
113
  withResolver:(RCTPromiseResolveBlock)resolve
114
114
  withRejecter:(RCTPromiseRejectBlock)reject)
115
115
 
116
+ RCT_EXTERN_METHOD(accountFund:(NSString *)accountString
117
+ withResolver:(RCTPromiseResolveBlock)resolve
118
+ withRejecter:(RCTPromiseRejectBlock)reject)
119
+
116
120
  RCT_EXTERN_METHOD(listPools:(RCTPromiseResolveBlock)resolve
117
121
  withRejecter:(RCTPromiseRejectBlock)reject)
118
122
 
@@ -158,6 +162,11 @@ RCT_EXTERN_METHOD(assetsBalance:(NSString *)account withAssetId:(NSString *)asse
158
162
 
159
163
  RCT_EXTERN_METHOD(getAccount:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
160
164
 
165
+ RCT_EXTERN_METHOD(fetchContainerLogs:(NSString *)containerName
166
+ withTailCount:(NSString *)tailCount
167
+ withResolver:(RCTPromiseResolveBlock)resolve
168
+ withRejecter:(RCTPromiseRejectBlock)reject)
169
+
161
170
  + (BOOL)requiresMainQueueSetup
162
171
  {
163
172
  return NO;
package/ios/Fula.swift CHANGED
@@ -1000,7 +1000,7 @@ class FulaModule: NSObject {
1000
1000
  }
1001
1001
 
1002
1002
  }
1003
-
1003
+
1004
1004
  @objc(clearCidsFromRecent:withResolver:withRejecter:)
1005
1005
  func clearCidsFromRecent(cidArray: NSArray, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
1006
1006
  DispatchQueue.global(qos: .default).async {
@@ -1105,6 +1105,20 @@ class FulaModule: NSObject {
1105
1105
 
1106
1106
  }
1107
1107
 
1108
+ @objc(accountFund:withResolver:withRejecter:)
1109
+ func accountFund(accountString: String, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
1110
+ print("ReactNative", "accountFund: accountString = ", accountString)
1111
+ do {
1112
+ let result = try fula!.accountFund(accountString)
1113
+ let resultString = result.toUTF8String()!
1114
+ resolve(resultString)
1115
+ } catch let error {
1116
+ print("accountFund", error.localizedDescription)
1117
+ reject("ERR_FULA", "accountFund", error)
1118
+ }
1119
+
1120
+ }
1121
+
1108
1122
  @objc(listPools:withRejecter:)
1109
1123
  func listPools( resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
1110
1124
  print("ReactNative", "listPools")
@@ -1284,6 +1298,18 @@ class FulaModule: NSObject {
1284
1298
  }
1285
1299
  }
1286
1300
 
1301
+ @objc(fetchContainerLogs:tailCount:withResolver:withRejecter:)
1302
+ func fetchContainerLogs(containerName: String, tailCount: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
1303
+ do {
1304
+ let result = try fula!.fetchContainerLogs(containerName, tailCount)
1305
+ let resultString = result.toUTF8String()!
1306
+ resolve(resultString)
1307
+ } catch let error {
1308
+ print("fetchContainerLogs", error.localizedDescription)
1309
+ reject("ERR_FULA", "fetchContainerLogs", error)
1310
+ }
1311
+ }
1312
+
1287
1313
  }
1288
1314
 
1289
1315