@functionland/react-native-fula 1.0.0 → 1.1.5

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