@functionland/react-native-fula 0.4.2 → 1.0.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 (51) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +133 -100
  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.lock +0 -0
  9. package/android/.gradle/7.5.1/fileChanges/last-build.bin +0 -0
  10. package/android/.gradle/7.5.1/fileHashes/fileHashes.bin +0 -0
  11. package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
  12. package/android/.gradle/7.5.1/fileHashes/resourceHashesCache.bin +0 -0
  13. package/android/.gradle/7.5.1/gc.properties +0 -0
  14. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  15. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  16. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  17. package/android/.gradle/vcs-1/gc.properties +0 -0
  18. package/android/.idea/compiler.xml +5 -5
  19. package/android/.idea/gradle.xml +17 -18
  20. package/android/.idea/jarRepositories.xml +44 -49
  21. package/android/.idea/misc.xml +9 -9
  22. package/android/.idea/vcs.xml +5 -5
  23. package/android/build.gradle +69 -67
  24. package/android/gradle/wrapper/gradle-wrapper.properties +1 -0
  25. package/android/gradlew +375 -240
  26. package/android/local.properties +8 -8
  27. package/android/src/main/AndroidManifest.xml +4 -4
  28. package/android/src/main/java/land/fx/fula/ConfigRef.java +7 -7
  29. package/android/src/main/java/land/fx/fula/Cryptography.java +47 -47
  30. package/android/src/main/java/land/fx/fula/FulaModule.java +701 -480
  31. package/android/src/main/java/land/fx/fula/FulaPackage.java +32 -32
  32. package/android/src/main/java/land/fx/fula/SharedPreferenceHelper.java +65 -65
  33. package/android/src/main/java/land/fx/fula/StaticHelper.java +13 -13
  34. package/android/src/main/java/land/fx/fula/ThreadUtils.java +42 -42
  35. package/ios/FulaModule.h +10 -10
  36. package/ios/FulaModule.m +149 -149
  37. package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
  38. package/lib/commonjs/protocols/fula.js +127 -70
  39. package/lib/commonjs/protocols/fula.js.map +1 -1
  40. package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
  41. package/lib/module/protocols/fula.js +122 -68
  42. package/lib/module/protocols/fula.js.map +1 -1
  43. package/lib/typescript/index.d.ts +1 -1
  44. package/lib/typescript/interfaces/fulaNativeModule.d.ts +28 -20
  45. package/lib/typescript/protocols/fula.d.ts +99 -77
  46. package/package.json +149 -152
  47. package/react-native-fula.podspec +19 -19
  48. package/src/interfaces/fulaNativeModule.ts +52 -42
  49. package/src/protocols/fula.ts +212 -138
  50. package/android/.gradle/7.5.1/executionHistory/executionHistory.bin +0 -0
  51. package/android/.gradle/file-system.probe +0 -0
@@ -1,42 +1,52 @@
1
- import { NativeModules, Platform } from 'react-native';
2
-
3
- interface FulaNativeModule {
4
- init: (
5
- identity: string | null, //Private key of did identity
6
- storePath: string | null, //You can leave empty
7
- bloxAddr: string, //Blox multiadddr needs to be manually entered now
8
- exchange: string //set to 'noope' for testing
9
- ) => Promise<[string, string, string]>;
10
- get: (key: string) => Promise<string>;
11
- has: (key: Uint8Array) => Promise<boolean>;
12
- push: () => Promise<string>;
13
- put: (content: string, codec: string) => Promise<string>;
14
- mkdir: (path: string) => Promise<string>;
15
- writeFileContent: (path: string, content: string) => Promise<string>;
16
- writeFile: (fulaTargetFilename: string, localFilename: string) => Promise<string>;
17
- ls: (path: string) => Promise<string>;
18
- rm: (path: string) => Promise<string>;
19
- readFile: (fulaTargetFilename: string, localFilename: string) => Promise<string>;
20
- readFileContent: (path: string) => Promise<string>;
21
-
22
- shutdown: () => Promise<void>;
23
- }
24
-
25
- const LINKING_ERROR =
26
- `The package 'react-native-fula' doesn't seem to be linked. Make sure: \n\n` +
27
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
28
- '- You rebuilt the app after installing the package\n' +
29
- '- You are not using Expo managed workflow\n';
30
-
31
- const Fula = NativeModules.FulaModule
32
- ? NativeModules.FulaModule
33
- : new Proxy(
34
- {},
35
- {
36
- get() {
37
- throw new Error(LINKING_ERROR);
38
- },
39
- }
40
- );
41
-
42
- export default Fula as FulaNativeModule;
1
+ import { NativeModules, Platform } from 'react-native';
2
+
3
+ interface FulaNativeModule {
4
+ init: (
5
+ identity: string, //Private key of did identity
6
+ storePath: string, //You can leave empty
7
+ bloxAddr: string, //Blox multiadddr needs to be manually entered now
8
+ exchange: string, //set to 'noope' for testing
9
+ rootCid: string | null //if you have the latest rootCid you can send it and it generates the private_ref for filesystem
10
+ ) => Promise<{ peerId: string; rootCid: string; private_ref: string }>;
11
+ logout: (identity: string, storePath: string) => Promise<boolean>;
12
+ get: (key: string) => Promise<string>;
13
+ has: (key: Uint8Array) => Promise<boolean>;
14
+ push: () => Promise<string>;
15
+ put: (content: string, codec: string) => Promise<string>;
16
+ mkdir: (path: string) => Promise<string>;
17
+ writeFileContent: (path: string, content: string) => Promise<string>;
18
+ writeFile: (
19
+ fulaTargetFilename: string,
20
+ localFilename: string
21
+ ) => Promise<string>;
22
+ ls: (path: string) => Promise<string>;
23
+ rm: (path: string) => Promise<string>;
24
+ cp: (sourcePath: string, targetPath: string) => Promise<string>;
25
+ mv: (sourcePath: string, targetPath: string) => Promise<string>;
26
+ readFile: (
27
+ fulaTargetFilename: string,
28
+ localFilename: string
29
+ ) => Promise<string>;
30
+ readFileContent: (path: string) => Promise<string>;
31
+
32
+ shutdown: () => Promise<void>;
33
+ }
34
+
35
+ const LINKING_ERROR =
36
+ `The package 'react-native-fula' doesn't seem to be linked. Make sure: \n\n` +
37
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
38
+ '- You rebuilt the app after installing the package\n' +
39
+ '- You are not using Expo managed workflow\n';
40
+
41
+ const Fula = NativeModules.FulaModule
42
+ ? NativeModules.FulaModule
43
+ : new Proxy(
44
+ {},
45
+ {
46
+ get() {
47
+ throw new Error(LINKING_ERROR);
48
+ },
49
+ }
50
+ );
51
+
52
+ export default Fula as FulaNativeModule;
@@ -1,138 +1,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
- ): Promise<[string, string, string]> => {
16
- console.log('init in react-native started',identity, storePath, bloxAddr, exchange);
17
- return Fula.init(identity, storePath, bloxAddr, exchange);
18
- };
19
-
20
- /**
21
- * Get gets the value corresponding to the given key from the local datastore.
22
- // The key must be a valid ipld.Link.
23
- * @param key
24
- * @returns value
25
- */
26
- export const get = (key: string): Promise<string> => {
27
- return Fula.get(key);
28
- };
29
-
30
- /**
31
- * Has checks whether the value corresponding to the given key is present in the local datastore.
32
- // The key must be a valid ipld.Link.
33
- * @param key
34
- * @returns boolean
35
- */
36
- export const has = (key: Uint8Array): Promise<boolean> => {
37
- return Fula.has(key);
38
- };
39
-
40
- /**
41
- * Push requests the given addr to download the root cid from this node.
42
- // The addr must be a valid multiaddr that includes peer ID.
43
- // this function.
44
- * @param addr
45
- * @returns null or error
46
- */
47
- export const push = (): Promise<string> => {
48
- return Fula.push();
49
- };
50
-
51
- /**
52
- * Put stores the given key value onto the local datastore.
53
- // The key must be a valid ipld.Link and the value must be the valid encoded ipld.Node corresponding
54
- // to the given key.
55
- * @param key, value
56
- * @returns null or string
57
- */
58
- export const put = (value: string, codec: string): Promise<string> => {
59
- return Fula.put(value, codec);
60
- };
61
-
62
- /**
63
- * mkdir creates a directory at the given path.
64
- * @param path
65
- * @returns string: new cid of the root
66
- */
67
- export const mkdir = (path: string): Promise<string> => {
68
- return Fula.mkdir(path);
69
- };
70
-
71
- /**
72
- * writeFileContent writes content at a given path
73
- * @param path
74
- * @returns string: new cid of the root
75
- */
76
- export const writeFileContent = (path: string, content: string): Promise<string> => {
77
- return Fula.writeFileContent(path, content);
78
- };
79
-
80
- /*
81
- // reads content of the file form localFilename (should include full absolute path to local file with read permission
82
- // writes content to the specified location by fulaTargetFilename in Fula filesystem
83
- // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
84
- // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
85
- // Returns: new cid of the root after this file is placed in the tree
86
- */
87
- export const writeFile = (fulaTargetFilename: string, localFilename: string): Promise<string> => {
88
- return Fula.writeFile(fulaTargetFilename, localFilename);
89
- };
90
-
91
- /**
92
- * ls lists the name of files and folders at a given path
93
- * @param path
94
- * @returns string: list of items
95
- * TODO: Findout how is the string and convert to array
96
- */
97
- export const ls = (path: string): Promise<string> => {
98
- return Fula.ls(path);
99
- };
100
-
101
- /**
102
- * rm removes all files and folders at a given path
103
- * @param path
104
- * @returns string: new cid of the root
105
- */
106
- export const rm = (path: string): Promise<string> => {
107
- return Fula.rm(path);
108
- };
109
-
110
- /*
111
- // reads content of the file form localFilename (should include full absolute path to local file with read permission
112
- // writes content to the specified location by fulaTargetFilename in Fula filesystem
113
- // fulaTargetFilename: a string including full path and filename of target file on Fula (e.g. root/pictures/cat.jpg)
114
- // localFilename: a string containing full path and filename of local file on hte device (e.g /usr/bin/cat.jpg)
115
- // Returns: new cid of the root after this file is placed in the tree
116
- */
117
- export const readFile = (fulaTargetFilename: string, localFilename: string): Promise<string> => {
118
- return Fula.readFile(fulaTargetFilename, localFilename);
119
- };
120
-
121
- /**
122
- * readFile reads content of a given path
123
- * @param path
124
- * @returns string: cotent
125
- */
126
- export const readFileContent = (path: string): Promise<string> => {
127
- return Fula.readFileContent(path);
128
- };
129
-
130
- /**
131
- * Shutdown closes all resources used by Client.
132
- // After calling this function Client must be discarded.
133
- * @param
134
- * @returns
135
- */
136
- export const shutdown = (): Promise<void> => {
137
- return Fula.shutdown();
138
- };
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
+ };
Binary file