@@ -190,6 +190,16 @@ private byte[] createPeerIdentity(byte[] privateKey) throws Exception {
190
190
}
191
191
}
192
192
193
+ @ NonNull
194
+ private void loadForestInternal (String privateRef , String cid ) throws Exception {
195
+ try {
196
+ this .privateForest = Fs .createPrivateForest (this .client );
197
+ } catch (Exception e ) {
198
+ Log .d ("ReactNative" , "loadForestInternal failed with Error: " + e .getMessage ());
199
+ throw (e );
200
+ }
201
+ }
202
+
193
203
@ NonNull
194
204
private String [] initInternal (byte [] identity , String storePath , String bloxAddr , String exchange ) throws Exception {
195
205
try {
@@ -210,21 +220,41 @@ private String[] initInternal(byte[] identity, String storePath, String bloxAddr
210
220
this .fula = Fulamobile .newClient (config_ext );
211
221
this .client = new Client (this .fula );
212
222
Log .d ("ReactNative" , "fula initialized: " + this .fula .id ());
223
+
213
224
if (this .rootConfig == null ) {
225
+
226
+ //Load from keystore
227
+ String cid = sharedPref .getValue ("cid_encrypted" );
228
+ String private_ref = sharedPref .getValue ("private_ref_encrypted" );
229
+ SecretKey secretKey = Cryptography .generateKey (identity );
230
+ if (cid != null && !cid .isEmpty () && cid != "" && private_ref != null && !private_ref .isEmpty () && private_ref != "" ) {
231
+ String cid_decrypted = Cryptography .decryptMsg (cid , secretKey );
232
+ String private_ref_decrypted = Cryptography .decryptMsg (private_ref , secretKey );
233
+ this .rootConfig = new land .fx .wnfslib .Config (cid_decrypted , private_ref_decrypted );
234
+ }else {
235
+ this .privateForest = Fs .createPrivateForest (this .client );
236
+ Log .d ("ReactNative" , "privateForest is created: " + this .privateForest );
237
+ this .rootConfig = Fs .createRootDir (this .client , this .privateForest );
238
+ String cid_encrypted = Cryptography .encryptMsg (this .rootConfig .getCid (), secretKey );
239
+ String private_ref_encrypted = Cryptography .encryptMsg (this .rootConfig .getPrivate_ref (), secretKey );
240
+ sharedPref .add ("cid_encrypted" , cid_encrypted );
241
+ sharedPref .add ("private_ref_encrypted" , private_ref_encrypted );
242
+ }
243
+
244
+
214
245
Log .d ("ReactNative" , "creating rootConfig" );
215
246
216
- /*byte[] testbyte = convertStringToByte("-104,40,24,-93,24,100,24,114,24,111,24,111,24,116,24,-126,24,-126,0,0,24,-128,24,103,24,118,24,101,24,114,24,115,24,105,24,111,24,110,24,101,24,48,24,46,24,49,24,46,24,48,24,105,24,115,24,116,24,114,24,117,24,99,24,116,24,117,24,114,24,101,24,100,24,104,24,97,24,109,24,116");
247
+ /*
248
+ byte[] testbyte = convertStringToByte("-104,40,24,-93,24,100,24,114,24,111,24,111,24,116,24,-126,24,-126,0,0,24,-128,24,103,24,118,24,101,24,114,24,115,24,105,24,111,24,110,24,101,24,48,24,46,24,49,24,46,24,48,24,105,24,115,24,116,24,114,24,117,24,99,24,116,24,117,24,114,24,101,24,100,24,104,24,97,24,109,24,116");
217
249
long testcodec = 85;
218
250
byte[] testputcid = this.client.put(testbyte, testcodec);
219
- Log.d("ReactNative", "client.put test done"+ Arrays.toString(testputcid));
251
+ Log.d("ReactNative", "client.put test done"+ Arrays.toString(testputcid));
220
252
byte[] testfetchedcid = convertStringToByte("1,113,18,32,-6,-63,-128,79,-102,-89,57,77,-8,67,-98,8,-81,40,-87,123,122,29,-52,-124,-60,-53,100,105,125,123,-5,-99,41,106,-124,-64");
221
253
byte[] testfetchedbytes = this.client.get(testfetchedcid);
222
254
Log.d("ReactNative", "client.get test done"+ Arrays.toString(testfetchedbytes));
223
- */
255
+ */
256
+
224
257
225
- this .privateForest = Fs .createPrivateForest (this .client );
226
- Log .d ("ReactNative" , "privateForest is created: " + this .privateForest );
227
- this .rootConfig = Fs .createRootDir (this .client , this .privateForest );
228
258
Log .d ("ReactNative" , "rootConfig is created: " + this .rootConfig .getCid ());
229
259
} else {
230
260
Log .d ("ReactNative" , "rootConfig existed: " + this .rootConfig .getCid ());
0 commit comments