@functionland/react-native-fula 1.9.0 → 1.12.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.
package/README.md CHANGED
@@ -1,205 +1,214 @@
1
- # react-native-fula
2
-
3
- This package is a bridge to use the [Fula protocols](https://github.com/functionland/go-fula) in the react-native. It uses [WNFS](https://github.com/wnfs-wg/rs-wnfs) to create the Merkle dag from files and folders and transfer the DAG using Graphsync to the nodes.
4
-
5
- ## Installation
6
-
7
- ```sh
8
- npm install react-native-fula
9
- ```
10
-
11
- ## Usage
12
-
13
- ```js
14
- import { fula } from 'react-native-fula'; // Until the library becomes stable, we suggest importing from github directly
15
- ```
16
-
17
- ```js
18
- // Creates a new client without creating a filesystem. It is better to call this instead of directly calling init
19
- const peerId //returns peerId as string
20
- = newClient(
21
- identity: string, //privateKey of did identity
22
- storePath: string, // leave empty to use the default temp one
23
- bloxAddr: string, //leave empty for testing without a backend node
24
- exchange: 'noop'|'', //add noop for testing without a backend
25
- autoFlush: boolean, //Default to false. Always set to false unless you know what you are doing. explicitly write data to disk after each operation if set to true
26
- useRelay: boolean, //default to true. If true it forces the connection through relay
27
- refresh: boolean? //forces the fula object to be recreated. default is false
28
- )
29
- ```
30
-
31
- ```js
32
- //Initialize the fula client, which creates the libp2p connection if newClient is not called before, and creates filesystem. Note that input is not an object e.g. init('','','','noop', false)
33
- [
34
- peerId, //returns peerId of the created libp2p instance in form of a string of bytes
35
- cid, //return the root cid of the WNFS merkle DAG in form of a string
36
- private_ref //return the keys needed to decode hte encrypted WNFS tree in form of a string of object
37
- ]
38
- =
39
- await fula.init(
40
- identity: string, //bytes of the privateKey of did identity in string format
41
- storePath: string, // leave empty to use the default temp one
42
- bloxAddr: string, //leave empty for testing without a backend node
43
- exchange: 'noop'|'', //add noop for testing without a backend
44
- autoFlush: boolean, //Default to false. Always set to false unless you know what you are doing. explicitly write data to disk after each operation if set to true
45
- useRelay: boolean, //default to true. If true it forces the connection through relay
46
- refresh: boolean? //forces the fula object to be recreated. default is false
47
- );
48
- ```
49
-
50
- ```js
51
- //Creates a Folder
52
- const cid //returns the cid of the new root. Note that on every write action the root cid changes.
53
- =
54
- await fula.mkdir(
55
- path: string // This is the Fula path to create a folder and always starts with "root/" and should not start or end with a slash e.g "root/pictures"
56
- );
57
- ```
58
-
59
- ```js
60
- //Write a local file on the device to the Fula tree (upload). It keeps the original file modification date.
61
- const cid //returns the cid of the new root. Note that on every write action the root cid changes.
62
- =
63
- await fula.writeFile(
64
- fulaTargetFilename: string, //path to the file on the tree. It should include the filename and extension and start from the "root/". e.g. "root/pictures/cat.jpg"
65
- localFilename: string //path to the local file. e.g the file that needs to be uploaded
66
- );
67
- //// TODO: This needs to be improved by using stream to not overload the memory for large files
68
- ```
69
-
70
- ```js
71
- //reads a file on fula tree to a local file on the device (download). It is stream so does not affect memory for large files.
72
- const localFilePath //returns the path to the local file and includes the filename
73
- =
74
- await fula.readFile(
75
- fulaTargetFilename: string, //path to the file on the tree. It should include the filename and extension and start from the "root/". e.g. "root/pictures/cat.jpg"
76
- localFilename: string //path to the local file. It should include the filename and extension. e.g. "/temp/cat.jpg"
77
- );
78
- ```
79
-
80
- ```js
81
- //shows all files and folders under the specified path on Fula
82
- const fileList //returns all the files and folders in a string separated by \n
83
- =
84
- await fula.ls(
85
- path: string, //path to the folder on the tree. It always starts from the "root". e.g. "root" or "root/pictures"
86
- );
87
- //// TODO: This needs to be improved by returning an array of files and folders and in chunks to not overload hte memory for large folders
88
- ```
89
-
90
- ```js
91
- //removes all files and folders at the specified path on Fula
92
- const cid //returns the cid of the new root. Note that on every write action the root cid changes.
93
- =
94
- await fula.rm(
95
- path: string, //path to the file or folder on the tree. It always starts from the "root". e.g. "root/pictures" or "root/pictures/cat.jpg"
96
- );
97
-
98
- ```
99
-
100
- ```js
101
- //copies the specified file or folder at sourcePath to the filename at targetPath. the path itself(apart from filename) must exist
102
- const cid //returns the cid of the new root. Note that on every write action the root cid changes.
103
- =
104
- await fula.cp(
105
- sourcePath: string, //path to the file or folder on the tree. It always starts from the "root". e.g. "root/pictures" or "root/pictures/cat.jpg"
106
- targetPath: string, //path to the file or folder on the tree. It always starts from the "root". e.g. "root/pictures2" or "root/pictures2/cat.jpg"
107
- );
108
-
109
- ```
110
-
111
- ```js
112
- //moves the specified file or folder at sourcePath to the filename at targetPath. the path itself(apart from filename) must exist
113
- const cid //returns the cid of the new root. Note that on every write action the root cid changes.
114
- =
115
- await fula.mv(
116
- sourcePath: string, //path to the file or folder on the tree. It always starts from the "root". e.g. "root/pictures" or "root/pictures/cat.jpg"
117
- targetPath: string, //path to the file or folder on the tree. It always starts from the "root". e.g. "root/pictures2" or "root/pictures2/cat.jpg"
118
- );
119
-
120
- ```
121
-
122
- ```js
123
- //checks if fula is ready (initialized through newClient or init)
124
- const result //returns true if succesful and false if fails
125
- =
126
- await fula.isReady(
127
- filesystemCheck: boolean //Default is true. If true it checks if both WNFS and Fula are ready. If false it only checks fula
128
- );
129
-
130
- ```
131
-
132
- ```js
133
- //checks if client can reach server
134
- const result //returns true if it can, and false if it cannot
135
- =
136
- await fula.checkConnection(
137
- timeout: number? //default to 20. Maximum time in seconds that checkConnection waits before throwing an error
138
- );
139
-
140
- ```
141
-
142
- ```js
143
- //checks if there are any un-synced actions on the client
144
- const result //returns true if there are, and false if everything is synced with server
145
- =
146
- await fula.checkFailedActions(
147
- retry: boolean //if true, it tries to sync device with server, if not, it only checks
148
- timeout: number? //default to 20. Maximum time in seconds that checkConnection waits before throwing an error
149
- );
150
- ```
151
-
152
- ```js
153
- //Gives access to the blox for a specific peerId. This call must be made from the authorizer only.
154
- const result //returns true if succesful and false if fails
155
- =
156
- await fula.setAuth(
157
- peerId: string, //peer ID of the app that needs access to the blox
158
- allow: boolean, // true to allow and false to remove access
159
- );
160
-
161
- ```
162
-
163
- ```js
164
- //shuts down the fula libp2p and datastore
165
- await fula.shutdown();
166
- ```
167
-
168
- ```js
169
- //removes all Fula related data and information (Except the encrypted filesystem) at the specified storage local path
170
- const result //returns true if succesful and false if fails
171
- =
172
- await fula.logout(
173
- identity: string, //bytes of the privateKey of did identity in string format
174
- storePath: string, // leave empty to use the default temp one
175
- );
176
-
177
- ```
178
-
179
- ## Roadmap
180
-
181
- Please note the following might not be done in order:
182
-
183
- - [x] Initial version with all functions included
184
- - [x] Add WNFS tree encryption key generation from an input (deterministically)
185
- - [x] Improve ead function to use a stream. ( :100: v1 Release here )
186
- - [x] Connect to backend
187
- - [ ] Connect to Blockchain codes using APIs
188
-
189
- ## Other related libraries
190
-
191
- | Name | Description |
192
- | --- | --- |
193
- | [WNFS for Android](https://github.com/functionland/wnfs-android) | Android build for WNFS rust version |
194
- | [WNFS for iOS](https://github.com/functionland/wnfs-ios) | iOS build for WNFS rust version |
195
- | [WNFS Build](https://github.com/functionland/wnfs-build-aar) | Android .aar for WNFS |
196
- | [Fula Build](https://github.com/functionland/fula-build-aar) | android .aar file for Fula |
197
- | [Fx Fotos](https://github.com/functionland/fx-fotos) | Fx Fotos dApp using react-native-fula |
198
-
199
- ## Contributing
200
-
201
- See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
202
-
203
- ## License
204
-
205
- MIT
1
+ # react-native-fula
2
+
3
+ This package is a bridge to use the [Fula protocols](https://github.com/functionland/go-fula) in the react-native. It uses [WNFS](https://github.com/wnfs-wg/rs-wnfs) to create the Merkle dag from files and folders and transfer the DAG using Graphsync to the nodes.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install react-native-fula
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import { fula } from 'react-native-fula'; // Until the library becomes stable, we suggest importing from github directly
15
+ ```
16
+
17
+ ```js
18
+ // Creates a new client without creating a filesystem. It is better to call this instead of directly calling init
19
+ const peerId //returns peerId as string
20
+ = newClient(
21
+ identity: string, //privateKey of did identity
22
+ storePath: string, // leave empty to use the default temp one
23
+ bloxAddr: string, //leave empty for testing without a backend node
24
+ exchange: 'noop'|'', //add noop for testing without a backend
25
+ autoFlush: boolean, //Default to false. Always set to false unless you know what you are doing. explicitly write data to disk after each operation if set to true
26
+ useRelay: boolean, //default to true. If true it forces the connection through relay
27
+ refresh: boolean? //forces the fula object to be recreated. default is false
28
+ )
29
+ ```
30
+
31
+ ```js
32
+ //Initialize the fula client, which creates the libp2p connection if newClient is not called before, and creates filesystem. Note that input is not an object e.g. init('','','','noop', false)
33
+ [
34
+ peerId, //returns peerId of the created libp2p instance in form of a string of bytes
35
+ cid, //return the root cid of the WNFS merkle DAG in form of a string
36
+ private_ref //return the keys needed to decode hte encrypted WNFS tree in form of a string of object
37
+ ]
38
+ =
39
+ await fula.init(
40
+ identity: string, //bytes of the privateKey of did identity in string format
41
+ storePath: string, // leave empty to use the default temp one
42
+ bloxAddr: string, //leave empty for testing without a backend node
43
+ exchange: 'noop'|'', //add noop for testing without a backend
44
+ autoFlush: boolean, //Default to false. Always set to false unless you know what you are doing. explicitly write data to disk after each operation if set to true
45
+ useRelay: boolean, //default to true. If true it forces the connection through relay
46
+ refresh: boolean? //forces the fula object to be recreated. default is false
47
+ );
48
+ ```
49
+
50
+ ```js
51
+ //Creates a Folder
52
+ const cid //returns the cid of the new root. Note that on every write action the root cid changes.
53
+ =
54
+ await fula.mkdir(
55
+ path: string // This is the Fula path to create a folder and always starts with "root/" and should not start or end with a slash e.g "root/pictures"
56
+ );
57
+ ```
58
+
59
+ ```js
60
+ //Write a local file on the device to the Fula tree (upload). It keeps the original file modification date.
61
+ const cid //returns the cid of the new root. Note that on every write action the root cid changes.
62
+ =
63
+ await fula.writeFile(
64
+ fulaTargetFilename: string, //path to the file on the tree. It should include the filename and extension and start from the "root/". e.g. "root/pictures/cat.jpg"
65
+ localFilename: string //path to the local file. e.g the file that needs to be uploaded
66
+ );
67
+ //// TODO: This needs to be improved by using stream to not overload the memory for large files
68
+ ```
69
+
70
+ ```js
71
+ //reads a file on fula tree to a local file on the device (download). It is stream so does not affect memory for large files.
72
+ const localFilePath //returns the path to the local file and includes the filename
73
+ =
74
+ await fula.readFile(
75
+ fulaTargetFilename: string, //path to the file on the tree. It should include the filename and extension and start from the "root/". e.g. "root/pictures/cat.jpg"
76
+ localFilename: string //path to the local file. It should include the filename and extension. e.g. "/temp/cat.jpg"
77
+ );
78
+ ```
79
+
80
+ ```js
81
+ //shows all files and folders under the specified path on Fula
82
+ const fileList //returns all the files and folders in a string separated by \n
83
+ =
84
+ await fula.ls(
85
+ path: string, //path to the folder on the tree. It always starts from the "root". e.g. "root" or "root/pictures"
86
+ );
87
+ //// TODO: This needs to be improved by returning an array of files and folders and in chunks to not overload hte memory for large folders
88
+ ```
89
+
90
+ ```js
91
+ //removes all files and folders at the specified path on Fula
92
+ const cid //returns the cid of the new root. Note that on every write action the root cid changes.
93
+ =
94
+ await fula.rm(
95
+ path: string, //path to the file or folder on the tree. It always starts from the "root". e.g. "root/pictures" or "root/pictures/cat.jpg"
96
+ );
97
+
98
+ ```
99
+
100
+ ```js
101
+ //copies the specified file or folder at sourcePath to the filename at targetPath. the path itself(apart from filename) must exist
102
+ const cid //returns the cid of the new root. Note that on every write action the root cid changes.
103
+ =
104
+ await fula.cp(
105
+ sourcePath: string, //path to the file or folder on the tree. It always starts from the "root". e.g. "root/pictures" or "root/pictures/cat.jpg"
106
+ targetPath: string, //path to the file or folder on the tree. It always starts from the "root". e.g. "root/pictures2" or "root/pictures2/cat.jpg"
107
+ );
108
+
109
+ ```
110
+
111
+ ```js
112
+ //moves the specified file or folder at sourcePath to the filename at targetPath. the path itself(apart from filename) must exist
113
+ const cid //returns the cid of the new root. Note that on every write action the root cid changes.
114
+ =
115
+ await fula.mv(
116
+ sourcePath: string, //path to the file or folder on the tree. It always starts from the "root". e.g. "root/pictures" or "root/pictures/cat.jpg"
117
+ targetPath: string, //path to the file or folder on the tree. It always starts from the "root". e.g. "root/pictures2" or "root/pictures2/cat.jpg"
118
+ );
119
+
120
+ ```
121
+
122
+ ```js
123
+ //checks if fula is ready (initialized through newClient or init)
124
+ const result //returns true if succesful and false if fails
125
+ =
126
+ await fula.isReady(
127
+ filesystemCheck: boolean //Default is true. If true it checks if both WNFS and Fula are ready. If false it only checks fula
128
+ );
129
+
130
+ ```
131
+
132
+ ```js
133
+ //checks if client can reach server
134
+ const result //returns true if it can, and false if it cannot
135
+ =
136
+ await fula.checkConnection(
137
+ timeout: number? //default to 20. Maximum time in seconds that checkConnection waits before throwing an error
138
+ );
139
+
140
+ ```
141
+
142
+ ```js
143
+ //checks if there are any un-synced actions on the client
144
+ const result //returns true if there are, and false if everything is synced with server
145
+ =
146
+ await fula.checkFailedActions(
147
+ retry: boolean //if true, it tries to sync device with server, if not, it only checks
148
+ timeout: number? //default to 20. Maximum time in seconds that checkConnection waits before throwing an error
149
+ );
150
+ ```
151
+
152
+ ```js
153
+ //lists any cids that are failed to be pushed to backend and only exist on client device
154
+ const result //returns an array of cids or false if no cid is found
155
+ =
156
+ await fula.listFailedActions(
157
+ cids: string[] //if [], it returns all failed cids, and if provided, it only return the failed cids that are in the array of cids provided as input
158
+ );
159
+ ```
160
+
161
+ ```js
162
+ //Gives access to the blox for a specific peerId. This call must be made from the authorizer only.
163
+ const result //returns true if succesful and false if fails
164
+ =
165
+ await fula.setAuth(
166
+ peerId: string, //peer ID of the app that needs access to the blox
167
+ allow: boolean, // true to allow and false to remove access
168
+ );
169
+
170
+ ```
171
+
172
+ ```js
173
+ //shuts down the fula libp2p and datastore
174
+ await fula.shutdown();
175
+ ```
176
+
177
+ ```js
178
+ //removes all Fula related data and information (Except the encrypted filesystem) at the specified storage local path
179
+ const result //returns true if succesful and false if fails
180
+ =
181
+ await fula.logout(
182
+ identity: string, //bytes of the privateKey of did identity in string format
183
+ storePath: string, // leave empty to use the default temp one
184
+ );
185
+
186
+ ```
187
+
188
+ ## Roadmap
189
+
190
+ Please note the following might not be done in order:
191
+
192
+ - [x] Initial version with all functions included
193
+ - [x] Add WNFS tree encryption key generation from an input (deterministically)
194
+ - [x] Improve ead function to use a stream. ( :100: v1 Release here )
195
+ - [x] Connect to backend
196
+ - [ ] Connect to Blockchain codes using APIs
197
+
198
+ ## Other related libraries
199
+
200
+ | Name | Description |
201
+ | --- | --- |
202
+ | [WNFS for Android](https://github.com/functionland/wnfs-android) | Android build for WNFS rust version |
203
+ | [WNFS for iOS](https://github.com/functionland/wnfs-ios) | iOS build for WNFS rust version |
204
+ | [WNFS Build](https://github.com/functionland/wnfs-build-aar) | Android .aar for WNFS |
205
+ | [Fula Build](https://github.com/functionland/fula-build-aar) | android .aar file for Fula |
206
+ | [Fx Fotos](https://github.com/functionland/fx-fotos) | Fx Fotos dApp using react-native-fula |
207
+
208
+ ## Contributing
209
+
210
+ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
211
+
212
+ ## License
213
+
214
+ MIT
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
3
  <component name="CompilerConfiguration">
4
- <bytecodeTargetLevel target="11" />
4
+ <bytecodeTargetLevel target="17" />
5
5
  </component>
6
6
  </project>
@@ -8,6 +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
12
  <option name="modules">
12
13
  <set>
13
14
  <option value="$PROJECT_DIR$" />
@@ -1,10 +1,10 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ExternalStorageConfigurationManager" enabled="true" />
4
- <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
5
- <output url="file://$PROJECT_DIR$/build/classes" />
6
- </component>
7
- <component name="ProjectType">
8
- <option name="id" value="Android" />
9
- </component>
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ExternalStorageConfigurationManager" enabled="true" />
4
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
5
+ <output url="file://$PROJECT_DIR$/build/classes" />
6
+ </component>
7
+ <component name="ProjectType">
8
+ <option name="id" value="Android" />
9
+ </component>
10
10
  </project>
@@ -1,69 +1,70 @@
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
- }
13
- }
14
-
15
- apply plugin: 'com.android.library'
16
-
17
- def safeExtGet(prop, fallback) {
18
- rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
19
- }
20
-
21
- 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"
28
-
29
- }
30
-
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
42
- }
43
- ndkVersion '25.1.8937393'
44
- }
45
-
46
- 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
-
56
-
57
-
58
- // Add this repo to get go-fula package
59
- maven { url 'https://jitpack.io' }
60
- }
61
-
62
- dependencies {
63
- //noinspection GradleDynamicVersion
64
- implementation "com.facebook.react:react-native:+" // From node_modules
65
- implementation 'com.github.functionland:fula-build-aar:1.9.0' // From jitpack.io
66
- implementation 'com.github.functionland:wnfs-build-aar:v1.4.1' // From jitpack.io
67
- implementation 'commons-io:commons-io:20030203.000550'
68
- // implementation files('mobile.aar')
69
- }
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
+ }
13
+ }
14
+
15
+ apply plugin: 'com.android.library'
16
+
17
+ def safeExtGet(prop, fallback) {
18
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
19
+ }
20
+
21
+ 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"
28
+
29
+ }
30
+
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
42
+ }
43
+ ndkVersion '25.1.8937393'
44
+ }
45
+
46
+ 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
+
56
+
57
+
58
+ // Add this repo to get go-fula package
59
+ maven { url 'https://jitpack.io' }
60
+ }
61
+
62
+ dependencies {
63
+ //noinspection GradleDynamicVersion
64
+ implementation "com.facebook.react:react-native:+" // From node_modules
65
+ implementation 'com.github.functionland:fula-build-aar:1.12.0' // From jitpack.io
66
+ implementation 'com.github.functionland:wnfs-build-aar:v1.4.1' // From jitpack.io
67
+ implementation 'commons-io:commons-io:20030203.000550'
68
+ implementation 'commons-codec:commons-codec:1.15'
69
+ // implementation files('mobile.aar')
70
+ }