@functionland/react-native-fula 1.14.7 → 1.19.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 (141) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +226 -214
  3. package/android/build.gradle +110 -110
  4. package/android/gradle.properties +5 -5
  5. package/android/src/main/AndroidManifest.xml +3 -3
  6. package/android/src/main/AndroidManifestNew.xml +2 -2
  7. package/android/src/main/java/land/fx/fula/ConfigRef.java +7 -7
  8. package/android/src/main/java/land/fx/fula/Cryptography.java +62 -62
  9. package/android/src/main/java/land/fx/fula/FulaModule.java +1435 -1466
  10. package/android/src/main/java/land/fx/fula/FulaPackage.java +32 -32
  11. package/android/src/main/java/land/fx/fula/SharedPreferenceHelper.java +65 -65
  12. package/android/src/main/java/land/fx/fula/StaticHelper.java +13 -13
  13. package/android/src/main/java/land/fx/fula/ThreadUtils.java +42 -42
  14. package/ios/Cryptography.swift +49 -49
  15. package/ios/Fula-Bridging-Header.h +3 -3
  16. package/ios/Fula.mm +197 -199
  17. package/ios/Fula.swift +1221 -1221
  18. package/ios/UserDataHelper.swift +143 -143
  19. package/lib/commonjs/index.js +2 -2
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/commonjs/interfaces/augment-api-errors.js +4 -0
  22. package/lib/commonjs/interfaces/augment-api-errors.js.map +1 -0
  23. package/lib/commonjs/interfaces/augment-api-rpc.js +4 -0
  24. package/lib/commonjs/interfaces/augment-api-rpc.js.map +1 -0
  25. package/lib/commonjs/interfaces/augment-api-runtime.js +4 -0
  26. package/lib/commonjs/interfaces/augment-api-runtime.js.map +1 -0
  27. package/lib/commonjs/interfaces/augment-api.js +10 -0
  28. package/lib/commonjs/interfaces/augment-api.js.map +1 -0
  29. package/lib/commonjs/interfaces/augment-types.js +4 -0
  30. package/lib/commonjs/interfaces/augment-types.js.map +1 -0
  31. package/lib/commonjs/interfaces/fulaNativeModule.js +1 -2
  32. package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
  33. package/lib/commonjs/interfaces/index.js +6 -0
  34. package/lib/commonjs/interfaces/index.js.map +1 -0
  35. package/lib/commonjs/interfaces/{api-lookup.js → lookup.js} +623 -382
  36. package/lib/commonjs/interfaces/lookup.js.map +1 -0
  37. package/lib/commonjs/interfaces/registry.js +4 -0
  38. package/lib/commonjs/interfaces/registry.js.map +1 -0
  39. package/lib/commonjs/interfaces/types-lookup.js +4 -0
  40. package/lib/commonjs/interfaces/types-lookup.js.map +1 -0
  41. package/lib/commonjs/interfaces/types.js +4 -0
  42. package/lib/commonjs/interfaces/types.js.map +1 -0
  43. package/lib/commonjs/protocols/blockchain.js +123 -76
  44. package/lib/commonjs/protocols/blockchain.js.map +1 -1
  45. package/lib/commonjs/protocols/chain-api.js +151 -37
  46. package/lib/commonjs/protocols/chain-api.js.map +1 -1
  47. package/lib/commonjs/protocols/fula.js +195 -99
  48. package/lib/commonjs/protocols/fula.js.map +1 -1
  49. package/lib/commonjs/protocols/fxblox.js +3 -3
  50. package/lib/commonjs/protocols/fxblox.js.map +1 -1
  51. package/lib/commonjs/types/blockchain.js.map +1 -1
  52. package/lib/commonjs/types/fxblox.js.map +1 -1
  53. package/lib/module/index.js.map +1 -1
  54. package/lib/module/interfaces/augment-api-errors.js +9 -0
  55. package/lib/module/interfaces/augment-api-errors.js.map +1 -0
  56. package/lib/module/interfaces/augment-api-rpc.js +9 -0
  57. package/lib/module/interfaces/augment-api-rpc.js.map +1 -0
  58. package/lib/module/interfaces/augment-api-runtime.js +9 -0
  59. package/lib/module/interfaces/augment-api-runtime.js.map +1 -0
  60. package/lib/module/interfaces/augment-api.js +11 -0
  61. package/lib/module/interfaces/augment-api.js.map +1 -0
  62. package/lib/module/interfaces/augment-types.js +9 -0
  63. package/lib/module/interfaces/augment-types.js.map +1 -0
  64. package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
  65. package/lib/module/interfaces/index.js +5 -0
  66. package/lib/module/interfaces/index.js.map +1 -0
  67. package/lib/module/interfaces/{api-lookup.js → lookup.js} +622 -380
  68. package/lib/module/interfaces/lookup.js.map +1 -0
  69. package/lib/module/interfaces/registry.js +9 -0
  70. package/lib/module/interfaces/registry.js.map +1 -0
  71. package/lib/module/interfaces/types-lookup.js +9 -0
  72. package/lib/module/interfaces/types-lookup.js.map +1 -0
  73. package/lib/module/interfaces/types.js +3 -0
  74. package/lib/module/interfaces/types.js.map +1 -0
  75. package/lib/module/protocols/blockchain.js +120 -75
  76. package/lib/module/protocols/blockchain.js.map +1 -1
  77. package/lib/module/protocols/chain-api.js +142 -31
  78. package/lib/module/protocols/chain-api.js.map +1 -1
  79. package/lib/module/protocols/fula.js +191 -99
  80. package/lib/module/protocols/fula.js.map +1 -1
  81. package/lib/module/protocols/fxblox.js +3 -3
  82. package/lib/module/protocols/fxblox.js.map +1 -1
  83. package/lib/module/types/blockchain.js.map +1 -1
  84. package/lib/module/types/fxblox.js.map +1 -1
  85. package/lib/typescript/interfaces/augment-api-errors.d.ts +442 -0
  86. package/lib/typescript/interfaces/augment-api-errors.d.ts.map +1 -0
  87. package/lib/typescript/interfaces/augment-api-rpc.d.ts +680 -0
  88. package/lib/typescript/interfaces/augment-api-rpc.d.ts.map +1 -0
  89. package/lib/typescript/interfaces/augment-api-runtime.d.ts +248 -0
  90. package/lib/typescript/interfaces/augment-api-runtime.d.ts.map +1 -0
  91. package/lib/typescript/interfaces/augment-api.d.ts +8 -0
  92. package/lib/typescript/interfaces/augment-api.d.ts.map +1 -0
  93. package/lib/typescript/interfaces/augment-types.d.ts +1224 -0
  94. package/lib/typescript/interfaces/augment-types.d.ts.map +1 -0
  95. package/lib/typescript/interfaces/fulaNativeModule.d.ts +7 -3
  96. package/lib/typescript/interfaces/fulaNativeModule.d.ts.map +1 -1
  97. package/lib/typescript/interfaces/index.d.ts +1 -0
  98. package/lib/typescript/interfaces/index.d.ts.map +1 -0
  99. package/lib/typescript/interfaces/{api-lookup.d.ts → lookup.d.ts} +441 -199
  100. package/lib/typescript/interfaces/lookup.d.ts.map +1 -0
  101. package/lib/typescript/interfaces/registry.d.ts +146 -0
  102. package/lib/typescript/interfaces/registry.d.ts.map +1 -0
  103. package/lib/typescript/interfaces/types-lookup.d.ts +1910 -0
  104. package/lib/typescript/interfaces/types-lookup.d.ts.map +1 -0
  105. package/lib/typescript/interfaces/types.d.ts +1 -0
  106. package/lib/typescript/interfaces/types.d.ts.map +1 -0
  107. package/lib/typescript/protocols/blockchain.d.ts +5 -3
  108. package/lib/typescript/protocols/blockchain.d.ts.map +1 -1
  109. package/lib/typescript/protocols/chain-api.d.ts +5 -0
  110. package/lib/typescript/protocols/chain-api.d.ts.map +1 -1
  111. package/lib/typescript/protocols/fula.d.ts +16 -0
  112. package/lib/typescript/protocols/fula.d.ts.map +1 -1
  113. package/lib/typescript/types/blockchain.d.ts +6 -0
  114. package/lib/typescript/types/blockchain.d.ts.map +1 -1
  115. package/package.json +178 -172
  116. package/react-native-fula.podspec +47 -47
  117. package/src/index.tsx +4 -4
  118. package/src/interfaces/augment-api-errors.ts +449 -0
  119. package/src/interfaces/augment-api-rpc.ts +617 -0
  120. package/src/interfaces/augment-api-runtime.ts +224 -0
  121. package/src/interfaces/augment-api.ts +10 -0
  122. package/src/interfaces/augment-types.ts +1230 -0
  123. package/src/interfaces/fulaNativeModule.ts +130 -122
  124. package/src/interfaces/index.ts +4 -0
  125. package/src/interfaces/{api-lookup.ts → lookup.ts} +1889 -1647
  126. package/src/interfaces/registry.ts +152 -0
  127. package/src/interfaces/types-lookup.ts +2043 -0
  128. package/src/interfaces/types.ts +3 -0
  129. package/src/protocols/blockchain.ts +549 -504
  130. package/src/protocols/chain-api.ts +148 -24
  131. package/src/protocols/fula.ts +419 -314
  132. package/src/protocols/fxblox.ts +49 -49
  133. package/src/types/blockchain.ts +89 -81
  134. package/src/types/fxblox.ts +8 -8
  135. package/ios/Fula.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  136. package/ios/Fula.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  137. package/ios/Fula.xcodeproj/project.xcworkspace/xcuserdata/user246549.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  138. package/ios/Fula.xcodeproj/xcuserdata/user246549.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  139. package/lib/commonjs/interfaces/api-lookup.js.map +0 -1
  140. package/lib/module/interfaces/api-lookup.js.map +0 -1
  141. package/lib/typescript/interfaces/api-lookup.d.ts.map +0 -1
@@ -1,314 +1,419 @@
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 }> => {
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.initFula(
30
- identity,
31
- storePath,
32
- bloxAddr,
33
- exchange,
34
- autoFlush,
35
- rootCid,
36
- useRelay,
37
- refresh
38
- );
39
- };
40
-
41
- /**
42
- * Get gets the value corresponding to the given key from the local datastore.
43
- // The key must be a valid ipld.Link.
44
- * @param config
45
- * @returns boolean
46
- */
47
-
48
- export const newClient = (
49
- identity: string, //privateKey of did identity
50
- storePath: string,
51
- bloxAddr: string,
52
- exchange: string,
53
- autoFlush: boolean = false,
54
- useRelay: boolean = true,
55
- refresh: boolean = false
56
- ): Promise<string> => {
57
- console.log(
58
- 'newClient in react-native started',
59
- identity,
60
- storePath,
61
- bloxAddr,
62
- exchange,
63
- autoFlush,
64
- useRelay,
65
- refresh
66
- );
67
- return Fula.newClient(
68
- identity,
69
- storePath,
70
- bloxAddr,
71
- exchange,
72
- autoFlush,
73
- useRelay,
74
- refresh
75
- );
76
- };
77
-
78
- /**
79
- * rm removes all data
80
- * @param path
81
- * @returns string: new cid of the root
82
- */
83
- export const logout = (
84
- identity: string,
85
- storePath: string
86
- ): Promise<boolean> => {
87
- return Fula.logout(identity, storePath);
88
- };
89
-
90
- /**
91
- * Checks if there are any un-synced changes on the device
92
- */
93
- export const checkFailedActions = (
94
- retry: boolean = false,
95
- timeout: number = 20
96
- ): Promise<boolean> => {
97
- return Fula.checkFailedActions(retry, timeout);
98
- };
99
-
100
- /**
101
- * Lists the cids that failed to be sent to backend and are kept only locally
102
- */
103
- export const listFailedActions = (cids: string[] = []): Promise<string[]> => {
104
- return Fula.listFailedActions(cids);
105
- };
106
-
107
- /**
108
- * Checks if there are any un-synced changes on the device
109
- */
110
- export const checkConnection = (timeout: number = 20): Promise<boolean> => {
111
- return Fula.checkConnection(timeout);
112
- };
113
-
114
- /**
115
- * Get gets the value corresponding to the given key from the local datastore.
116
- // The key must be a valid ipld.Link.
117
- * @param key
118
- * @returns value
119
- */
120
- export const get = (key: string): Promise<string> => {
121
- return Fula.get(key);
122
- };
123
-
124
- /**
125
- * Has checks whether the value corresponding to the given key is present in the local datastore.
126
- // The key must be a valid ipld.Link.
127
- * @param key
128
- * @returns boolean
129
- */
130
- export const has = (key: Uint8Array): Promise<boolean> => {
131
- return Fula.has(key);
132
- };
133
-
134
- /**
135
- * Push requests the given addr to download the root cid from this node.
136
- // The addr must be a valid multiaddr that includes peer ID.
137
- // this function.
138
- * @param addr
139
- * @returns null or error
140
- */
141
- export const push = (): Promise<string> => {
142
- return Fula.push();
143
- };
144
-
145
- //This method sends some test data to backedn
146
- export const testData = (
147
- identity: string,
148
- bloxAddr: string
149
- ): Promise<string> => {
150
- return Fula.testData(identity, bloxAddr);
151
- };
152
-
153
- /**
154
- * Put stores the given key value onto the local datastore.
155
- // The key must be a valid ipld.Link and the value must be the valid encoded ipld.Node corresponding
156
- // to the given key.
157
- * @param key, value
158
- * @returns null or string
159
- */
160
- export const put = (value: string, codec: string): Promise<string> => {
161
- return Fula.put(value, codec);
162
- };
163
-
164
- /**
165
- * mkdir creates a directory at the given path.
166
- * @param path
167
- * @returns string: new cid of the root
168
- */
169
- export const mkdir = (path: string): Promise<string> => {
170
- return Fula.mkdir(path);
171
- };
172
-
173
- /**
174
- * writeFileContent writes content at a given path
175
- * @param path
176
- * @returns string: new cid of the root
177
- */
178
- export const writeFileContent = (
179
- path: string,
180
- content: string
181
- ): Promise<string> => {
182
- return Fula.writeFileContent(path, content);
183
- };
184
-
185
- /*
186
- // reads content of the file form localFilename (should include full absolute path to local file with read permission
187
- // writes content to the specified location by fulaTargetFilename in Fula filesystem
188
- // It keeps the original file modiifcation date
189
- // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
190
- // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
191
- // Returns: new cid of the root after this file is placed in the tree
192
- */
193
- export const writeFile = (
194
- fulaTargetFilename: string,
195
- localFilename: string
196
- ): Promise<string> => {
197
- return Fula.writeFile(fulaTargetFilename, localFilename);
198
- };
199
-
200
- /**
201
- * ls lists the name of files and folders at a given path
202
- * @param path
203
- * @returns string: list of items
204
- * TODO: Findout how is the string and convert to array
205
- */
206
- export const ls = (path: string): Promise<void | JSON> => {
207
- return Fula.ls(path)
208
- .then((res) => {
209
- let lsResult = [];
210
- let lsRows = res.split('!!!');
211
- for (const element of lsRows) {
212
- let rowItems = element.split('???');
213
- if (rowItems && rowItems[0]) {
214
- let item = {
215
- name: '',
216
- created: '',
217
- modified: '',
218
- };
219
- item.name = rowItems[0];
220
- if (rowItems[1]) {
221
- item.created = rowItems[1];
222
- }
223
- if (rowItems[2]) {
224
- item.modified = rowItems[2];
225
- }
226
- lsResult.push(item);
227
- }
228
- }
229
- let jsonRes = JSON.parse(JSON.stringify(lsResult));
230
- return jsonRes;
231
- })
232
- .catch((e) => {
233
- return e;
234
- });
235
- };
236
-
237
- /**
238
- * rm removes all files and folders at a given path
239
- * @param path
240
- * @returns string: new cid of the root
241
- */
242
- export const rm = (path: string): Promise<string> => {
243
- return Fula.rm(path);
244
- };
245
-
246
- /**
247
- * cp copies the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
248
- * @param sourcePath, targetPath
249
- * @returns string: new cid of the root
250
- */
251
- export const cp = (sourcePath: string, targetPath: string): Promise<string> => {
252
- return Fula.cp(sourcePath, targetPath);
253
- };
254
-
255
- /**
256
- * mv moves the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
257
- * @param sourcePath, targetPath
258
- * @returns string: new cid of the root
259
- */
260
- export const mv = (sourcePath: string, targetPath: string): Promise<string> => {
261
- return Fula.mv(sourcePath, targetPath);
262
- };
263
-
264
- /*
265
- // reads content of the file form localFilename (should include full absolute path to local file with read permission
266
- // writes content to the specified location by fulaTargetFilename in Fula filesystem
267
- // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
268
- // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
269
- // Returns: new cid of the root after this file is placed in the tree
270
- */
271
- export const readFile = (
272
- fulaTargetFilename: string,
273
- localFilename: string
274
- ): Promise<string> => {
275
- return Fula.readFile(fulaTargetFilename, localFilename);
276
- };
277
-
278
- /**
279
- * readFile reads content of a given path
280
- * @param path
281
- * @returns string: cotent
282
- */
283
- export const readFileContent = (path: string): Promise<string> => {
284
- return Fula.readFileContent(path);
285
- };
286
-
287
- /**
288
- * Shutdown closes all resources used by Client.
289
- // After calling this function Client must be discarded.
290
- * @param
291
- * @returns
292
- */
293
- export const shutdown = (): Promise<void> => {
294
- return Fula.shutdown();
295
- };
296
-
297
- /**
298
- * setAuth adds or removes a peer from the list of peers that are allowed to push to this node.
299
- * This can only be called on a peer that is added as an owner of blox by --authorizer parameter
300
- * @param peerId, allow
301
- * @returns boolean: true if successful or false if not
302
- */
303
- export const setAuth = (peerId: string, allow: boolean): Promise<boolean> => {
304
- return Fula.setAuth(peerId, allow);
305
- };
306
-
307
- /**
308
- * isReady checks if the connection is ready to be used.
309
- * @param filesystemCheck: also check if the wnfs is ready
310
- * @returns boolean: true if ready or false if not
311
- */
312
- export const isReady = (filesystemCheck: boolean = true): Promise<boolean> => {
313
- return Fula.isReady(filesystemCheck);
314
- };
1
+ import Fula from '../interfaces/fulaNativeModule';
2
+ import {
3
+ init as chainApiInit,
4
+ batchUploadManifest,
5
+ checkAccountBalance,
6
+ getAccountIdFromSeed,
7
+ } from './chain-api';
8
+ import { ApiPromise } from '@polkadot/api';
9
+
10
+ /**
11
+ * Get gets the value corresponding to the given key from the local datastore.
12
+ // The key must be a valid ipld.Link.
13
+ * @param config
14
+ * @returns boolean
15
+ */
16
+
17
+ export const init = (
18
+ identity: string, //privateKey of did identity
19
+ storePath: string,
20
+ bloxAddr: string,
21
+ exchange: string,
22
+ autoFlush: boolean = false,
23
+ rootCid: string | null = null,
24
+ useRelay: boolean = true,
25
+ refresh: boolean = false
26
+ ): Promise<{ peerId: string; rootCid: string }> => {
27
+ console.log(
28
+ 'init in react-native started',
29
+ identity,
30
+ storePath,
31
+ bloxAddr,
32
+ exchange,
33
+ autoFlush,
34
+ useRelay
35
+ );
36
+ return Fula.initFula(
37
+ identity,
38
+ storePath,
39
+ bloxAddr,
40
+ exchange,
41
+ autoFlush,
42
+ rootCid,
43
+ useRelay,
44
+ refresh
45
+ );
46
+ };
47
+
48
+ /**
49
+ * Get gets the value corresponding to the given key from the local datastore.
50
+ // The key must be a valid ipld.Link.
51
+ * @param config
52
+ * @returns boolean
53
+ */
54
+
55
+ export const newClient = (
56
+ identity: string, //privateKey of did identity
57
+ storePath: string,
58
+ bloxAddr: string,
59
+ exchange: string,
60
+ autoFlush: boolean = false,
61
+ useRelay: boolean = true,
62
+ refresh: boolean = false
63
+ ): Promise<string> => {
64
+ console.log(
65
+ 'newClient in react-native started',
66
+ identity,
67
+ storePath,
68
+ bloxAddr,
69
+ exchange,
70
+ autoFlush,
71
+ useRelay,
72
+ refresh
73
+ );
74
+ return Fula.newClient(
75
+ identity,
76
+ storePath,
77
+ bloxAddr,
78
+ exchange,
79
+ autoFlush,
80
+ useRelay,
81
+ refresh
82
+ );
83
+ };
84
+
85
+ /**
86
+ * rm removes all data
87
+ * @param path
88
+ * @returns string: new cid of the root
89
+ */
90
+ export const logout = (
91
+ identity: string,
92
+ storePath: string
93
+ ): Promise<boolean> => {
94
+ return Fula.logout(identity, storePath);
95
+ };
96
+
97
+ /**
98
+ * Checks if there are any un-synced changes on the device
99
+ */
100
+ export const checkFailedActions = (
101
+ retry: boolean = false,
102
+ timeout: number = 20
103
+ ): Promise<boolean> => {
104
+ return Fula.checkFailedActions(retry, timeout);
105
+ };
106
+
107
+ /**
108
+ * Lists the cids that failed to be sent to backend and are kept only locally
109
+ */
110
+ export const listFailedActions = (cids: string[] = []): Promise<string[]> => {
111
+ return Fula.listFailedActions(cids);
112
+ };
113
+
114
+ /**
115
+ * Lists the cids that are recent
116
+ */
117
+ export const listRecentCidsAsString = (): Promise<string[]> => {
118
+ return Fula.listRecentCidsAsString();
119
+ };
120
+
121
+ /**
122
+ * Clears the cids that ar recent
123
+ */
124
+ export const clearCidsFromRecent = (cids: string[] = []): Promise<boolean> => {
125
+ return Fula.clearCidsFromRecent(cids);
126
+ };
127
+
128
+ /**
129
+ * Checks if there are any un-synced changes on the device
130
+ */
131
+ export const checkConnection = (timeout: number = 20): Promise<boolean> => {
132
+ return Fula.checkConnection(timeout);
133
+ };
134
+
135
+ /**
136
+ * Get gets the value corresponding to the given key from the local datastore.
137
+ // The key must be a valid ipld.Link.
138
+ * @param key
139
+ * @returns value
140
+ */
141
+ export const get = (key: string): Promise<string> => {
142
+ return Fula.get(key);
143
+ };
144
+
145
+ /**
146
+ * Has checks whether the value corresponding to the given key is present in the local datastore.
147
+ // The key must be a valid ipld.Link.
148
+ * @param key
149
+ * @returns boolean
150
+ */
151
+ export const has = (key: Uint8Array): Promise<boolean> => {
152
+ return Fula.has(key);
153
+ };
154
+
155
+ /**
156
+ * Push requests the given addr to download the root cid from this node.
157
+ // The addr must be a valid multiaddr that includes peer ID.
158
+ // this function.
159
+ * @param addr
160
+ * @returns null or error
161
+ */
162
+ export const push = (): Promise<string> => {
163
+ return Fula.push();
164
+ };
165
+
166
+ //This method sends some test data to backedn
167
+ export const testData = (
168
+ identity: string,
169
+ bloxAddr: string
170
+ ): Promise<string> => {
171
+ return Fula.testData(identity, bloxAddr);
172
+ };
173
+
174
+ /**
175
+ * Put stores the given key value onto the local datastore.
176
+ // The key must be a valid ipld.Link and the value must be the valid encoded ipld.Node corresponding
177
+ // to the given key.
178
+ * @param key, value
179
+ * @returns null or string
180
+ */
181
+ export const put = (value: string, codec: string): Promise<string> => {
182
+ return Fula.put(value, codec);
183
+ };
184
+
185
+ /**
186
+ * mkdir creates a directory at the given path.
187
+ * @param path
188
+ * @returns string: new cid of the root
189
+ */
190
+ export const mkdir = (path: string): Promise<string> => {
191
+ return Fula.mkdir(path);
192
+ };
193
+
194
+ /**
195
+ * writeFileContent writes content at a given path
196
+ * @param path
197
+ * @returns string: new cid of the root
198
+ */
199
+ export const writeFileContent = (
200
+ path: string,
201
+ content: string
202
+ ): Promise<string> => {
203
+ return Fula.writeFileContent(path, content);
204
+ };
205
+
206
+ /*
207
+ // reads content of the file form localFilename (should include full absolute path to local file with read permission
208
+ // writes content to the specified location by fulaTargetFilename in Fula filesystem
209
+ // It keeps the original file modiifcation date
210
+ // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
211
+ // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
212
+ // Returns: new cid of the root after this file is placed in the tree
213
+ */
214
+ export const writeFile = (
215
+ fulaTargetFilename: string,
216
+ localFilename: string
217
+ ): Promise<string> => {
218
+ return Fula.writeFile(fulaTargetFilename, localFilename);
219
+ };
220
+
221
+ /**
222
+ * ls lists the name of files and folders at a given path
223
+ * @param path
224
+ * @returns string: list of items
225
+ * TODO: Findout how is the string and convert to array
226
+ */
227
+ export const ls = (path: string): Promise<void | JSON> => {
228
+ return Fula.ls(path)
229
+ .then((res) => {
230
+ let lsResult = [];
231
+ let lsRows = res.split('!!!');
232
+ for (const element of lsRows) {
233
+ let rowItems = element.split('???');
234
+ if (rowItems && rowItems[0]) {
235
+ let item = {
236
+ name: '',
237
+ created: '',
238
+ modified: '',
239
+ };
240
+ item.name = rowItems[0];
241
+ if (rowItems[1]) {
242
+ item.created = rowItems[1];
243
+ }
244
+ if (rowItems[2]) {
245
+ item.modified = rowItems[2];
246
+ }
247
+ lsResult.push(item);
248
+ }
249
+ }
250
+ let jsonRes = JSON.parse(JSON.stringify(lsResult));
251
+ return jsonRes;
252
+ })
253
+ .catch((e) => {
254
+ return e;
255
+ });
256
+ };
257
+
258
+ /**
259
+ * rm removes all files and folders at a given path
260
+ * @param path
261
+ * @returns string: new cid of the root
262
+ */
263
+ export const rm = (path: string): Promise<string> => {
264
+ return Fula.rm(path);
265
+ };
266
+
267
+ /**
268
+ * cp copies the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
269
+ * @param sourcePath, targetPath
270
+ * @returns string: new cid of the root
271
+ */
272
+ export const cp = (sourcePath: string, targetPath: string): Promise<string> => {
273
+ return Fula.cp(sourcePath, targetPath);
274
+ };
275
+
276
+ /**
277
+ * mv moves the file or folder at the sourcePath to targetPath. targetPath is a folder that must exist already
278
+ * @param sourcePath, targetPath
279
+ * @returns string: new cid of the root
280
+ */
281
+ export const mv = (sourcePath: string, targetPath: string): Promise<string> => {
282
+ return Fula.mv(sourcePath, targetPath);
283
+ };
284
+
285
+ /*
286
+ // reads content of the file form localFilename (should include full absolute path to local file with read permission
287
+ // writes content to the specified location by fulaTargetFilename in Fula filesystem
288
+ // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
289
+ // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
290
+ // Returns: new cid of the root after this file is placed in the tree
291
+ */
292
+ export const readFile = (
293
+ fulaTargetFilename: string,
294
+ localFilename: string
295
+ ): Promise<string> => {
296
+ return Fula.readFile(fulaTargetFilename, localFilename);
297
+ };
298
+
299
+ /**
300
+ * readFile reads content of a given path
301
+ * @param path
302
+ * @returns string: cotent
303
+ */
304
+ export const readFileContent = (path: string): Promise<string> => {
305
+ return Fula.readFileContent(path);
306
+ };
307
+
308
+ /**
309
+ * Shutdown closes all resources used by Client.
310
+ // After calling this function Client must be discarded.
311
+ * @param
312
+ * @returns
313
+ */
314
+ export const shutdown = (): Promise<void> => {
315
+ return Fula.shutdown();
316
+ };
317
+
318
+ /**
319
+ * setAuth adds or removes a peer from the list of peers that are allowed to push to this node.
320
+ * This can only be called on a peer that is added as an owner of blox by --authorizer parameter
321
+ * @param peerId, allow
322
+ * @returns boolean: true if successful or false if not
323
+ */
324
+ export const setAuth = (peerId: string, allow: boolean): Promise<boolean> => {
325
+ return Fula.setAuth(peerId, allow);
326
+ };
327
+
328
+ /**
329
+ * isReady checks if the connection is ready to be used.
330
+ * @param filesystemCheck: also check if the wnfs is ready
331
+ * @returns boolean: true if ready or false if not
332
+ */
333
+ export const isReady = (filesystemCheck: boolean = true): Promise<boolean> => {
334
+ return Fula.isReady(filesystemCheck);
335
+ };
336
+
337
+ /**
338
+ * replicate replicates data on the nework
339
+ */
340
+ export const replicateRecentCids = async (
341
+ api: ApiPromise,
342
+ seed: string,
343
+ poolId: number,
344
+ replicationNo: number = 4
345
+ ): Promise<{ status: boolean; msg: string }> => {
346
+ let status = true;
347
+ let msg = '';
348
+ if (!api) {
349
+ api = await chainApiInit();
350
+ }
351
+ if (api) {
352
+ console.log('uploading manifests');
353
+ try {
354
+ let account = await getAccountIdFromSeed(seed);
355
+ console.log('account: ' + account);
356
+ const accountBal = await checkAccountBalance(api, account);
357
+ console.log('account balance: ' + accountBal);
358
+ if (accountBal !== '0') {
359
+ const recentCids = await listRecentCidsAsString();
360
+ console.log(recentCids);
361
+ if (recentCids) {
362
+ console.log({
363
+ api,
364
+ seed,
365
+ recentCids,
366
+ poolId,
367
+ replicationNo,
368
+ });
369
+ const res = await batchUploadManifest(
370
+ api,
371
+ seed,
372
+ recentCids,
373
+ poolId,
374
+ replicationNo
375
+ );
376
+ console.log('batchUploadManifest res received');
377
+ console.log(res);
378
+ if (res && res.hash) {
379
+ const signedBlock = await api.rpc.chain.getBlock(res.hash);
380
+ if (signedBlock?.block?.extrinsics?.length) {
381
+ await clearCidsFromRecent(recentCids);
382
+ msg = res.hash;
383
+ } else {
384
+ status = false;
385
+ msg = 'block data is not found';
386
+ }
387
+ } else {
388
+ status = false;
389
+ msg = 'hash is not returned';
390
+ }
391
+ } else {
392
+ status = false;
393
+ msg = 'No recent Cids found';
394
+ }
395
+ } else {
396
+ status = false;
397
+ msg = 'Account balance is not enough or account does not exists';
398
+ }
399
+ } catch (e: any) {
400
+ console.log('res failed');
401
+ console.log(e);
402
+ let errorMessage = '';
403
+
404
+ if (e instanceof Error) {
405
+ // If it's an Error instance, use the message property
406
+ errorMessage = e.message;
407
+ } else {
408
+ // If it's not an Error instance, convert it to string
409
+ errorMessage = e.toString();
410
+ }
411
+ status = false;
412
+ msg = errorMessage;
413
+ }
414
+ }
415
+
416
+ // Return a value (true/false) depending on the outcome of the function
417
+ // For example:
418
+ return { status: status, msg: msg }; // or false, depending on your logic
419
+ };