@functionland/react-native-fula 1.14.8 → 1.20.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 (141) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +226 -214
  3. package/android/build.gradle +2 -2
  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 +73 -104
  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 +197 -199
  17. package/ios/Fula.swift +1221 -1221
  18. package/ios/UserDataHelper.swift +143 -143
  19. package/lib/commonjs/index.js +2 -2
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/commonjs/interfaces/augment-api-errors.js +4 -0
  22. package/lib/commonjs/interfaces/augment-api-errors.js.map +1 -0
  23. package/lib/commonjs/interfaces/augment-api-rpc.js +4 -0
  24. package/lib/commonjs/interfaces/augment-api-rpc.js.map +1 -0
  25. package/lib/commonjs/interfaces/augment-api-runtime.js +4 -0
  26. package/lib/commonjs/interfaces/augment-api-runtime.js.map +1 -0
  27. package/lib/commonjs/interfaces/augment-api.js +10 -0
  28. package/lib/commonjs/interfaces/augment-api.js.map +1 -0
  29. package/lib/commonjs/interfaces/augment-types.js +4 -0
  30. package/lib/commonjs/interfaces/augment-types.js.map +1 -0
  31. package/lib/commonjs/interfaces/fulaNativeModule.js +1 -2
  32. package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
  33. package/lib/commonjs/interfaces/index.js +6 -0
  34. package/lib/commonjs/interfaces/index.js.map +1 -0
  35. package/lib/commonjs/interfaces/{api-lookup.js → lookup.js} +623 -382
  36. package/lib/commonjs/interfaces/lookup.js.map +1 -0
  37. package/lib/commonjs/interfaces/registry.js +4 -0
  38. package/lib/commonjs/interfaces/registry.js.map +1 -0
  39. package/lib/commonjs/interfaces/types-lookup.js +4 -0
  40. package/lib/commonjs/interfaces/types-lookup.js.map +1 -0
  41. package/lib/commonjs/interfaces/types.js +4 -0
  42. package/lib/commonjs/interfaces/types.js.map +1 -0
  43. package/lib/commonjs/protocols/blockchain.js +123 -76
  44. package/lib/commonjs/protocols/blockchain.js.map +1 -1
  45. package/lib/commonjs/protocols/chain-api.js +156 -42
  46. package/lib/commonjs/protocols/chain-api.js.map +1 -1
  47. package/lib/commonjs/protocols/fula.js +195 -99
  48. package/lib/commonjs/protocols/fula.js.map +1 -1
  49. package/lib/commonjs/protocols/fxblox.js +3 -3
  50. package/lib/commonjs/protocols/fxblox.js.map +1 -1
  51. package/lib/commonjs/types/blockchain.js.map +1 -1
  52. package/lib/commonjs/types/fxblox.js.map +1 -1
  53. package/lib/module/index.js.map +1 -1
  54. package/lib/module/interfaces/augment-api-errors.js +9 -0
  55. package/lib/module/interfaces/augment-api-errors.js.map +1 -0
  56. package/lib/module/interfaces/augment-api-rpc.js +9 -0
  57. package/lib/module/interfaces/augment-api-rpc.js.map +1 -0
  58. package/lib/module/interfaces/augment-api-runtime.js +9 -0
  59. package/lib/module/interfaces/augment-api-runtime.js.map +1 -0
  60. package/lib/module/interfaces/augment-api.js +11 -0
  61. package/lib/module/interfaces/augment-api.js.map +1 -0
  62. package/lib/module/interfaces/augment-types.js +9 -0
  63. package/lib/module/interfaces/augment-types.js.map +1 -0
  64. package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
  65. package/lib/module/interfaces/index.js +5 -0
  66. package/lib/module/interfaces/index.js.map +1 -0
  67. package/lib/module/interfaces/{api-lookup.js → lookup.js} +622 -380
  68. package/lib/module/interfaces/lookup.js.map +1 -0
  69. package/lib/module/interfaces/registry.js +9 -0
  70. package/lib/module/interfaces/registry.js.map +1 -0
  71. package/lib/module/interfaces/types-lookup.js +9 -0
  72. package/lib/module/interfaces/types-lookup.js.map +1 -0
  73. package/lib/module/interfaces/types.js +3 -0
  74. package/lib/module/interfaces/types.js.map +1 -0
  75. package/lib/module/protocols/blockchain.js +120 -75
  76. package/lib/module/protocols/blockchain.js.map +1 -1
  77. package/lib/module/protocols/chain-api.js +147 -36
  78. package/lib/module/protocols/chain-api.js.map +1 -1
  79. package/lib/module/protocols/fula.js +191 -99
  80. package/lib/module/protocols/fula.js.map +1 -1
  81. package/lib/module/protocols/fxblox.js +3 -3
  82. package/lib/module/protocols/fxblox.js.map +1 -1
  83. package/lib/module/types/blockchain.js.map +1 -1
  84. package/lib/module/types/fxblox.js.map +1 -1
  85. package/lib/typescript/interfaces/augment-api-errors.d.ts +442 -0
  86. package/lib/typescript/interfaces/augment-api-errors.d.ts.map +1 -0
  87. package/lib/typescript/interfaces/augment-api-rpc.d.ts +680 -0
  88. package/lib/typescript/interfaces/augment-api-rpc.d.ts.map +1 -0
  89. package/lib/typescript/interfaces/augment-api-runtime.d.ts +248 -0
  90. package/lib/typescript/interfaces/augment-api-runtime.d.ts.map +1 -0
  91. package/lib/typescript/interfaces/augment-api.d.ts +8 -0
  92. package/lib/typescript/interfaces/augment-api.d.ts.map +1 -0
  93. package/lib/typescript/interfaces/augment-types.d.ts +1224 -0
  94. package/lib/typescript/interfaces/augment-types.d.ts.map +1 -0
  95. package/lib/typescript/interfaces/fulaNativeModule.d.ts +7 -3
  96. package/lib/typescript/interfaces/fulaNativeModule.d.ts.map +1 -1
  97. package/lib/typescript/interfaces/index.d.ts +1 -0
  98. package/lib/typescript/interfaces/index.d.ts.map +1 -0
  99. package/lib/typescript/interfaces/{api-lookup.d.ts → lookup.d.ts} +441 -199
  100. package/lib/typescript/interfaces/lookup.d.ts.map +1 -0
  101. package/lib/typescript/interfaces/registry.d.ts +146 -0
  102. package/lib/typescript/interfaces/registry.d.ts.map +1 -0
  103. package/lib/typescript/interfaces/types-lookup.d.ts +1910 -0
  104. package/lib/typescript/interfaces/types-lookup.d.ts.map +1 -0
  105. package/lib/typescript/interfaces/types.d.ts +1 -0
  106. package/lib/typescript/interfaces/types.d.ts.map +1 -0
  107. package/lib/typescript/protocols/blockchain.d.ts +5 -3
  108. package/lib/typescript/protocols/blockchain.d.ts.map +1 -1
  109. package/lib/typescript/protocols/chain-api.d.ts +5 -0
  110. package/lib/typescript/protocols/chain-api.d.ts.map +1 -1
  111. package/lib/typescript/protocols/fula.d.ts +16 -0
  112. package/lib/typescript/protocols/fula.d.ts.map +1 -1
  113. package/lib/typescript/types/blockchain.d.ts +6 -0
  114. package/lib/typescript/types/blockchain.d.ts.map +1 -1
  115. package/package.json +9 -3
  116. package/react-native-fula.podspec +47 -47
  117. package/src/index.tsx +4 -4
  118. package/src/interfaces/augment-api-errors.ts +449 -0
  119. package/src/interfaces/augment-api-rpc.ts +617 -0
  120. package/src/interfaces/augment-api-runtime.ts +224 -0
  121. package/src/interfaces/augment-api.ts +10 -0
  122. package/src/interfaces/augment-types.ts +1230 -0
  123. package/src/interfaces/fulaNativeModule.ts +11 -3
  124. package/src/interfaces/index.ts +4 -0
  125. package/src/interfaces/{api-lookup.ts → lookup.ts} +1889 -1647
  126. package/src/interfaces/registry.ts +152 -0
  127. package/src/interfaces/types-lookup.ts +2043 -0
  128. package/src/interfaces/types.ts +3 -0
  129. package/src/protocols/blockchain.ts +549 -504
  130. package/src/protocols/chain-api.ts +259 -135
  131. package/src/protocols/fula.ts +419 -314
  132. package/src/protocols/fxblox.ts +49 -49
  133. package/src/types/blockchain.ts +89 -81
  134. package/src/types/fxblox.ts +8 -8
  135. package/ios/Fula.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  136. package/ios/Fula.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  137. package/ios/Fula.xcodeproj/project.xcworkspace/xcuserdata/user246549.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  138. package/ios/Fula.xcodeproj/xcuserdata/user246549.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  139. package/lib/commonjs/interfaces/api-lookup.js.map +0 -1
  140. package/lib/module/interfaces/api-lookup.js.map +0 -1
  141. package/lib/typescript/interfaces/api-lookup.d.ts.map +0 -1
@@ -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
+ }
@@ -651,6 +651,7 @@ public class FulaModule extends ReactContextBaseJavaModule {
651
651
  Log.d("ReactNative", "Creating a new Fula instance");
652
652
  try {
653
653
  shutdownInternal();
654
+ Log.d("ReactNative", "Creating a new Fula instance with config");
654
655
  this.fula = Fulamobile.newClient(fulaConfig);
655
656
  if (this.fula != null) {
656
657
  this.fula.flush();
@@ -1121,6 +1122,8 @@ public class FulaModule extends ReactContextBaseJavaModule {
1121
1122
  this.fula.shutdown();
1122
1123
  this.fula = null;
1123
1124
  this.client = null;
1125
+ Log.d("ReactNative", "shutdownInternal done");
1126
+
1124
1127
  }
1125
1128
  } catch (Exception e) {
1126
1129
  Log.d("ReactNative", "shutdownInternal"+ e.getMessage());
@@ -1148,21 +1151,13 @@ public class FulaModule extends ReactContextBaseJavaModule {
1148
1151
  //////////////////////ANYTHING BELOW IS FOR BLOCKCHAIN/////
1149
1152
  ///////////////////////////////////////////////////////////
1150
1153
  @ReactMethod
1151
- public void createAccount(String seedString, Promise promise) {
1154
+ public void getAccount(Promise promise) {
1152
1155
  ThreadUtils.runOnExecutor(() -> {
1153
- Log.d("ReactNative", "createAccount: seedString = " + seedString);
1156
+ Log.d("ReactNative", "getAccount called ");
1154
1157
  try {
1155
- if (this.fula == null || this.fula.id() == null || this.fula.id().isEmpty()) {
1156
- promise.reject(new Error("Fula client is not initialized"));
1157
- } else {
1158
-
1159
- if (!seedString.startsWith("/")) {
1160
- promise.reject(new Error("seed should start with /"));
1161
- }
1162
- byte[] result = this.fula.seeded(seedString);
1163
- String resultString = toString(result);
1164
- promise.resolve(resultString);
1165
- }
1158
+ byte[] result = this.fula.getAccount();
1159
+ String resultString = toString(result);
1160
+ promise.resolve(resultString);
1166
1161
  } catch (Exception e) {
1167
1162
  Log.d("get", e.getMessage());
1168
1163
  promise.reject(e);
@@ -1171,11 +1166,11 @@ public class FulaModule extends ReactContextBaseJavaModule {
1171
1166
  }
1172
1167
 
1173
1168
  @ReactMethod
1174
- public void checkAccountExists(String accountString, Promise promise) {
1169
+ public void assetsBalance(String account, String assetId, String classId, Promise promise) {
1175
1170
  ThreadUtils.runOnExecutor(() -> {
1176
- Log.d("ReactNative", "checkAccountExists: accountString = " + accountString);
1171
+ Log.d("ReactNative", "assetsBalance called ");
1177
1172
  try {
1178
- byte[] result = this.fula.accountExists(accountString);
1173
+ byte[] result = this.fula.assetsBalance(account, assetId, classId);
1179
1174
  String resultString = toString(result);
1180
1175
  promise.resolve(resultString);
1181
1176
  } catch (Exception e) {
@@ -1186,11 +1181,11 @@ public class FulaModule extends ReactContextBaseJavaModule {
1186
1181
  }
1187
1182
 
1188
1183
  @ReactMethod
1189
- public void createPool(String seedString, String poolName, Promise promise) {
1184
+ public void checkAccountExists(String accountString, Promise promise) {
1190
1185
  ThreadUtils.runOnExecutor(() -> {
1191
- Log.d("ReactNative", "createPool: seedString = " + seedString + "; poolName = " + poolName);
1186
+ Log.d("ReactNative", "checkAccountExists: accountString = " + accountString);
1192
1187
  try {
1193
- byte[] result = this.fula.poolCreate(seedString, poolName);
1188
+ byte[] result = this.fula.accountExists(accountString);
1194
1189
  String resultString = toString(result);
1195
1190
  promise.resolve(resultString);
1196
1191
  } catch (Exception e) {
@@ -1216,11 +1211,12 @@ public class FulaModule extends ReactContextBaseJavaModule {
1216
1211
  }
1217
1212
 
1218
1213
  @ReactMethod
1219
- public void joinPool(String seedString, long poolID, Promise promise) {
1214
+ public void joinPool(String poolID, Promise promise) {
1220
1215
  ThreadUtils.runOnExecutor(() -> {
1221
- Log.d("ReactNative", "joinPool: seedString = " + seedString + "; poolID = " + poolID);
1216
+ long poolIdLong = Long.parseLong(poolID);
1217
+ Log.d("ReactNative", "joinPool: poolID = " + poolIdLong);
1222
1218
  try {
1223
- byte[] result = this.fula.poolJoin(seedString, poolID);
1219
+ byte[] result = this.fula.poolJoin(poolIdLong);
1224
1220
  String resultString = toString(result);
1225
1221
  promise.resolve(resultString);
1226
1222
  } catch (Exception e) {
@@ -1231,11 +1227,11 @@ public class FulaModule extends ReactContextBaseJavaModule {
1231
1227
  }
1232
1228
 
1233
1229
  @ReactMethod
1234
- public void cancelPoolJoin(String seedString, long poolID, Promise promise) {
1230
+ public void cancelPoolJoin(long poolID, Promise promise) {
1235
1231
  ThreadUtils.runOnExecutor(() -> {
1236
- Log.d("ReactNative", "cancelPoolJoin: seedString = " + seedString + "; poolID = " + poolID);
1232
+ Log.d("ReactNative", "cancelPoolJoin: poolID = " + poolID);
1237
1233
  try {
1238
- byte[] result = this.fula.poolCancelJoin(seedString, poolID);
1234
+ byte[] result = this.fula.poolCancelJoin(poolID);
1239
1235
  String resultString = toString(result);
1240
1236
  promise.resolve(resultString);
1241
1237
  } catch (Exception e) {
@@ -1261,56 +1257,11 @@ public class FulaModule extends ReactContextBaseJavaModule {
1261
1257
  }
1262
1258
 
1263
1259
  @ReactMethod
1264
- public void votePoolJoinRequest(String seedString, long poolID, String accountString, boolean accept, Promise promise) {
1265
- ThreadUtils.runOnExecutor(() -> {
1266
- Log.d("ReactNative", "votePoolJoinRequest: seedString = " + seedString + "; poolID = " + poolID + "; accountString = " + accountString + "; accept = " + accept);
1267
- try {
1268
- byte[] result = this.fula.poolVote(seedString, poolID, accountString, accept);
1269
- String resultString = toString(result);
1270
- promise.resolve(resultString);
1271
- } catch (Exception e) {
1272
- Log.d("get", e.getMessage());
1273
- promise.reject(e);
1274
- }
1275
- });
1276
- }
1277
-
1278
- @ReactMethod
1279
- public void leavePool(String seedString, long poolID, Promise promise) {
1260
+ public void leavePool(long poolID, Promise promise) {
1280
1261
  ThreadUtils.runOnExecutor(() -> {
1281
- Log.d("ReactNative", "leavePool: seedString = " + seedString + "; poolID = " + poolID);
1262
+ Log.d("ReactNative", "leavePool: poolID = " + poolID);
1282
1263
  try {
1283
- byte[] result = this.fula.poolLeave(seedString, poolID);
1284
- String resultString = toString(result);
1285
- promise.resolve(resultString);
1286
- } catch (Exception e) {
1287
- Log.d("get", e.getMessage());
1288
- promise.reject(e);
1289
- }
1290
- });
1291
- }
1292
-
1293
- @ReactMethod
1294
- public void newReplicationRequest(String seedString, long poolID, long replicationFactor, String cid, Promise promise) {
1295
- ThreadUtils.runOnExecutor(() -> {
1296
- Log.d("ReactNative", "newReplicationRequest: seedString = " + seedString + "; poolID = " + poolID + "; replicationFactor = " + replicationFactor + "; cid = " + cid);
1297
- try {
1298
- byte[] result = this.fula.manifestUpload(seedString, poolID, replicationFactor, cid);
1299
- String resultString = toString(result);
1300
- promise.resolve(resultString);
1301
- } catch (Exception e) {
1302
- Log.d("get", e.getMessage());
1303
- promise.reject(e);
1304
- }
1305
- });
1306
- }
1307
-
1308
- @ReactMethod
1309
- public void newStoreRequest(String seedString, long poolID, String uploader, String cid, Promise promise) {
1310
- ThreadUtils.runOnExecutor(() -> {
1311
- Log.d("ReactNative", "newStoreRequest: seedString = " + seedString + "; poolID = " + poolID + "; uploader = " + uploader + "; cid = " + cid);
1312
- try {
1313
- byte[] result = this.fula.manifestStore(seedString, poolID, uploader, cid);
1264
+ byte[] result = this.fula.poolLeave(poolID);
1314
1265
  String resultString = toString(result);
1315
1266
  promise.resolve(resultString);
1316
1267
  } catch (Exception e) {
@@ -1336,50 +1287,68 @@ public class FulaModule extends ReactContextBaseJavaModule {
1336
1287
  }
1337
1288
 
1338
1289
  @ReactMethod
1339
- public void removeReplicationRequest(String seedString, long poolID, String cid, Promise promise) {
1290
+ private void listRecentCidsAsString(Promise promise) throws Exception {
1340
1291
  ThreadUtils.runOnExecutor(() -> {
1341
- Log.d("ReactNative", "newReplicationRequest: seedString = " + seedString + "; poolID = " + poolID + "; cid = " + cid);
1342
- try {
1343
- byte[] result = this.fula.manifestRemove(seedString, poolID, cid);
1344
- String resultString = toString(result);
1345
- promise.resolve(resultString);
1346
- } catch (Exception e) {
1347
- Log.d("get", e.getMessage());
1348
- promise.reject(e);
1292
+ try {
1293
+ if (this.fula != null) {
1294
+ Log.d("ReactNative", "ListRecentCidsAsString");
1295
+ fulamobile.StringIterator recentLinks = this.fula.listRecentCidsAsString();
1296
+ ArrayList<String> recentLinksList = new ArrayList<>();
1297
+ while (recentLinks.hasNext()) {
1298
+ recentLinksList.add(recentLinks.next());
1299
+ }
1300
+ if (!recentLinksList.isEmpty()) {
1301
+ // return the whole list
1302
+ Log.d("ReactNative", "ListRecentCidsAsString found: "+ recentLinksList);
1303
+ WritableArray recentLinksArray = Arguments.createArray();
1304
+ for (String link : recentLinksList) {
1305
+ recentLinksArray.pushString(link);
1306
+ }
1307
+ promise.resolve(recentLinksArray);
1308
+ } else {
1309
+ promise.resolve(false);
1310
+ }
1311
+ } else {
1312
+ throw new Exception("ListRecentCidsAsString: Fula is not initialized");
1349
1313
  }
1350
- });
1351
- }
1352
-
1353
- @ReactMethod
1354
- public void removeStorer(String seedString, String storage, long poolID, String cid, Promise promise) {
1355
- ThreadUtils.runOnExecutor(() -> {
1356
- Log.d("ReactNative", "removeStorer: seedString = " + seedString + "; storage = " + storage + "; poolID = " + poolID + "; cid = " + cid);
1314
+ } catch (Exception e) {
1315
+ Log.d("ReactNative", "ListRecentCidsAsString failed with Error: " + e.getMessage());
1357
1316
  try {
1358
- byte[] result = this.fula.manifestRemoveStorer(seedString, storage, poolID, cid);
1359
- String resultString = toString(result);
1360
- promise.resolve(resultString);
1361
- } catch (Exception e) {
1362
- Log.d("get", e.getMessage());
1363
- promise.reject(e);
1317
+ throw (e);
1318
+ } catch (Exception ex) {
1319
+ throw new RuntimeException(ex);
1364
1320
  }
1321
+ }
1365
1322
  });
1366
1323
  }
1367
1324
 
1368
1325
  @ReactMethod
1369
- public void removeStoredReplication(String seedString, String uploader, long poolID, String cid, Promise promise) {
1326
+ public void clearCidsFromRecent(ReadableArray cidArray, Promise promise) {
1370
1327
  ThreadUtils.runOnExecutor(() -> {
1371
- Log.d("ReactNative", "removeStoredReplication: seedString = " + seedString + "; uploader = " + uploader + "; poolID = " + poolID + "; cid = " + cid);
1372
- try {
1373
- byte[] result = this.fula.manifestRemoveStored(seedString, uploader, poolID, cid);
1374
- String resultString = toString(result);
1375
- promise.resolve(resultString);
1376
- } catch (Exception e) {
1377
- Log.d("get", e.getMessage());
1378
- promise.reject(e);
1328
+ try {
1329
+ if (this.fula != null) {
1330
+ StringBuilder cidStrBuilder = new StringBuilder();
1331
+ for (int i = 0; i < cidArray.size(); i++) {
1332
+ if (i > 0) {
1333
+ cidStrBuilder.append("|");
1334
+ }
1335
+ cidStrBuilder.append(cidArray.getString(i));
1336
+ }
1337
+
1338
+ byte[] cidsBytes = cidStrBuilder.toString().getBytes(StandardCharsets.UTF_8);
1339
+ this.fula.clearCidsFromRecent(cidsBytes);
1340
+ promise.resolve(true); // Indicate success
1341
+ } else {
1342
+ throw new Exception("clearCidsFromRecent: Fula is not initialized");
1379
1343
  }
1344
+ } catch (Exception e) {
1345
+ Log.d("ReactNative", "clearCidsFromRecent failed with Error: " + e.getMessage());
1346
+ promise.reject("Error", e.getMessage());
1347
+ }
1380
1348
  });
1381
1349
  }
1382
1350
 
1351
+
1383
1352
  ////////////////////////////////////////////////////////////////
1384
1353
  ///////////////// Blox Hardware Methods ////////////////////////
1385
1354
  ////////////////////////////////////////////////////////////////
@@ -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
+ }