@functionland/react-native-fula 1.14.1 → 1.14.4

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 (135) hide show
  1. package/LICENSE +20 -21
  2. package/android/build.gradle +90 -50
  3. package/android/gradle.properties +5 -1
  4. package/android/src/main/AndroidManifest.xml +3 -4
  5. package/android/src/main/AndroidManifestNew.xml +2 -0
  6. package/android/src/main/java/land/fx/fula/ConfigRef.java +7 -7
  7. package/android/src/main/java/land/fx/fula/Cryptography.java +62 -62
  8. package/android/src/main/java/land/fx/fula/FulaModule.java +1 -1
  9. package/android/src/main/java/land/fx/fula/FulaPackage.java +32 -32
  10. package/android/src/main/java/land/fx/fula/SharedPreferenceHelper.java +65 -65
  11. package/android/src/main/java/land/fx/fula/StaticHelper.java +13 -13
  12. package/android/src/main/java/land/fx/fula/ThreadUtils.java +42 -42
  13. package/ios/Cryptography.swift +36 -0
  14. package/ios/Fula-Bridging-Header.h +3 -0
  15. package/ios/Fula.mm +199 -0
  16. package/ios/Fula.swift +1152 -0
  17. package/ios/{FulaModule.xcodeproj → Fula.xcodeproj}/project.pbxproj +38 -16
  18. package/ios/Fula.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  19. package/ios/Fula.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  20. package/ios/Fula.xcodeproj/project.xcworkspace/xcuserdata/user246549.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  21. package/ios/Fula.xcodeproj/xcuserdata/user246549.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  22. package/ios/UserDataHelper.swift +143 -0
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/commonjs/interfaces/api-lookup.js +266 -266
  25. package/lib/commonjs/interfaces/api-lookup.js.map +1 -1
  26. package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
  27. package/lib/commonjs/protocols/blockchain.js +64 -64
  28. package/lib/commonjs/protocols/blockchain.js.map +1 -1
  29. package/lib/commonjs/protocols/chain-api.js +10 -0
  30. package/lib/commonjs/protocols/chain-api.js.map +1 -1
  31. package/lib/commonjs/protocols/fula.js +99 -99
  32. package/lib/commonjs/protocols/fula.js.map +1 -1
  33. package/lib/commonjs/protocols/fxblox.js +3 -3
  34. package/lib/commonjs/protocols/fxblox.js.map +1 -1
  35. package/lib/commonjs/types/blockchain.js.map +1 -1
  36. package/lib/commonjs/types/fxblox.js.map +1 -1
  37. package/lib/module/index.js +4 -8
  38. package/lib/module/index.js.map +1 -1
  39. package/lib/module/interfaces/api-lookup.js +266 -266
  40. package/lib/module/interfaces/api-lookup.js.map +1 -1
  41. package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
  42. package/lib/module/protocols/blockchain.js +64 -64
  43. package/lib/module/protocols/blockchain.js.map +1 -1
  44. package/lib/module/protocols/chain-api.js +8 -0
  45. package/lib/module/protocols/chain-api.js.map +1 -1
  46. package/lib/module/protocols/fula.js +99 -99
  47. package/lib/module/protocols/fula.js.map +1 -1
  48. package/lib/module/protocols/fxblox.js +3 -3
  49. package/lib/module/protocols/fxblox.js.map +1 -1
  50. package/lib/module/types/blockchain.js.map +1 -1
  51. package/lib/module/types/fxblox.js.map +1 -1
  52. package/lib/typescript/index.d.ts +5 -4
  53. package/lib/typescript/index.d.ts.map +1 -0
  54. package/lib/typescript/interfaces/api-lookup.d.ts +1644 -1643
  55. package/lib/typescript/interfaces/api-lookup.d.ts.map +1 -0
  56. package/lib/typescript/interfaces/fulaNativeModule.d.ts +62 -61
  57. package/lib/typescript/interfaces/fulaNativeModule.d.ts.map +1 -0
  58. package/lib/typescript/protocols/blockchain.d.ts +18 -17
  59. package/lib/typescript/protocols/blockchain.d.ts.map +1 -0
  60. package/lib/typescript/protocols/chain-api.d.ts +7 -6
  61. package/lib/typescript/protocols/chain-api.d.ts.map +1 -0
  62. package/lib/typescript/protocols/fula.d.ts +132 -131
  63. package/lib/typescript/protocols/fula.d.ts.map +1 -0
  64. package/lib/typescript/protocols/fxblox.d.ts +8 -7
  65. package/lib/typescript/protocols/fxblox.d.ts.map +1 -0
  66. package/lib/typescript/types/blockchain.d.ts +69 -68
  67. package/lib/typescript/types/blockchain.d.ts.map +1 -0
  68. package/lib/typescript/types/fxblox.d.ts +9 -8
  69. package/lib/typescript/types/fxblox.d.ts.map +1 -0
  70. package/package.json +43 -28
  71. package/react-native-fula.podspec +47 -19
  72. package/src/index.tsx +4 -4
  73. package/src/interfaces/api-lookup.ts +1647 -1647
  74. package/src/interfaces/fulaNativeModule.ts +122 -122
  75. package/src/protocols/blockchain.ts +504 -504
  76. package/src/protocols/chain-api.ts +8 -0
  77. package/src/protocols/fula.ts +314 -314
  78. package/src/protocols/fxblox.ts +49 -49
  79. package/src/types/blockchain.ts +80 -80
  80. package/src/types/fxblox.ts +8 -8
  81. package/android/.gradle/7.5.1/checksums/checksums.lock +0 -0
  82. package/android/.gradle/7.5.1/checksums/md5-checksums.bin +0 -0
  83. package/android/.gradle/7.5.1/checksums/sha1-checksums.bin +0 -0
  84. package/android/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  85. package/android/.gradle/7.5.1/dependencies-accessors/gc.properties +0 -0
  86. package/android/.gradle/7.5.1/executionHistory/executionHistory.bin +0 -0
  87. package/android/.gradle/7.5.1/executionHistory/executionHistory.lock +0 -0
  88. package/android/.gradle/7.5.1/fileChanges/last-build.bin +0 -0
  89. package/android/.gradle/7.5.1/fileHashes/fileHashes.bin +0 -0
  90. package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
  91. package/android/.gradle/7.5.1/fileHashes/resourceHashesCache.bin +0 -0
  92. package/android/.gradle/7.5.1/gc.properties +0 -0
  93. package/android/.gradle/7.6/checksums/checksums.lock +0 -0
  94. package/android/.gradle/7.6/checksums/md5-checksums.bin +0 -0
  95. package/android/.gradle/7.6/checksums/sha1-checksums.bin +0 -0
  96. package/android/.gradle/7.6/dependencies-accessors/dependencies-accessors.lock +0 -0
  97. package/android/.gradle/7.6/dependencies-accessors/gc.properties +0 -0
  98. package/android/.gradle/7.6/executionHistory/executionHistory.bin +0 -0
  99. package/android/.gradle/7.6/executionHistory/executionHistory.lock +0 -0
  100. package/android/.gradle/7.6/fileChanges/last-build.bin +0 -0
  101. package/android/.gradle/7.6/fileHashes/fileHashes.bin +0 -0
  102. package/android/.gradle/7.6/fileHashes/fileHashes.lock +0 -0
  103. package/android/.gradle/7.6/fileHashes/resourceHashesCache.bin +0 -0
  104. package/android/.gradle/7.6/gc.properties +0 -0
  105. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  106. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  107. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  108. package/android/.gradle/file-system.probe +0 -0
  109. package/android/.gradle/vcs-1/gc.properties +0 -0
  110. package/android/.idea/compiler.xml +0 -6
  111. package/android/.idea/gradle.xml +0 -20
  112. package/android/.idea/jarRepositories.xml +0 -50
  113. package/android/.idea/misc.xml +0 -10
  114. package/android/.idea/sonarlint/issuestore/2/a/2afbb999f001938c88fa43fc2ef52abf0f8213e4 +0 -0
  115. package/android/.idea/sonarlint/issuestore/2/e/2e09eb0f0df666781fdff057a0af6101364ebe2f +0 -0
  116. package/android/.idea/sonarlint/issuestore/6/2/62149c3f7c3a14d7a77778e558d274e8c00a5585 +0 -0
  117. package/android/.idea/sonarlint/issuestore/8/0/80a78d662b0659428eb880336106c3c5fc3f0714 +0 -0
  118. package/android/.idea/sonarlint/issuestore/d/2/d2865ef8fc01c40e9fd82977fde2c8378fad0b12 +0 -0
  119. package/android/.idea/sonarlint/issuestore/f/b/fbe448ebfc3eb2d4e308f6b8b043666f5b57235e +0 -0
  120. package/android/.idea/sonarlint/issuestore/index.pb +0 -13
  121. package/android/.idea/sonarlint/securityhotspotstore/2/a/2afbb999f001938c88fa43fc2ef52abf0f8213e4 +0 -0
  122. package/android/.idea/sonarlint/securityhotspotstore/2/e/2e09eb0f0df666781fdff057a0af6101364ebe2f +0 -0
  123. package/android/.idea/sonarlint/securityhotspotstore/6/2/62149c3f7c3a14d7a77778e558d274e8c00a5585 +0 -0
  124. package/android/.idea/sonarlint/securityhotspotstore/8/0/80a78d662b0659428eb880336106c3c5fc3f0714 +0 -0
  125. package/android/.idea/sonarlint/securityhotspotstore/d/2/d2865ef8fc01c40e9fd82977fde2c8378fad0b12 +0 -0
  126. package/android/.idea/sonarlint/securityhotspotstore/f/b/fbe448ebfc3eb2d4e308f6b8b043666f5b57235e +0 -0
  127. package/android/.idea/sonarlint/securityhotspotstore/index.pb +0 -13
  128. package/android/.idea/vcs.xml +0 -6
  129. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  130. package/android/gradle/wrapper/gradle-wrapper.properties +0 -7
  131. package/android/gradlew +0 -291
  132. package/android/gradlew.bat +0 -91
  133. package/android/local.properties +0 -8
  134. package/ios/FulaModule.h +0 -10
  135. package/ios/FulaModule.m +0 -149
package/LICENSE CHANGED
@@ -1,21 +1,20 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 Mahdi Ghorbani
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Ehsan Shariati <ehsan6sha@gmail.com> (https://github.com/ehsan6sha)
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
@@ -1,70 +1,110 @@
1
1
  buildscript {
2
- if (project == rootProject) {
3
- repositories {
4
- google()
5
- mavenCentral()
6
- jcenter()
7
- }
8
-
9
- dependencies {
10
- classpath 'com.android.tools.build:gradle:4.2.2'
11
- }
12
- }
2
+ repositories {
3
+ google()
4
+ mavenCentral()
5
+ }
6
+
7
+ dependencies {
8
+ classpath "com.android.tools.build:gradle:7.2.1"
9
+ }
10
+ }
11
+
12
+ def isNewArchitectureEnabled() {
13
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
14
+ }
15
+
16
+ apply plugin: "com.android.library"
17
+
18
+
19
+ def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
20
+
21
+ if (isNewArchitectureEnabled()) {
22
+ apply plugin: "com.facebook.react"
23
+ }
24
+
25
+ def getExtOrDefault(name) {
26
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Fula_" + name]
27
+ }
28
+
29
+ def getExtOrIntegerDefault(name) {
30
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Fula_" + name]).toInteger()
13
31
  }
14
32
 
15
- apply plugin: 'com.android.library'
33
+ def supportsNamespace() {
34
+ def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
35
+ def major = parsed[0].toInteger()
36
+ def minor = parsed[1].toInteger()
16
37
 
17
- def safeExtGet(prop, fallback) {
18
- rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
38
+ // Namespace support was added in 7.3.0
39
+ if (major == 7 && minor >= 3) {
40
+ return true
41
+ }
42
+
43
+ return major >= 8
19
44
  }
20
45
 
21
46
  android {
22
- compileSdk 33
23
- defaultConfig {
24
- minSdkVersion safeExtGet('Fula_minSdkVersion', 26)
25
- targetSdkVersion safeExtGet('Fula_targetSdkVersion', 31)
26
- versionCode 1
27
- versionName "1.0"
47
+ if (supportsNamespace()) {
48
+ namespace "land.fx.fula"
28
49
 
50
+ sourceSets {
51
+ main {
52
+ manifest.srcFile "src/main/AndroidManifestNew.xml"
53
+ }
29
54
  }
55
+ }
30
56
 
31
- buildTypes {
32
- release {
33
- minifyEnabled false
34
- }
35
- }
36
- lintOptions {
37
- disable 'GradleCompatible'
38
- }
39
- compileOptions {
40
- sourceCompatibility JavaVersion.VERSION_1_8
41
- targetCompatibility JavaVersion.VERSION_1_8
57
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
58
+
59
+ defaultConfig {
60
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
61
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
62
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
63
+ }
64
+ buildTypes {
65
+ release {
66
+ minifyEnabled false
42
67
  }
68
+ }
69
+
70
+ lintOptions {
71
+ disable "GradleCompatible"
72
+ }
73
+
74
+ compileOptions {
75
+ sourceCompatibility JavaVersion.VERSION_1_8
76
+ targetCompatibility JavaVersion.VERSION_1_8
77
+ }
43
78
  ndkVersion '25.1.8937393'
44
79
  }
45
80
 
46
81
  repositories {
47
- mavenLocal()
48
- google()
49
- jcenter()
50
- mavenCentral()
51
- maven {
52
- // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
53
- url("$rootDir/../node_modules/react-native/android")
54
- }
55
-
82
+ mavenLocal()
83
+ google()
84
+ jcenter()
85
+ mavenCentral()
86
+
87
+ // Add this repo to get go-fula package
88
+ maven { url 'https://jitpack.io' }
89
+ }
56
90
 
57
91
 
58
- // Add this repo to get go-fula package
59
- maven { url 'https://jitpack.io' }
92
+ dependencies {
93
+ // For < 0.71, this will be from the local maven repo
94
+ // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
95
+ //noinspection GradleDynamicVersion
96
+ implementation "com.facebook.react:react-native:+"
97
+ implementation 'com.github.functionland:fula-build-aar:1.13.1' // From jitpack.io
98
+ implementation 'com.github.functionland:wnfs-android:v1.8.0' // From jitpack.io
99
+ implementation 'commons-io:commons-io:20030203.000550'
100
+ implementation 'commons-codec:commons-codec:1.15'
101
+ // implementation files('mobile.aar')
60
102
  }
61
103
 
62
- dependencies {
63
- //noinspection GradleDynamicVersion
64
- implementation "com.facebook.react:react-native:+" // From node_modules
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
- implementation 'commons-io:commons-io:20030203.000550'
68
- implementation 'commons-codec:commons-codec:1.15'
69
- // implementation files('mobile.aar')
104
+ if (isNewArchitectureEnabled()) {
105
+ react {
106
+ jsRootDir = file("../src/")
107
+ libraryName = "Fula"
108
+ codegenJavaPackageName = "land.fx.fula"
109
+ }
70
110
  }
@@ -1 +1,5 @@
1
- android.useAndroidX=true
1
+ Fula_kotlinVersion=1.7.0
2
+ Fula_minSdkVersion=21
3
+ Fula_targetSdkVersion=31
4
+ Fula_compileSdkVersion=31
5
+ Fula_ndkversion=21.4.7075529
@@ -1,4 +1,3 @@
1
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
- package="land.fx.fula">
3
-
4
- </manifest>
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="land.fx.fula">
3
+ </manifest>
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -1,7 +1,7 @@
1
- package land.fx.fula;
2
-
3
- public final class ConfigRef {
4
- public byte[] identity;
5
- public java.lang.String storePath;
6
- }
7
-
1
+ package land.fx.fula;
2
+
3
+ public final class ConfigRef {
4
+ public byte[] identity;
5
+ public java.lang.String storePath;
6
+ }
7
+
@@ -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
+ }
@@ -250,7 +250,7 @@ public class FulaModule extends ReactContextBaseJavaModule {
250
250
  }
251
251
 
252
252
  @ReactMethod
253
- public void init(String identityString, String storePath, String bloxAddr, String exchange, boolean autoFlush, String rootConfig, boolean useRelay, boolean refresh, Promise promise) {
253
+ public void initFula(String identityString, String storePath, String bloxAddr, String exchange, boolean autoFlush, String rootConfig, boolean useRelay, boolean refresh, Promise promise) {
254
254
  Log.d("ReactNative", "init started");
255
255
  ThreadUtils.runOnExecutor(() -> {
256
256
  try {
@@ -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
+ }