@functionland/react-native-fula 1.12.1 → 1.14.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 (39) hide show
  1. package/android/.gradle/7.5.1/checksums/checksums.lock +0 -0
  2. package/android/.gradle/7.5.1/checksums/md5-checksums.bin +0 -0
  3. package/android/.gradle/7.5.1/checksums/sha1-checksums.bin +0 -0
  4. package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
  5. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  6. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  7. package/android/.idea/gradle.xml +1 -1
  8. package/android/.idea/misc.xml +2 -1
  9. package/android/.idea/sonarlint/issuestore/2/a/2afbb999f001938c88fa43fc2ef52abf0f8213e4 +0 -0
  10. package/android/.idea/sonarlint/issuestore/2/e/2e09eb0f0df666781fdff057a0af6101364ebe2f +0 -0
  11. package/android/.idea/sonarlint/issuestore/6/2/62149c3f7c3a14d7a77778e558d274e8c00a5585 +0 -0
  12. package/android/.idea/sonarlint/issuestore/8/0/80a78d662b0659428eb880336106c3c5fc3f0714 +0 -0
  13. package/android/.idea/sonarlint/issuestore/d/2/d2865ef8fc01c40e9fd82977fde2c8378fad0b12 +0 -0
  14. package/android/.idea/sonarlint/issuestore/f/b/fbe448ebfc3eb2d4e308f6b8b043666f5b57235e +0 -0
  15. package/android/.idea/sonarlint/issuestore/index.pb +13 -0
  16. package/android/.idea/sonarlint/securityhotspotstore/2/a/2afbb999f001938c88fa43fc2ef52abf0f8213e4 +0 -0
  17. package/android/.idea/sonarlint/securityhotspotstore/2/e/2e09eb0f0df666781fdff057a0af6101364ebe2f +0 -0
  18. package/android/.idea/sonarlint/securityhotspotstore/6/2/62149c3f7c3a14d7a77778e558d274e8c00a5585 +0 -0
  19. package/android/.idea/sonarlint/securityhotspotstore/8/0/80a78d662b0659428eb880336106c3c5fc3f0714 +0 -0
  20. package/android/.idea/sonarlint/securityhotspotstore/d/2/d2865ef8fc01c40e9fd82977fde2c8378fad0b12 +0 -0
  21. package/android/.idea/sonarlint/securityhotspotstore/f/b/fbe448ebfc3eb2d4e308f6b8b043666f5b57235e +0 -0
  22. package/android/.idea/sonarlint/securityhotspotstore/index.pb +13 -0
  23. package/android/build.gradle +2 -2
  24. package/android/src/main/java/land/fx/fula/Cryptography.java +62 -62
  25. package/android/src/main/java/land/fx/fula/FulaModule.java +33 -11
  26. package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
  27. package/lib/commonjs/protocols/chain-api.js +46 -8
  28. package/lib/commonjs/protocols/chain-api.js.map +1 -1
  29. package/lib/commonjs/protocols/fula.js +98 -98
  30. package/lib/commonjs/protocols/fula.js.map +1 -1
  31. package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
  32. package/lib/module/protocols/chain-api.js +48 -8
  33. package/lib/module/protocols/chain-api.js.map +1 -1
  34. package/lib/module/protocols/fula.js +98 -98
  35. package/lib/module/protocols/fula.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/interfaces/fulaNativeModule.ts +122 -122
  38. package/src/protocols/chain-api.ts +127 -80
  39. package/src/protocols/fula.ts +314 -314
@@ -8,7 +8,7 @@
8
8
  <option name="distributionType" value="DEFAULT_WRAPPED" />
9
9
  <option name="externalProjectPath" value="$PROJECT_DIR$" />
10
10
  <option name="gradleHome" value="$PROJECT_DIR$/../../../../../../Gradle/gradle-7.6" />
11
- <option name="gradleJvm" value="Embedded JDK" />
11
+ <option name="gradleJvm" value="jbr-17" />
12
12
  <option name="modules">
13
13
  <set>
14
14
  <option value="$PROJECT_DIR$" />
@@ -1,6 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
1
2
  <project version="4">
2
3
  <component name="ExternalStorageConfigurationManager" enabled="true" />
3
- <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
4
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
4
5
  <output url="file://$PROJECT_DIR$/build/classes" />
5
6
  </component>
6
7
  <component name="ProjectType">
@@ -0,0 +1,13 @@
1
+
2
+ Y
3
+ )src/main/java/land/fx/fula/ConfigRef.java,d\2\d2865ef8fc01c40e9fd82977fde2c8378fad0b12
4
+ f
5
+ 6src/main/java/land/fx/fula/SharedPreferenceHelper.java,2\e\2e09eb0f0df666781fdff057a0af6101364ebe2f
6
+ [
7
+ +src/main/java/land/fx/fula/FulaPackage.java,6\2\62149c3f7c3a14d7a77778e558d274e8c00a5585
8
+ X
9
+ (gradle/wrapper/gradle-wrapper.properties,f\b\fbe448ebfc3eb2d4e308f6b8b043666f5b57235e
10
+ A
11
+ gradle.properties,2\a\2afbb999f001938c88fa43fc2ef52abf0f8213e4
12
+ \
13
+ ,src/main/java/land/fx/fula/StaticHelper.java,8\0\80a78d662b0659428eb880336106c3c5fc3f0714
@@ -0,0 +1,13 @@
1
+
2
+ Y
3
+ )src/main/java/land/fx/fula/ConfigRef.java,d\2\d2865ef8fc01c40e9fd82977fde2c8378fad0b12
4
+ f
5
+ 6src/main/java/land/fx/fula/SharedPreferenceHelper.java,2\e\2e09eb0f0df666781fdff057a0af6101364ebe2f
6
+ [
7
+ +src/main/java/land/fx/fula/FulaPackage.java,6\2\62149c3f7c3a14d7a77778e558d274e8c00a5585
8
+ X
9
+ (gradle/wrapper/gradle-wrapper.properties,f\b\fbe448ebfc3eb2d4e308f6b8b043666f5b57235e
10
+ A
11
+ gradle.properties,2\a\2afbb999f001938c88fa43fc2ef52abf0f8213e4
12
+ \
13
+ ,src/main/java/land/fx/fula/StaticHelper.java,8\0\80a78d662b0659428eb880336106c3c5fc3f0714
@@ -62,8 +62,8 @@ repositories {
62
62
  dependencies {
63
63
  //noinspection GradleDynamicVersion
64
64
  implementation "com.facebook.react:react-native:+" // From node_modules
65
- implementation 'com.github.functionland:fula-build-aar:1.13.0' // From jitpack.io
66
- implementation 'com.github.functionland:wnfs-android:v1.7.3' // From jitpack.io
65
+ implementation 'com.github.functionland:fula-build-aar:1.13.1' // From jitpack.io
66
+ implementation 'com.github.functionland:wnfs-android:v1.8.0' // From jitpack.io
67
67
  implementation 'commons-io:commons-io:20030203.000550'
68
68
  implementation 'commons-codec:commons-codec:1.15'
69
69
  // implementation files('mobile.aar')
@@ -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
+ }
@@ -26,6 +26,7 @@ import java.security.GeneralSecurityException;
26
26
  import java.security.InvalidAlgorithmParameterException;
27
27
  import java.security.InvalidKeyException;
28
28
  import java.security.NoSuchAlgorithmException;
29
+ import java.security.MessageDigest;
29
30
  import java.util.Arrays;
30
31
  import java.util.ArrayList;
31
32
 
@@ -62,6 +63,8 @@ public class FulaModule extends ReactContextBaseJavaModule {
62
63
 
63
64
  Client client;
64
65
  Config fulaConfig;
66
+
67
+ String appName;
65
68
  String appDir;
66
69
  String fulaStorePath;
67
70
  land.fx.wnfslib.Config rootConfig;
@@ -110,6 +113,7 @@ public class FulaModule extends ReactContextBaseJavaModule {
110
113
 
111
114
  public FulaModule(ReactApplicationContext reactContext) {
112
115
  super(reactContext);
116
+ appName = reactContext.getPackageName();
113
117
  appDir = reactContext.getFilesDir().toString();
114
118
  fulaStorePath = appDir + "/fula";
115
119
  File storeDir = new File(fulaStorePath);
@@ -119,9 +123,9 @@ public class FulaModule extends ReactContextBaseJavaModule {
119
123
  success = storeDir.mkdirs();
120
124
  }
121
125
  if (success) {
122
- Log.d(NAME, "Fula store folder created");
126
+ Log.d("ReactNative", "Fula store folder created for " + appName + " at " + fulaStorePath);
123
127
  } else {
124
- Log.d(NAME, "Unable to create fula store folder!");
128
+ Log.d("ReactNative", "Unable to create fula store folder for " + appName + " at " + fulaStorePath);
125
129
  }
126
130
  }
127
131
 
@@ -503,7 +507,8 @@ public class FulaModule extends ReactContextBaseJavaModule {
503
507
  throw new GeneralSecurityException("Failed to generate key encryption", e);
504
508
  }
505
509
 
506
- if (encryptedLibp2pId == null || !encryptedLibp2pId.startsWith("FULA_ENC_V3:")) {
510
+ if (encryptedLibp2pId == null || !encryptedLibp2pId.startsWith("FULA_" +
511
+ "ENC_V4:")) {
507
512
  Log.d("ReactNative", "encryptedLibp2pId is not correct. creating new one " + encryptedLibp2pId);
508
513
 
509
514
  try {
@@ -512,14 +517,14 @@ public class FulaModule extends ReactContextBaseJavaModule {
512
517
  Log.d("ReactNative", "Failed to generate libp2pId: " + e.getMessage());
513
518
  throw new GeneralSecurityException("Failed to generate libp2pId", e);
514
519
  }
515
- encryptedLibp2pId = "FULA_ENC_V3:" + Cryptography.encryptMsg(StaticHelper.bytesToBase64(libp2pId), encryptionSecretKey, null);
520
+ encryptedLibp2pId = "FULA_ENC_V4:" + Cryptography.encryptMsg(StaticHelper.bytesToBase64(libp2pId), encryptionSecretKey, null);
516
521
  sharedPref.add(PRIVATE_KEY_STORE_PEERID, encryptedLibp2pId);
517
522
  } else {
518
523
  Log.d("ReactNative", "encryptedLibp2pId is correct. decrypting " + encryptedLibp2pId);
519
524
  }
520
525
 
521
526
  try {
522
- String decryptedLibp2pId = Cryptography.decryptMsg(encryptedLibp2pId.replace("FULA_ENC_V3:", ""), encryptionSecretKey);
527
+ String decryptedLibp2pId = Cryptography.decryptMsg(encryptedLibp2pId.replace("FULA_ENC_V4:", ""), encryptionSecretKey);
523
528
 
524
529
  return StaticHelper.base64ToBytes(decryptedLibp2pId);
525
530
  } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException e) {
@@ -534,7 +539,8 @@ public class FulaModule extends ReactContextBaseJavaModule {
534
539
  }
535
540
 
536
541
  private void createNewRootConfig(FulaModule.Client iClient, byte[] identity) throws Exception {
537
- this.rootConfig = Fs.init(iClient, identity);
542
+ byte[] hash32 = getSHA256Hash(identity);
543
+ this.rootConfig = Fs.init(iClient, hash32);
538
544
  Log.d("ReactNative", "rootConfig is created " + this.rootConfig.getCid());
539
545
  if (this.fula != null) {
540
546
  this.fula.flush();
@@ -542,9 +548,24 @@ public class FulaModule extends ReactContextBaseJavaModule {
542
548
  this.encrypt_and_store_config();
543
549
  }
544
550
 
551
+ public static byte[] getSHA256Hash(byte[] input) throws NoSuchAlgorithmException {
552
+ MessageDigest md = MessageDigest.getInstance("SHA-256");
553
+ return md.digest(input);
554
+ }
555
+
556
+ private static String bytesToHex(byte[] bytes) {
557
+ StringBuilder result = new StringBuilder();
558
+ for (byte b : bytes) {
559
+ result.append(String.format("%02x", b));
560
+ }
561
+ return result.toString();
562
+ }
563
+
545
564
  private void reloadFS(FulaModule.Client iClient, byte[] wnfsKey, String rootCid) throws Exception {
546
565
  Log.d("ReactNative", "reloadFS called: rootCid=" + rootCid);
547
- Fs.loadWithWNFSKey(iClient, wnfsKey, rootCid);
566
+ byte[] hash32 = getSHA256Hash(wnfsKey);
567
+ Log.d("ReactNative", "wnfsKey=" + bytesToHex(wnfsKey) + "; hash32 = " + bytesToHex(hash32));
568
+ Fs.loadWithWNFSKey(iClient, hash32, rootCid);
548
569
  Log.d("ReactNative", "reloadFS completed");
549
570
  }
550
571
 
@@ -555,7 +576,7 @@ public class FulaModule extends ReactContextBaseJavaModule {
555
576
 
556
577
  String cid_encrypted = Cryptography.encryptMsg(this.rootConfig.getCid(), this.secretKeyGlobal, null);
557
578
 
558
- sharedPref.add("FULA_ENC_V3:cid_encrypted_" + this.identityEncryptedGlobal, cid_encrypted);
579
+ sharedPref.add("FULA_ENC_V4:cid_encrypted_" + this.identityEncryptedGlobal, cid_encrypted);
559
580
  return true;
560
581
  } else {
561
582
  Log.d("ReactNative", "encrypt_and_store_config failed because identityEncryptedGlobal is empty");
@@ -575,11 +596,11 @@ public class FulaModule extends ReactContextBaseJavaModule {
575
596
  SecretKey secretKey = Cryptography.generateKey(identity);
576
597
  byte[] iv = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B };
577
598
  String identity_encrypted = Cryptography.encryptMsg(Arrays.toString(identity), secretKey, iv);
578
- sharedPref.remove("FULA_ENC_V3:cid_encrypted_"+ identity_encrypted);
599
+ sharedPref.remove("FULA_ENC_V4:cid_encrypted_"+ identity_encrypted);
579
600
 
580
601
  //TODO: Should also remove peerid @Mahdi
581
602
 
582
- sharedPref.remove("FULA_ENC_V3:cid_encrypted_"+ identity_encrypted);
603
+ sharedPref.remove("FULA_ENC_V4:cid_encrypted_"+ identity_encrypted);
583
604
 
584
605
  this.rootConfig = null;
585
606
  this.secretKeyGlobal = null;
@@ -670,7 +691,7 @@ public class FulaModule extends ReactContextBaseJavaModule {
670
691
  Log.d("ReactNative", "this.rootCid is empty.");
671
692
  //Load from keystore
672
693
 
673
- String cid_encrypted_fetched = sharedPref.getValue("FULA_ENC_V3:cid_encrypted_"+ identity_encrypted);
694
+ String cid_encrypted_fetched = sharedPref.getValue("FULA_ENC_V4:cid_encrypted_"+ identity_encrypted);
674
695
  Log.d("ReactNative", "Here1");
675
696
  String cid = "";
676
697
  if(cid_encrypted_fetched != null && !cid_encrypted_fetched.isEmpty()) {
@@ -904,6 +925,7 @@ public class FulaModule extends ReactContextBaseJavaModule {
904
925
  ThreadUtils.runOnExecutor(() -> {
905
926
  Log.d("ReactNative", "readFile: fulaTargetFilename = " + fulaTargetFilename);
906
927
  try {
928
+ Log.d("ReactNative", "readFile: localFilename = " + localFilename + " fulaTargetFilename = " + fulaTargetFilename + " cid = " + this.rootConfig.getCid() + " client = " + this.client);
907
929
  String path = Fs.readFilestreamToPath(this.client, this.rootConfig.getCid(), fulaTargetFilename, localFilename);
908
930
  promise.resolve(path);
909
931
  } catch (Exception e) {
@@ -1 +1 @@
1
- {"version":3,"names":["LINKING_ERROR","Platform","select","ios","default","Fula","NativeModules","FulaModule","Proxy","get","Error"],"sources":["fulaNativeModule.ts"],"sourcesContent":["import { NativeModules, Platform } from 'react-native';\n\ninterface FulaNativeModule {\n init: (\n identity: string, //Private key of did identity\n storePath: string, //You can leave empty\n bloxAddr: string, //Blox multiadddr needs to be manually entered now\n exchange: string, //set to 'noope' for testing\n autoFlush: boolean, //set to false always unless you know what you are doing. This is to write actions to disk explicitly after each write\n rootCid: string | null, //if you have the latest rootCid you can send it and it generates the private_ref for filesystem\n useRelay: boolean | null, // if true it forces the use of relay\n refresh: boolean // if true it forces to refresh the fula object\n ) => Promise<{ peerId: string; rootCid: string }>;\n newClient: (\n identity: string, //Private key of did identity\n storePath: string, //You can leave empty\n bloxAddr: string, //Blox multiadddr needs to be manually entered now\n exchange: string, //set to 'noope' for testing\n autoFlush: boolean, //set to false always unless you know what you are doing. This is to write actions to disk explicitly after each write\n useRelay: boolean | null, // if true it forces the use of relay\n refresh: boolean // if true it forces to refresh the fula object\n ) => Promise<string>;\n isReady: (filesystemCheck: boolean) => Promise<boolean>;\n logout: (identity: string, storePath: string) => Promise<boolean>;\n checkFailedActions: (retry: boolean, timeout: number) => Promise<boolean>;\n listFailedActions: (cids: string[]) => Promise<string[]>;\n checkConnection: (timeout: number) => Promise<boolean>;\n get: (key: string) => Promise<string>;\n has: (key: Uint8Array) => Promise<boolean>;\n push: () => Promise<string>;\n put: (content: string, codec: string) => Promise<string>;\n mkdir: (path: string) => Promise<string>;\n writeFileContent: (path: string, content: string) => Promise<string>;\n writeFile: (\n fulaTargetFilename: string,\n localFilename: string\n ) => Promise<string>;\n ls: (path: string) => Promise<string>;\n rm: (path: string) => Promise<string>;\n cp: (sourcePath: string, targetPath: string) => Promise<string>;\n mv: (sourcePath: string, targetPath: string) => Promise<string>;\n readFile: (\n fulaTargetFilename: string,\n localFilename: string\n ) => Promise<string>;\n readFileContent: (path: string) => Promise<string>;\n setAuth: (peerId: string, allow: boolean) => Promise<boolean>;\n\n shutdown: () => Promise<void>;\n\n testData: (identity: string, bloxAddr: string) => Promise<string>;\n\n //Blockchain related functions\n createAccount: (seed: string) => Promise<string>;\n checkAccountExists: (account: string) => Promise<string>;\n createPool: (seed: string, poolName: string) => Promise<string>;\n listPools: () => Promise<string>;\n joinPool: (seed: string, poolID: number) => Promise<string>;\n leavePool: (seed: string, poolID: number) => Promise<string>;\n cancelPoolJoin: (seed: string, poolID: number) => Promise<string>;\n listPoolJoinRequests: (poolID: number) => Promise<string>;\n votePoolJoinRequest: (\n seed: string,\n poolID: number,\n account: string,\n accept: boolean\n ) => Promise<string>;\n newReplicationRequest: (\n seed: string,\n poolID: number,\n replicationFactor: number,\n cid: string\n ) => Promise<string>;\n newStoreRequest: (\n seed: string,\n poolID: number,\n uploader: string,\n cid: string\n ) => Promise<string>;\n listAvailableReplicationRequests: (poolID: number) => Promise<string>;\n removeReplicationRequest: (\n seed: string,\n poolID: number,\n cid: string\n ) => Promise<string>;\n removeStorer: (\n seed: string,\n storer: string,\n poolID: number,\n cid: string\n ) => Promise<string>;\n removeStoredReplication: (\n seed: string,\n uploader: string,\n poolID: number,\n cid: string\n ) => Promise<string>;\n\n //Hardware\n bloxFreeSpace: () => Promise<string>;\n wifiRemoveall: () => Promise<string>;\n reboot: () => Promise<string>;\n}\n\nconst LINKING_ERROR =\n `The package 'react-native-fula/Fula' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\nconst Fula = NativeModules.FulaModule\n ? NativeModules.FulaModule\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\nexport default Fula as FulaNativeModule;\n"],"mappings":";;;;;;AAAA;AAwGA,MAAMA,aAAa,GAChB,iFAAgF,GACjFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,6CAA6C;AAE/C,MAAMC,IAAI,GAAGC,0BAAa,CAACC,UAAU,GACjCD,0BAAa,CAACC,UAAU,GACxB,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAG,GAAG;IACJ,MAAM,IAAIC,KAAK,CAACV,aAAa,CAAC;EAChC;AACF,CAAC,CACF;AAAC,eAESK,IAAI;AAAA"}
1
+ {"version":3,"names":["LINKING_ERROR","Platform","select","ios","default","Fula","NativeModules","FulaModule","Proxy","get","Error"],"sources":["fulaNativeModule.ts"],"sourcesContent":["import { NativeModules, Platform } from 'react-native';\r\n\r\ninterface FulaNativeModule {\r\n init: (\r\n identity: string, //Private key of did identity\r\n storePath: string, //You can leave empty\r\n bloxAddr: string, //Blox multiadddr needs to be manually entered now\r\n exchange: string, //set to 'noope' for testing\r\n autoFlush: boolean, //set to false always unless you know what you are doing. This is to write actions to disk explicitly after each write\r\n rootCid: string | null, //if you have the latest rootCid you can send it and it generates the private_ref for filesystem\r\n useRelay: boolean | null, // if true it forces the use of relay\r\n refresh: boolean // if true it forces to refresh the fula object\r\n ) => Promise<{ peerId: string; rootCid: string }>;\r\n newClient: (\r\n identity: string, //Private key of did identity\r\n storePath: string, //You can leave empty\r\n bloxAddr: string, //Blox multiadddr needs to be manually entered now\r\n exchange: string, //set to 'noope' for testing\r\n autoFlush: boolean, //set to false always unless you know what you are doing. This is to write actions to disk explicitly after each write\r\n useRelay: boolean | null, // if true it forces the use of relay\r\n refresh: boolean // if true it forces to refresh the fula object\r\n ) => Promise<string>;\r\n isReady: (filesystemCheck: boolean) => Promise<boolean>;\r\n logout: (identity: string, storePath: string) => Promise<boolean>;\r\n checkFailedActions: (retry: boolean, timeout: number) => Promise<boolean>;\r\n listFailedActions: (cids: string[]) => Promise<string[]>;\r\n checkConnection: (timeout: number) => Promise<boolean>;\r\n get: (key: string) => Promise<string>;\r\n has: (key: Uint8Array) => Promise<boolean>;\r\n push: () => Promise<string>;\r\n put: (content: string, codec: string) => Promise<string>;\r\n mkdir: (path: string) => Promise<string>;\r\n writeFileContent: (path: string, content: string) => Promise<string>;\r\n writeFile: (\r\n fulaTargetFilename: string,\r\n localFilename: string\r\n ) => Promise<string>;\r\n ls: (path: string) => Promise<string>;\r\n rm: (path: string) => Promise<string>;\r\n cp: (sourcePath: string, targetPath: string) => Promise<string>;\r\n mv: (sourcePath: string, targetPath: string) => Promise<string>;\r\n readFile: (\r\n fulaTargetFilename: string,\r\n localFilename: string\r\n ) => Promise<string>;\r\n readFileContent: (path: string) => Promise<string>;\r\n setAuth: (peerId: string, allow: boolean) => Promise<boolean>;\r\n\r\n shutdown: () => Promise<void>;\r\n\r\n testData: (identity: string, bloxAddr: string) => Promise<string>;\r\n\r\n //Blockchain related functions\r\n createAccount: (seed: string) => Promise<string>;\r\n checkAccountExists: (account: string) => Promise<string>;\r\n createPool: (seed: string, poolName: string) => Promise<string>;\r\n listPools: () => Promise<string>;\r\n joinPool: (seed: string, poolID: number) => Promise<string>;\r\n leavePool: (seed: string, poolID: number) => Promise<string>;\r\n cancelPoolJoin: (seed: string, poolID: number) => Promise<string>;\r\n listPoolJoinRequests: (poolID: number) => Promise<string>;\r\n votePoolJoinRequest: (\r\n seed: string,\r\n poolID: number,\r\n account: string,\r\n accept: boolean\r\n ) => Promise<string>;\r\n newReplicationRequest: (\r\n seed: string,\r\n poolID: number,\r\n replicationFactor: number,\r\n cid: string\r\n ) => Promise<string>;\r\n newStoreRequest: (\r\n seed: string,\r\n poolID: number,\r\n uploader: string,\r\n cid: string\r\n ) => Promise<string>;\r\n listAvailableReplicationRequests: (poolID: number) => Promise<string>;\r\n removeReplicationRequest: (\r\n seed: string,\r\n poolID: number,\r\n cid: string\r\n ) => Promise<string>;\r\n removeStorer: (\r\n seed: string,\r\n storer: string,\r\n poolID: number,\r\n cid: string\r\n ) => Promise<string>;\r\n removeStoredReplication: (\r\n seed: string,\r\n uploader: string,\r\n poolID: number,\r\n cid: string\r\n ) => Promise<string>;\r\n\r\n //Hardware\r\n bloxFreeSpace: () => Promise<string>;\r\n wifiRemoveall: () => Promise<string>;\r\n reboot: () => Promise<string>;\r\n}\r\n\r\nconst LINKING_ERROR =\r\n `The package 'react-native-fula/Fula' doesn't seem to be linked. Make sure: \\n\\n` +\r\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\r\n '- You rebuilt the app after installing the package\\n' +\r\n '- You are not using Expo managed workflow\\n';\r\n\r\nconst Fula = NativeModules.FulaModule\r\n ? NativeModules.FulaModule\r\n : new Proxy(\r\n {},\r\n {\r\n get() {\r\n throw new Error(LINKING_ERROR);\r\n },\r\n }\r\n );\r\n\r\nexport default Fula as FulaNativeModule;\r\n"],"mappings":";;;;;;AAAA;AAwGA,MAAMA,aAAa,GAChB,iFAAgF,GACjFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,6CAA6C;AAE/C,MAAMC,IAAI,GAAGC,0BAAa,CAACC,UAAU,GACjCD,0BAAa,CAACC,UAAU,GACxB,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAG,GAAG;IACJ,MAAM,IAAIC,KAAK,CAACV,aAAa,CAAC;EAChC;AACF,CAAC,CACF;AAAC,eAESK,IAAI;AAAA"}
@@ -11,7 +11,7 @@ const types = {
11
11
  FulaPoolPool: _apiLookup.default.FulaPoolPool
12
12
  };
13
13
  const init = async function () {
14
- let wsAddress = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'wss://node.testnet.fx.land';
14
+ let wsAddress = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'wss://node3.functionyard.fx.land';
15
15
  const provider = new _api.WsProvider(wsAddress);
16
16
  const api = await _api.ApiPromise.create({
17
17
  types,
@@ -27,8 +27,46 @@ const disconnectApi = async api => {
27
27
  await api.disconnect();
28
28
  };
29
29
 
30
- /*
31
- listPools: This function takes start index and length and returns a promise of an object that contains a list of pools. Each pool in the list contains the poolID, owner, poolName, parent, and participants of the pool
30
+ /*
31
+ createAccount: This function takes a seed and returns am account
32
+ */
33
+ /*export const uploadManifest = async (
34
+ api: ApiPromise | undefined,
35
+ seed: string,
36
+ manifest: typeof EventTypes.FunctionlandFulaCall._enum.upload_manifest
37
+ ): Promise<BType.ManifestUploadResponse> => {
38
+ console.log('uploadManifest in react-native started');
39
+ try {
40
+ if (api === undefined) {
41
+ api = await init();
42
+ }
43
+
44
+ // Simple transaction
45
+ const keyring = new Keyring({ type: 'sr25519' });
46
+ const userKey = keyring.addFromUri(seed, { name: 'account' });
47
+ console.log(
48
+ `${userKey.meta.name}: has address ${userKey.address} with publicKey [${userKey.publicKey}]`
49
+ );
50
+ const submitExtrinsic = await api.tx.manifest.upload(manifest);
51
+ const unsub = await submitExtrinsic
52
+ .signAndSend(userKey, ({ status, events }) => {
53
+ if (status.isInBlock || status.isFinalized) {
54
+ console.log(events);
55
+ unsub();
56
+ return Promise.resolve({ success: true });
57
+ }
58
+ })
59
+ .catch((error) => {
60
+ console.log(':( transaction failed', error);
61
+ return Promise.reject(error);
62
+ });
63
+ } catch (err) {
64
+ return Promise.reject(err);
65
+ }
66
+ };*/
67
+
68
+ /*
69
+ listPools: This function takes start index and length and returns a promise of an object that contains a list of pools. Each pool in the list contains the poolID, owner, poolName, parent, and participants of the pool
32
70
  */
33
71
  exports.disconnectApi = disconnectApi;
34
72
  const listPools = async function (api) {
@@ -36,7 +74,7 @@ const listPools = async function (api) {
36
74
  let length = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
37
75
  console.log('listPools in react-native started');
38
76
  try {
39
- if (api == undefined) {
77
+ if (api === undefined) {
40
78
  api = await init();
41
79
  }
42
80
  const pools = {
@@ -63,14 +101,14 @@ const listPools = async function (api) {
63
101
  }
64
102
  };
65
103
 
66
- /*
67
- checkJoinRequest: This function takes poolId and AccontId and returns a promise of an object that contains request to the pools.
68
- */
104
+ /*
105
+ checkJoinRequest: This function takes poolId and AccontId and returns a promise of an object that contains request to the pools.
106
+ */
69
107
  exports.listPools = listPools;
70
108
  const checkJoinRequest = async (api, poolId, accountId) => {
71
109
  console.log('checkJoinRequest in react-native started');
72
110
  try {
73
- if (api == undefined) {
111
+ if (api === undefined) {
74
112
  api = await init();
75
113
  }
76
114
  const poolRequest = await api.query.pool.poolRequests(poolId, accountId);
@@ -1 +1 @@
1
- {"version":3,"names":["types","FulaPoolPool","EventTypes","init","wsAddress","provider","WsProvider","api","ApiPromise","create","catch","err","console","log","Promise","reject","disconnectApi","disconnect","listPools","start","length","undefined","pools","lastPoolId","query","pool","finalReturnedId","Number","toHuman","i","poolInfo","formattedPoolInfo","JSON","parse","stringify","push","resolve","checkJoinRequest","poolId","accountId","poolRequest","poolRequests","formattedPoolRequest"],"sources":["chain-api.ts"],"sourcesContent":["import { default as EventTypes } from '../interfaces/api-lookup';\r\n\r\nimport { ApiPromise, WsProvider } from '@polkadot/api';\r\nimport type * as BType from '../types/blockchain';\r\n\r\n const types = {\r\n FulaPoolPool: EventTypes.FulaPoolPool,\r\n }\r\n\r\n export const init = async (wsAddress: string = 'wss://node.testnet.fx.land'): Promise<ApiPromise> => {\r\n const provider = new WsProvider(wsAddress);\r\n const api = await ApiPromise.create({ types, provider }).catch((err) => {\r\n console.log(err);\r\n return Promise.reject(err);\r\n });\r\n return api;\r\n };\r\n\r\n export const disconnectApi = async (api: ApiPromise): Promise<void> => {\r\n await api.disconnect();\r\n };\r\n\r\n/*\r\n listPools: This function takes start index and length and returns a promise of an object that contains a list of pools. Each pool in the list contains the poolID, owner, poolName, parent, and participants of the pool\r\n */\r\n export const listPools = async (api: ApiPromise|undefined, start: number=1, length: number=10): Promise<BType.PoolListResponse> => {\r\n console.log(\r\n 'listPools in react-native started'\r\n );\r\n try {\r\n if(api == undefined) {\r\n api = await init();\r\n }\r\n const pools: BType.PoolListResponse = { pools: [] };\r\n const lastPoolId = await api.query.pool.lastPoolId();\r\n let finalReturnedId: number = Number(lastPoolId.toHuman());\r\n if (Number(lastPoolId.toHuman()) > start + length) {\r\n finalReturnedId = start + length;\r\n }\r\n for(let i=start; i<=finalReturnedId;i++) {\r\n const poolInfo = await api.query.pool\r\n .pools(i).catch((err) => {\r\n console.log(err);\r\n return Promise.reject(err);\r\n });\r\n if(poolInfo != null) {\r\n let formattedPoolInfo: BType.Pool = JSON.parse(JSON.stringify(poolInfo.toHuman()));\r\n pools.pools.push(formattedPoolInfo);\r\n }\r\n }\r\n return Promise.resolve(pools);\r\n } catch (err) {\r\n return Promise.reject(err);\r\n }\r\n }\r\n\r\n /*\r\n checkJoinRequest: This function takes poolId and AccontId and returns a promise of an object that contains request to the pools.\r\n */\r\n export const checkJoinRequest = async (api: ApiPromise|undefined, poolId: number, accountId: string): Promise<BType.PoolRequest|null> => {\r\n console.log(\r\n 'checkJoinRequest in react-native started'\r\n );\r\n try {\r\n if(api == undefined) {\r\n api = await init();\r\n }\r\n\r\n const poolRequest = await api.query.pool.poolRequests(poolId, accountId);\r\n\r\n if(poolRequest != null) {\r\n let formattedPoolRequest: BType.PoolRequest = JSON.parse(JSON.stringify(poolRequest.toHuman()));\r\n return Promise.resolve(formattedPoolRequest);\r\n }\r\n return Promise.resolve(null);\r\n \r\n } catch (err) {\r\n return Promise.reject(err);\r\n }\r\n }"],"mappings":";;;;;;AAAA;AAEA;AAAuD;AAGnD,MAAMA,KAAK,GAAG;EACVC,YAAY,EAAEC,kBAAU,CAACD;AAC7B,CAAC;AAEM,MAAME,IAAI,GAAG,kBAAiF;EAAA,IAA1EC,SAAiB,uEAAG,4BAA4B;EACvE,MAAMC,QAAQ,GAAG,IAAIC,eAAU,CAACF,SAAS,CAAC;EAC1C,MAAMG,GAAG,GAAG,MAAMC,eAAU,CAACC,MAAM,CAAC;IAAET,KAAK;IAAEK;EAAS,CAAC,CAAC,CAACK,KAAK,CAAEC,GAAG,IAAK;IACpEC,OAAO,CAACC,GAAG,CAACF,GAAG,CAAC;IAChB,OAAOG,OAAO,CAACC,MAAM,CAACJ,GAAG,CAAC;EAC9B,CAAC,CAAC;EACF,OAAOJ,GAAG;AACd,CAAC;AAAC;AAEK,MAAMS,aAAa,GAAG,MAAOT,GAAe,IAAoB;EACnE,MAAMA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AAO,CAACsB,OAAO,CAACd,KAAK,CAAC;EACjC,CAAC,CAAC,OAAOX,GAAG,EAAE;IACV,OAAOG,OAAO,CAACC,MAAM,CAACJ,GAAG,CAAC;EAC9B;AACF,CAAC;;AAED;AACF;AACA;AAFE;AAGO,MAAM0B,gBAAgB,GAAG,OAAO9B,GAAyB,EAAE+B,MAAc,EAAEC,SAAiB,KAAsC;EACvI3B,OAAO,CAACC,GAAG,CACP,0CAA0C,CAC7C;EACD,IAAI;IACA,IAAGN,GAAG,IAAIc,SAAS,EAAE;MACjBd,GAAG,GAAG,MAAMJ,IAAI,EAAE;IACtB;IAEA,MAAMqC,WAAW,GAAG,MAAMjC,GAAG,CAACiB,KAAK,CAACC,IAAI,CAACgB,YAAY,CAACH,MAAM,EAAEC,SAAS,CAAC;IAExE,IAAGC,WAAW,IAAI,IAAI,EAAE;MACpB,IAAIE,oBAAuC,GAAGV,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,SAAS,CAACM,WAAW,CAACZ,OAAO,EAAE,CAAC,CAAC;MAC/F,OAAOd,OAAO,CAACsB,OAAO,CAACM,oBAAoB,CAAC;IAChD;IACA,OAAO5B,OAAO,CAACsB,OAAO,CAAC,IAAI,CAAC;EAEhC,CAAC,CAAC,OAAOzB,GAAG,EAAE;IACV,OAAOG,OAAO,CAACC,MAAM,CAACJ,GAAG,CAAC;EAC9B;AACF,CAAC;AAAA"}
1
+ {"version":3,"names":["types","FulaPoolPool","EventTypes","init","wsAddress","provider","WsProvider","api","ApiPromise","create","catch","err","console","log","Promise","reject","disconnectApi","disconnect","listPools","start","length","undefined","pools","lastPoolId","query","pool","finalReturnedId","Number","toHuman","i","poolInfo","formattedPoolInfo","JSON","parse","stringify","push","resolve","checkJoinRequest","poolId","accountId","poolRequest","poolRequests","formattedPoolRequest"],"sources":["chain-api.ts"],"sourcesContent":["import { default as EventTypes } from '../interfaces/api-lookup';\n\nimport { ApiPromise, WsProvider } from '@polkadot/api';\n//import { Keyring } from '@polkadot/keyring';\nimport type * as BType from '../types/blockchain';\n\nconst types = {\n FulaPoolPool: EventTypes.FulaPoolPool,\n};\n\nexport const init = async (\n wsAddress: string = 'wss://node3.functionyard.fx.land'\n): Promise<ApiPromise> => {\n const provider = new WsProvider(wsAddress);\n const api = await ApiPromise.create({ types, provider }).catch((err) => {\n console.log(err);\n return Promise.reject(err);\n });\n return api;\n};\n\nexport const disconnectApi = async (api: ApiPromise): Promise<void> => {\n await api.disconnect();\n};\n\n/*\n createAccount: This function takes a seed and returns am account\n*/\n/*export const uploadManifest = async (\n api: ApiPromise | undefined,\n seed: string,\n manifest: typeof EventTypes.FunctionlandFulaCall._enum.upload_manifest\n): Promise<BType.ManifestUploadResponse> => {\n console.log('uploadManifest in react-native started');\n try {\n if (api === undefined) {\n api = await init();\n }\n\n // Simple transaction\n const keyring = new Keyring({ type: 'sr25519' });\n const userKey = keyring.addFromUri(seed, { name: 'account' });\n console.log(\n `${userKey.meta.name}: has address ${userKey.address} with publicKey [${userKey.publicKey}]`\n );\n const submitExtrinsic = await api.tx.manifest.upload(manifest);\n const unsub = await submitExtrinsic\n .signAndSend(userKey, ({ status, events }) => {\n if (status.isInBlock || status.isFinalized) {\n console.log(events);\n unsub();\n return Promise.resolve({ success: true });\n }\n })\n .catch((error) => {\n console.log(':( transaction failed', error);\n return Promise.reject(error);\n });\n } catch (err) {\n return Promise.reject(err);\n }\n};*/\n\n/*\n listPools: This function takes start index and length and returns a promise of an object that contains a list of pools. Each pool in the list contains the poolID, owner, poolName, parent, and participants of the pool\n */\nexport const listPools = async (\n api: ApiPromise | undefined,\n start: number = 1,\n length: number = 10\n): Promise<BType.PoolListResponse> => {\n console.log('listPools in react-native started');\n try {\n if (api === undefined) {\n api = await init();\n }\n const pools: BType.PoolListResponse = { pools: [] };\n const lastPoolId = await api.query.pool.lastPoolId();\n let finalReturnedId: number = Number(lastPoolId.toHuman());\n if (Number(lastPoolId.toHuman()) > start + length) {\n finalReturnedId = start + length;\n }\n for (let i = start; i <= finalReturnedId; i++) {\n const poolInfo = await api.query.pool.pools(i).catch((err) => {\n console.log(err);\n return Promise.reject(err);\n });\n if (poolInfo != null) {\n let formattedPoolInfo: BType.Pool = JSON.parse(\n JSON.stringify(poolInfo.toHuman())\n );\n pools.pools.push(formattedPoolInfo);\n }\n }\n return Promise.resolve(pools);\n } catch (err) {\n return Promise.reject(err);\n }\n};\n\n/*\n checkJoinRequest: This function takes poolId and AccontId and returns a promise of an object that contains request to the pools.\n */\nexport const checkJoinRequest = async (\n api: ApiPromise | undefined,\n poolId: number,\n accountId: string\n): Promise<BType.PoolRequest | null> => {\n console.log('checkJoinRequest in react-native started');\n try {\n if (api === undefined) {\n api = await init();\n }\n\n const poolRequest = await api.query.pool.poolRequests(poolId, accountId);\n\n if (poolRequest != null) {\n let formattedPoolRequest: BType.PoolRequest = JSON.parse(\n JSON.stringify(poolRequest.toHuman())\n );\n return Promise.resolve(formattedPoolRequest);\n }\n return Promise.resolve(null);\n } catch (err) {\n return Promise.reject(err);\n }\n};\n"],"mappings":";;;;;;AAAA;AAEA;AAAuD;AAIvD,MAAMA,KAAK,GAAG;EACZC,YAAY,EAAEC,kBAAU,CAACD;AAC3B,CAAC;AAEM,MAAME,IAAI,GAAG,kBAEM;EAAA,IADxBC,SAAiB,uEAAG,kCAAkC;EAEtD,MAAMC,QAAQ,GAAG,IAAIC,eAAU,CAACF,SAAS,CAAC;EAC1C,MAAMG,GAAG,GAAG,MAAMC,eAAU,CAACC,MAAM,CAAC;IAAET,KAAK;IAAEK;EAAS,CAAC,CAAC,CAACK,KAAK,CAAEC,GAAG,IAAK;IACtEC,OAAO,CAACC,GAAG,CAACF,GAAG,CAAC;IAChB,OAAOG,OAAO,CAACC,MAAM,CAACJ,GAAG,CAAC;EAC5B,CAAC,CAAC;EACF,OAAOJ,GAAG;AACZ,CAAC;AAAC;AAEK,MAAMS,aAAa,GAAG,MAAOT,GAAe,IAAoB;EACrE,MAAMA,GAAG,CAACU,UAAU,EAAE;AACxB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