@functionland/react-native-fula 1.8.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.
Files changed (54) hide show
  1. package/README.md +214 -205
  2. package/android/.gradle/7.5.1/checksums/checksums.lock +0 -0
  3. package/android/.gradle/7.5.1/checksums/md5-checksums.bin +0 -0
  4. package/android/.gradle/7.5.1/checksums/sha1-checksums.bin +0 -0
  5. package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
  6. package/android/.gradle/7.6/checksums/checksums.lock +0 -0
  7. package/android/.gradle/7.6/checksums/md5-checksums.bin +0 -0
  8. package/android/.gradle/7.6/checksums/sha1-checksums.bin +0 -0
  9. package/android/.gradle/7.6/executionHistory/executionHistory.bin +0 -0
  10. package/android/.gradle/7.6/executionHistory/executionHistory.lock +0 -0
  11. package/android/.gradle/7.6/fileHashes/fileHashes.bin +0 -0
  12. package/android/.gradle/7.6/fileHashes/fileHashes.lock +0 -0
  13. package/android/.gradle/7.6/fileHashes/resourceHashesCache.bin +0 -0
  14. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  15. package/android/.gradle/buildOutputCleanup/cache.properties +1 -1
  16. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  17. package/android/.gradle/file-system.probe +0 -0
  18. package/android/.idea/compiler.xml +1 -1
  19. package/android/.idea/gradle.xml +1 -0
  20. package/android/.idea/misc.xml +9 -9
  21. package/android/.idea/sonarlint/securityhotspotstore/index.pb +0 -0
  22. package/android/build.gradle +2 -1
  23. package/android/src/main/java/land/fx/fula/Cryptography.java +60 -60
  24. package/android/src/main/java/land/fx/fula/FulaModule.java +126 -17
  25. package/android/src/main/java/land/fx/fula/FulaPackage.java +32 -32
  26. package/lib/commonjs/index.js.map +1 -1
  27. package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
  28. package/lib/commonjs/protocols/blockchain.js +12 -12
  29. package/lib/commonjs/protocols/blockchain.js.map +1 -1
  30. package/lib/commonjs/protocols/fula.js +113 -98
  31. package/lib/commonjs/protocols/fula.js.map +1 -1
  32. package/lib/commonjs/protocols/fxblox.js +23 -4
  33. package/lib/commonjs/protocols/fxblox.js.map +1 -1
  34. package/lib/commonjs/types/fxblox.js.map +1 -1
  35. package/lib/module/index.js.map +1 -1
  36. package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
  37. package/lib/module/protocols/blockchain.js +12 -12
  38. package/lib/module/protocols/blockchain.js.map +1 -1
  39. package/lib/module/protocols/fula.js +109 -96
  40. package/lib/module/protocols/fula.js.map +1 -1
  41. package/lib/module/protocols/fxblox.js +21 -3
  42. package/lib/module/protocols/fxblox.js.map +1 -1
  43. package/lib/module/types/fxblox.js.map +1 -1
  44. package/lib/typescript/interfaces/fulaNativeModule.d.ts +3 -0
  45. package/lib/typescript/protocols/fula.d.ts +5 -0
  46. package/lib/typescript/protocols/fxblox.d.ts +1 -0
  47. package/lib/typescript/types/fxblox.d.ts +4 -0
  48. package/package.json +1 -1
  49. package/src/index.tsx +4 -4
  50. package/src/interfaces/fulaNativeModule.ts +43 -8
  51. package/src/protocols/blockchain.ts +318 -274
  52. package/src/protocols/fula.ts +301 -286
  53. package/src/protocols/fxblox.ts +49 -28
  54. package/src/types/fxblox.ts +8 -4
@@ -1,286 +1,301 @@
1
- import Fula from '../interfaces/fulaNativeModule';
2
-
3
- /**
4
- * Get gets the value corresponding to the given key from the local datastore.
5
- // The key must be a valid ipld.Link.
6
- * @param config
7
- * @returns boolean
8
- */
9
-
10
- export const init = (
11
- identity: string, //privateKey of did identity
12
- storePath: string,
13
- bloxAddr: string,
14
- exchange: string,
15
- autoFlush: boolean = false,
16
- rootCid: string | null = null,
17
- useRelay: boolean = true,
18
- refresh: boolean = false
19
- ): Promise<{ peerId: string; rootCid: string; private_ref: string }> => {
20
- console.log(
21
- 'init in react-native started',
22
- identity,
23
- storePath,
24
- bloxAddr,
25
- exchange,
26
- autoFlush,
27
- useRelay
28
- );
29
- return Fula.init(identity, storePath, bloxAddr, exchange, autoFlush, rootCid, useRelay, refresh);
30
- };
31
-
32
- /**
33
- * Get gets the value corresponding to the given key from the local datastore.
34
- // The key must be a valid ipld.Link.
35
- * @param config
36
- * @returns boolean
37
- */
38
-
39
- export const newClient = (
40
- identity: string, //privateKey of did identity
41
- storePath: string,
42
- bloxAddr: string,
43
- exchange: string,
44
- autoFlush: boolean = false,
45
- useRelay: boolean = true,
46
- refresh: boolean = false
47
- ): Promise<string> => {
48
- console.log(
49
- 'newClient in react-native started',
50
- identity,
51
- storePath,
52
- bloxAddr,
53
- exchange,
54
- autoFlush,
55
- useRelay,
56
- refresh
57
- );
58
- return Fula.newClient(identity, storePath, bloxAddr, exchange, autoFlush, useRelay, refresh);
59
- };
60
-
61
- /**
62
- * rm removes all data
63
- * @param path
64
- * @returns string: new cid of the root
65
- */
66
- export const logout = (
67
- identity: string,
68
- storePath: string
69
- ): Promise<boolean> => {
70
- return Fula.logout(identity, storePath);
71
- };
72
-
73
- /**
74
- * Checks if there are any un-synced changes on the device
75
- */
76
- export const checkFailedActions = (
77
- retry: boolean = false,
78
- timeout: number = 20
79
- ): Promise<boolean> => {
80
- return Fula.checkFailedActions(retry, timeout);
81
- };
82
-
83
- /**
84
- * Checks if there are any un-synced changes on the device
85
- */
86
- export const checkConnection = (timeout: number = 20): Promise<boolean> => {
87
- return Fula.checkConnection(timeout);
88
- };
89
-
90
- /**
91
- * Get gets the value corresponding to the given key from the local datastore.
92
- // The key must be a valid ipld.Link.
93
- * @param key
94
- * @returns value
95
- */
96
- export const get = (key: string): Promise<string> => {
97
- return Fula.get(key);
98
- };
99
-
100
- /**
101
- * Has checks whether the value corresponding to the given key is present in the local datastore.
102
- // The key must be a valid ipld.Link.
103
- * @param key
104
- * @returns boolean
105
- */
106
- export const has = (key: Uint8Array): Promise<boolean> => {
107
- return Fula.has(key);
108
- };
109
-
110
- /**
111
- * Push requests the given addr to download the root cid from this node.
112
- // The addr must be a valid multiaddr that includes peer ID.
113
- // this function.
114
- * @param addr
115
- * @returns null or error
116
- */
117
- export const push = (): Promise<string> => {
118
- return Fula.push();
119
- };
120
-
121
- /**
122
- * Put stores the given key value onto the local datastore.
123
- // The key must be a valid ipld.Link and the value must be the valid encoded ipld.Node corresponding
124
- // to the given key.
125
- * @param key, value
126
- * @returns null or string
127
- */
128
- export const put = (value: string, codec: string): Promise<string> => {
129
- return Fula.put(value, codec);
130
- };
131
-
132
- /**
133
- * mkdir creates a directory at the given path.
134
- * @param path
135
- * @returns string: new cid of the root
136
- */
137
- export const mkdir = (path: string): Promise<string> => {
138
- return Fula.mkdir(path);
139
- };
140
-
141
- /**
142
- * writeFileContent writes content at a given path
143
- * @param path
144
- * @returns string: new cid of the root
145
- */
146
- export const writeFileContent = (
147
- path: string,
148
- content: string
149
- ): Promise<string> => {
150
- return Fula.writeFileContent(path, content);
151
- };
152
-
153
- /*
154
- // reads content of the file form localFilename (should include full absolute path to local file with read permission
155
- // writes content to the specified location by fulaTargetFilename in Fula filesystem
156
- // It keeps the original file modiifcation date
157
- // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
158
- // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
159
- // Returns: new cid of the root after this file is placed in the tree
160
- */
161
- export const writeFile = (
162
- fulaTargetFilename: string,
163
- localFilename: string
164
- ): Promise<string> => {
165
- return Fula.writeFile(fulaTargetFilename, localFilename);
166
- };
167
-
168
- /**
169
- * ls lists the name of files and folders at a given path
170
- * @param path
171
- * @returns string: list of items
172
- * TODO: Findout how is the string and convert to array
173
- */
174
- export const ls = (path: string): Promise<void | JSON> => {
175
- return Fula.ls(path)
176
- .then((res) => {
177
- let lsResult = [];
178
- let lsRows = res.split('!!!');
179
- for (const element of lsRows) {
180
- let rowItems = element.split('???');
181
- if (rowItems && rowItems[0]) {
182
- let item = {
183
- name: '',
184
- created: '',
185
- modified: '',
186
- };
187
- item.name = rowItems[0];
188
- if (rowItems[1]) {
189
- item.created = rowItems[1];
190
- }
191
- if (rowItems[2]) {
192
- item.modified = rowItems[2];
193
- }
194
- lsResult.push(item);
195
- }
196
- }
197
- let jsonRes = JSON.parse(JSON.stringify(lsResult));
198
- return jsonRes;
199
- })
200
- .catch((e) => {
201
- return e;
202
- });
203
- };
204
-
205
- /**
206
- * rm removes all files and folders at a given path
207
- * @param path
208
- * @returns string: new cid of the root
209
- */
210
- export const rm = (path: string): Promise<string> => {
211
- return Fula.rm(path);
212
- };
213
-
214
- /**
215
- * cp copies the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
216
- * @param sourcePath, targetPath
217
- * @returns string: new cid of the root
218
- */
219
- export const cp = (sourcePath: string, targetPath: string): Promise<string> => {
220
- return Fula.cp(sourcePath, targetPath);
221
- };
222
-
223
- /**
224
- * mv moves the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
225
- * @param sourcePath, targetPath
226
- * @returns string: new cid of the root
227
- */
228
- export const mv = (sourcePath: string, targetPath: string): Promise<string> => {
229
- return Fula.mv(sourcePath, targetPath);
230
- };
231
-
232
- /*
233
- // reads content of the file form localFilename (should include full absolute path to local file with read permission
234
- // writes content to the specified location by fulaTargetFilename in Fula filesystem
235
- // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
236
- // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
237
- // Returns: new cid of the root after this file is placed in the tree
238
- */
239
- export const readFile = (
240
- fulaTargetFilename: string,
241
- localFilename: string
242
- ): Promise<string> => {
243
- return Fula.readFile(fulaTargetFilename, localFilename);
244
- };
245
-
246
- /**
247
- * readFile reads content of a given path
248
- * @param path
249
- * @returns string: cotent
250
- */
251
- export const readFileContent = (path: string): Promise<string> => {
252
- return Fula.readFileContent(path);
253
- };
254
-
255
- /**
256
- * Shutdown closes all resources used by Client.
257
- // After calling this function Client must be discarded.
258
- * @param
259
- * @returns
260
- */
261
- export const shutdown = (): Promise<void> => {
262
- return Fula.shutdown();
263
- };
264
-
265
- /**
266
- * setAuth adds or removes a peer from the list of peers that are allowed to push to this node.
267
- * This can only be called on a peer that is added as an owner of blox by --authorizer parameter
268
- * @param peerId, allow
269
- * @returns boolean: true if successful or false if not
270
- */
271
- export const setAuth = (
272
- peerId: string,
273
- allow: boolean
274
- ): Promise<boolean> => {
275
- return Fula.setAuth(peerId, allow);
276
- };
277
-
278
-
279
- /**
280
- * isReady checks if the connection is ready to be used.
281
- * @param filesystemCheck: also check if the wnfs is ready
282
- * @returns boolean: true if ready or false if not
283
- */
284
- export const isReady = (filesystemCheck: boolean = true): Promise<boolean> => {
285
- return Fula.isReady(filesystemCheck);
286
- };
1
+ import Fula from '../interfaces/fulaNativeModule';
2
+
3
+ /**
4
+ * Get gets the value corresponding to the given key from the local datastore.
5
+ // The key must be a valid ipld.Link.
6
+ * @param config
7
+ * @returns boolean
8
+ */
9
+
10
+ export const init = (
11
+ identity: string, //privateKey of did identity
12
+ storePath: string,
13
+ bloxAddr: string,
14
+ exchange: string,
15
+ autoFlush: boolean = false,
16
+ rootCid: string | null = null,
17
+ useRelay: boolean = true,
18
+ refresh: boolean = false
19
+ ): Promise<{ peerId: string; rootCid: string; private_ref: string }> => {
20
+ console.log(
21
+ 'init in react-native started',
22
+ identity,
23
+ storePath,
24
+ bloxAddr,
25
+ exchange,
26
+ autoFlush,
27
+ useRelay
28
+ );
29
+ return Fula.init(identity, storePath, bloxAddr, exchange, autoFlush, rootCid, useRelay, refresh);
30
+ };
31
+
32
+ /**
33
+ * Get gets the value corresponding to the given key from the local datastore.
34
+ // The key must be a valid ipld.Link.
35
+ * @param config
36
+ * @returns boolean
37
+ */
38
+
39
+ export const newClient = (
40
+ identity: string, //privateKey of did identity
41
+ storePath: string,
42
+ bloxAddr: string,
43
+ exchange: string,
44
+ autoFlush: boolean = false,
45
+ useRelay: boolean = true,
46
+ refresh: boolean = false
47
+ ): Promise<string> => {
48
+ console.log(
49
+ 'newClient in react-native started',
50
+ identity,
51
+ storePath,
52
+ bloxAddr,
53
+ exchange,
54
+ autoFlush,
55
+ useRelay,
56
+ refresh
57
+ );
58
+ return Fula.newClient(identity, storePath, bloxAddr, exchange, autoFlush, useRelay, refresh);
59
+ };
60
+
61
+ /**
62
+ * rm removes all data
63
+ * @param path
64
+ * @returns string: new cid of the root
65
+ */
66
+ export const logout = (
67
+ identity: string,
68
+ storePath: string
69
+ ): Promise<boolean> => {
70
+ return Fula.logout(identity, storePath);
71
+ };
72
+
73
+ /**
74
+ * Checks if there are any un-synced changes on the device
75
+ */
76
+ export const checkFailedActions = (
77
+ retry: boolean = false,
78
+ timeout: number = 20
79
+ ): Promise<boolean> => {
80
+ return Fula.checkFailedActions(retry, timeout);
81
+ };
82
+
83
+ /**
84
+ * Lists the cids that failed to be sent to backend and are kept only locally
85
+ */
86
+ export const listFailedActions = (cids: string[] = []): Promise<string[]> => {
87
+ return Fula.listFailedActions(cids);
88
+ };
89
+
90
+ /**
91
+ * Checks if there are any un-synced changes on the device
92
+ */
93
+ export const checkConnection = (timeout: number = 20): Promise<boolean> => {
94
+ return Fula.checkConnection(timeout);
95
+ };
96
+
97
+ /**
98
+ * Get gets the value corresponding to the given key from the local datastore.
99
+ // The key must be a valid ipld.Link.
100
+ * @param key
101
+ * @returns value
102
+ */
103
+ export const get = (key: string): Promise<string> => {
104
+ return Fula.get(key);
105
+ };
106
+
107
+ /**
108
+ * Has checks whether the value corresponding to the given key is present in the local datastore.
109
+ // The key must be a valid ipld.Link.
110
+ * @param key
111
+ * @returns boolean
112
+ */
113
+ export const has = (key: Uint8Array): Promise<boolean> => {
114
+ return Fula.has(key);
115
+ };
116
+
117
+ /**
118
+ * Push requests the given addr to download the root cid from this node.
119
+ // The addr must be a valid multiaddr that includes peer ID.
120
+ // this function.
121
+ * @param addr
122
+ * @returns null or error
123
+ */
124
+ export const push = (): Promise<string> => {
125
+ return Fula.push();
126
+ };
127
+
128
+ //This method sends some test data to backedn
129
+ export const testData = (
130
+ identity: string,
131
+ bloxAddr: string
132
+ ): Promise<string> => {
133
+ return Fula.testData(identity, bloxAddr);
134
+ };
135
+
136
+ /**
137
+ * Put stores the given key value onto the local datastore.
138
+ // The key must be a valid ipld.Link and the value must be the valid encoded ipld.Node corresponding
139
+ // to the given key.
140
+ * @param key, value
141
+ * @returns null or string
142
+ */
143
+ export const put = (value: string, codec: string): Promise<string> => {
144
+ return Fula.put(value, codec);
145
+ };
146
+
147
+ /**
148
+ * mkdir creates a directory at the given path.
149
+ * @param path
150
+ * @returns string: new cid of the root
151
+ */
152
+ export const mkdir = (path: string): Promise<string> => {
153
+ return Fula.mkdir(path);
154
+ };
155
+
156
+ /**
157
+ * writeFileContent writes content at a given path
158
+ * @param path
159
+ * @returns string: new cid of the root
160
+ */
161
+ export const writeFileContent = (
162
+ path: string,
163
+ content: string
164
+ ): Promise<string> => {
165
+ return Fula.writeFileContent(path, content);
166
+ };
167
+
168
+ /*
169
+ // reads content of the file form localFilename (should include full absolute path to local file with read permission
170
+ // writes content to the specified location by fulaTargetFilename in Fula filesystem
171
+ // It keeps the original file modiifcation date
172
+ // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
173
+ // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
174
+ // Returns: new cid of the root after this file is placed in the tree
175
+ */
176
+ export const writeFile = (
177
+ fulaTargetFilename: string,
178
+ localFilename: string
179
+ ): Promise<string> => {
180
+ return Fula.writeFile(fulaTargetFilename, localFilename);
181
+ };
182
+
183
+ /**
184
+ * ls lists the name of files and folders at a given path
185
+ * @param path
186
+ * @returns string: list of items
187
+ * TODO: Findout how is the string and convert to array
188
+ */
189
+ export const ls = (path: string): Promise<void | JSON> => {
190
+ return Fula.ls(path)
191
+ .then((res) => {
192
+ let lsResult = [];
193
+ let lsRows = res.split('!!!');
194
+ for (const element of lsRows) {
195
+ let rowItems = element.split('???');
196
+ if (rowItems && rowItems[0]) {
197
+ let item = {
198
+ name: '',
199
+ created: '',
200
+ modified: '',
201
+ };
202
+ item.name = rowItems[0];
203
+ if (rowItems[1]) {
204
+ item.created = rowItems[1];
205
+ }
206
+ if (rowItems[2]) {
207
+ item.modified = rowItems[2];
208
+ }
209
+ lsResult.push(item);
210
+ }
211
+ }
212
+ let jsonRes = JSON.parse(JSON.stringify(lsResult));
213
+ return jsonRes;
214
+ })
215
+ .catch((e) => {
216
+ return e;
217
+ });
218
+ };
219
+
220
+ /**
221
+ * rm removes all files and folders at a given path
222
+ * @param path
223
+ * @returns string: new cid of the root
224
+ */
225
+ export const rm = (path: string): Promise<string> => {
226
+ return Fula.rm(path);
227
+ };
228
+
229
+ /**
230
+ * cp copies the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
231
+ * @param sourcePath, targetPath
232
+ * @returns string: new cid of the root
233
+ */
234
+ export const cp = (sourcePath: string, targetPath: string): Promise<string> => {
235
+ return Fula.cp(sourcePath, targetPath);
236
+ };
237
+
238
+ /**
239
+ * mv moves the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
240
+ * @param sourcePath, targetPath
241
+ * @returns string: new cid of the root
242
+ */
243
+ export const mv = (sourcePath: string, targetPath: string): Promise<string> => {
244
+ return Fula.mv(sourcePath, targetPath);
245
+ };
246
+
247
+ /*
248
+ // reads content of the file form localFilename (should include full absolute path to local file with read permission
249
+ // writes content to the specified location by fulaTargetFilename in Fula filesystem
250
+ // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
251
+ // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
252
+ // Returns: new cid of the root after this file is placed in the tree
253
+ */
254
+ export const readFile = (
255
+ fulaTargetFilename: string,
256
+ localFilename: string
257
+ ): Promise<string> => {
258
+ return Fula.readFile(fulaTargetFilename, localFilename);
259
+ };
260
+
261
+ /**
262
+ * readFile reads content of a given path
263
+ * @param path
264
+ * @returns string: cotent
265
+ */
266
+ export const readFileContent = (path: string): Promise<string> => {
267
+ return Fula.readFileContent(path);
268
+ };
269
+
270
+ /**
271
+ * Shutdown closes all resources used by Client.
272
+ // After calling this function Client must be discarded.
273
+ * @param
274
+ * @returns
275
+ */
276
+ export const shutdown = (): Promise<void> => {
277
+ return Fula.shutdown();
278
+ };
279
+
280
+ /**
281
+ * setAuth adds or removes a peer from the list of peers that are allowed to push to this node.
282
+ * This can only be called on a peer that is added as an owner of blox by --authorizer parameter
283
+ * @param peerId, allow
284
+ * @returns boolean: true if successful or false if not
285
+ */
286
+ export const setAuth = (
287
+ peerId: string,
288
+ allow: boolean
289
+ ): Promise<boolean> => {
290
+ return Fula.setAuth(peerId, allow);
291
+ };
292
+
293
+
294
+ /**
295
+ * isReady checks if the connection is ready to be used.
296
+ * @param filesystemCheck: also check if the wnfs is ready
297
+ * @returns boolean: true if ready or false if not
298
+ */
299
+ export const isReady = (filesystemCheck: boolean = true): Promise<boolean> => {
300
+ return Fula.isReady(filesystemCheck);
301
+ };