@functionland/react-native-fula 1.0.0 → 1.1.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 (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 +138 -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 +133 -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 +57 -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 +85 -52
  81. package/src/protocols/blockchain.ts +460 -0
  82. package/src/protocols/chain-api.ts +80 -0
  83. package/src/protocols/fula.ts +283 -212
  84. package/src/types/blockchain.ts +81 -0
@@ -1,212 +1,283 @@
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
+ ): Promise<string> => {
47
+ console.log(
48
+ 'newClient in react-native started',
49
+ identity,
50
+ storePath,
51
+ bloxAddr,
52
+ exchange,
53
+ autoFlush,
54
+ useRelay
55
+ );
56
+ return Fula.newClient(identity, storePath, bloxAddr, exchange, autoFlush, useRelay);
57
+ };
58
+
59
+ /**
60
+ * rm removes all data
61
+ * @param path
62
+ * @returns string: new cid of the root
63
+ */
64
+ export const logout = (
65
+ identity: string,
66
+ storePath: string
67
+ ): Promise<boolean> => {
68
+ return Fula.logout(identity, storePath);
69
+ };
70
+
71
+ /**
72
+ * Checks if there are any un-synced changes on the device
73
+ */
74
+ export const checkFailedActions = (
75
+ retry: boolean = false
76
+ ): Promise<boolean> => {
77
+ return Fula.checkFailedActions(retry);
78
+ };
79
+
80
+ /**
81
+ * Checks if there are any un-synced changes on the device
82
+ */
83
+ export const checkConnection = (): Promise<boolean> => {
84
+ return Fula.checkConnection();
85
+ };
86
+
87
+ /**
88
+ * Get gets the value corresponding to the given key from the local datastore.
89
+ // The key must be a valid ipld.Link.
90
+ * @param key
91
+ * @returns value
92
+ */
93
+ export const get = (key: string): Promise<string> => {
94
+ return Fula.get(key);
95
+ };
96
+
97
+ /**
98
+ * Has checks whether the value corresponding to the given key is present in the local datastore.
99
+ // The key must be a valid ipld.Link.
100
+ * @param key
101
+ * @returns boolean
102
+ */
103
+ export const has = (key: Uint8Array): Promise<boolean> => {
104
+ return Fula.has(key);
105
+ };
106
+
107
+ /**
108
+ * Push requests the given addr to download the root cid from this node.
109
+ // The addr must be a valid multiaddr that includes peer ID.
110
+ // this function.
111
+ * @param addr
112
+ * @returns null or error
113
+ */
114
+ export const push = (): Promise<string> => {
115
+ return Fula.push();
116
+ };
117
+
118
+ /**
119
+ * Put stores the given key value onto the local datastore.
120
+ // The key must be a valid ipld.Link and the value must be the valid encoded ipld.Node corresponding
121
+ // to the given key.
122
+ * @param key, value
123
+ * @returns null or string
124
+ */
125
+ export const put = (value: string, codec: string): Promise<string> => {
126
+ return Fula.put(value, codec);
127
+ };
128
+
129
+ /**
130
+ * mkdir creates a directory at the given path.
131
+ * @param path
132
+ * @returns string: new cid of the root
133
+ */
134
+ export const mkdir = (path: string): Promise<string> => {
135
+ return Fula.mkdir(path);
136
+ };
137
+
138
+ /**
139
+ * writeFileContent writes content at a given path
140
+ * @param path
141
+ * @returns string: new cid of the root
142
+ */
143
+ export const writeFileContent = (
144
+ path: string,
145
+ content: string
146
+ ): Promise<string> => {
147
+ return Fula.writeFileContent(path, content);
148
+ };
149
+
150
+ /*
151
+ // reads content of the file form localFilename (should include full absolute path to local file with read permission
152
+ // writes content to the specified location by fulaTargetFilename in Fula filesystem
153
+ // It keeps the original file modiifcation date
154
+ // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
155
+ // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
156
+ // Returns: new cid of the root after this file is placed in the tree
157
+ */
158
+ export const writeFile = (
159
+ fulaTargetFilename: string,
160
+ localFilename: string
161
+ ): Promise<string> => {
162
+ return Fula.writeFile(fulaTargetFilename, localFilename);
163
+ };
164
+
165
+ /**
166
+ * ls lists the name of files and folders at a given path
167
+ * @param path
168
+ * @returns string: list of items
169
+ * TODO: Findout how is the string and convert to array
170
+ */
171
+ export const ls = (path: string): Promise<void | JSON> => {
172
+ return Fula.ls(path)
173
+ .then((res) => {
174
+ let lsResult = [];
175
+ let lsRows = res.split('!!!');
176
+ for (const element of lsRows) {
177
+ let rowItems = element.split('???');
178
+ if (rowItems && rowItems[0]) {
179
+ let item = {
180
+ name: '',
181
+ created: '',
182
+ modified: '',
183
+ };
184
+ item.name = rowItems[0];
185
+ if (rowItems[1]) {
186
+ item.created = rowItems[1];
187
+ }
188
+ if (rowItems[2]) {
189
+ item.modified = rowItems[2];
190
+ }
191
+ lsResult.push(item);
192
+ }
193
+ }
194
+ let jsonRes = JSON.parse(JSON.stringify(lsResult));
195
+ return jsonRes;
196
+ })
197
+ .catch((e) => {
198
+ return e;
199
+ });
200
+ };
201
+
202
+ /**
203
+ * rm removes all files and folders at a given path
204
+ * @param path
205
+ * @returns string: new cid of the root
206
+ */
207
+ export const rm = (path: string): Promise<string> => {
208
+ return Fula.rm(path);
209
+ };
210
+
211
+ /**
212
+ * cp copies the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
213
+ * @param sourcePath, targetPath
214
+ * @returns string: new cid of the root
215
+ */
216
+ export const cp = (sourcePath: string, targetPath: string): Promise<string> => {
217
+ return Fula.cp(sourcePath, targetPath);
218
+ };
219
+
220
+ /**
221
+ * mv moves the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
222
+ * @param sourcePath, targetPath
223
+ * @returns string: new cid of the root
224
+ */
225
+ export const mv = (sourcePath: string, targetPath: string): Promise<string> => {
226
+ return Fula.mv(sourcePath, targetPath);
227
+ };
228
+
229
+ /*
230
+ // reads content of the file form localFilename (should include full absolute path to local file with read permission
231
+ // writes content to the specified location by fulaTargetFilename in Fula filesystem
232
+ // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
233
+ // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
234
+ // Returns: new cid of the root after this file is placed in the tree
235
+ */
236
+ export const readFile = (
237
+ fulaTargetFilename: string,
238
+ localFilename: string
239
+ ): Promise<string> => {
240
+ return Fula.readFile(fulaTargetFilename, localFilename);
241
+ };
242
+
243
+ /**
244
+ * readFile reads content of a given path
245
+ * @param path
246
+ * @returns string: cotent
247
+ */
248
+ export const readFileContent = (path: string): Promise<string> => {
249
+ return Fula.readFileContent(path);
250
+ };
251
+
252
+ /**
253
+ * Shutdown closes all resources used by Client.
254
+ // After calling this function Client must be discarded.
255
+ * @param
256
+ * @returns
257
+ */
258
+ export const shutdown = (): Promise<void> => {
259
+ return Fula.shutdown();
260
+ };
261
+
262
+ /**
263
+ * setAuth adds or removes a peer from the list of peers that are allowed to push to this node.
264
+ * This can only be called on a peer that is added as an owner of blox by --authorizer parameter
265
+ * @param peerId, allow
266
+ * @returns boolean: true if successful or false if not
267
+ */
268
+ export const setAuth = (
269
+ peerId: string,
270
+ allow: boolean
271
+ ): Promise<boolean> => {
272
+ return Fula.setAuth(peerId, allow);
273
+ };
274
+
275
+
276
+ /**
277
+ * isReady checks if the connection is ready to be used.
278
+ * @param filesystemCheck: also check if the wnfs is ready
279
+ * @returns boolean: true if ready or false if not
280
+ */
281
+ export const isReady = (filesystemCheck: boolean = true): Promise<boolean> => {
282
+ return Fula.isReady(filesystemCheck);
283
+ };
@@ -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
+ }