@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.
- package/LICENSE +21 -21
- package/README.md +133 -100
- package/android/.gradle/7.5.1/checksums/checksums.lock +0 -0
- package/android/.gradle/7.5.1/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/7.5.1/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.5.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.5.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.5.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.5.1/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.5.1/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/7.5.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/compiler.xml +5 -5
- package/android/.idea/gradle.xml +17 -18
- package/android/.idea/jarRepositories.xml +44 -49
- package/android/.idea/misc.xml +9 -9
- package/android/.idea/vcs.xml +5 -5
- package/android/build.gradle +69 -67
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -0
- package/android/gradlew +375 -240
- package/android/local.properties +8 -8
- package/android/src/main/AndroidManifest.xml +4 -4
- package/android/src/main/java/land/fx/fula/ConfigRef.java +7 -7
- package/android/src/main/java/land/fx/fula/Cryptography.java +47 -47
- package/android/src/main/java/land/fx/fula/FulaModule.java +701 -480
- package/android/src/main/java/land/fx/fula/FulaPackage.java +32 -32
- package/android/src/main/java/land/fx/fula/SharedPreferenceHelper.java +65 -65
- package/android/src/main/java/land/fx/fula/StaticHelper.java +13 -13
- package/android/src/main/java/land/fx/fula/ThreadUtils.java +42 -42
- package/ios/FulaModule.h +10 -10
- package/ios/FulaModule.m +149 -149
- package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
- package/lib/commonjs/protocols/fula.js +127 -70
- package/lib/commonjs/protocols/fula.js.map +1 -1
- package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
- package/lib/module/protocols/fula.js +122 -68
- package/lib/module/protocols/fula.js.map +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/interfaces/fulaNativeModule.d.ts +28 -20
- package/lib/typescript/protocols/fula.d.ts +99 -77
- package/package.json +149 -152
- package/react-native-fula.podspec +19 -19
- package/src/interfaces/fulaNativeModule.ts +52 -42
- package/src/protocols/fula.ts +212 -138
- package/android/.gradle/7.5.1/executionHistory/executionHistory.bin +0 -0
- 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
|
|
6
|
-
storePath: string
|
|
7
|
-
bloxAddr: string, //Blox multiadddr needs to be manually entered now
|
|
8
|
-
exchange: string //set to 'noope' for testing
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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;
|
package/src/protocols/fula.ts
CHANGED
|
@@ -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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
*
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
*
|
|
64
|
-
* @
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
* @
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
*
|
|
93
|
-
* @
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
|
Binary file
|