Skip to content

Commit 52cb7ae

Browse files
committed
added PoolID to poolList
1 parent cdd4aeb commit 52cb7ae

File tree

5 files changed

+54
-16
lines changed

5 files changed

+54
-16
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ dependencies {
9494
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
9595
//noinspection GradleDynamicVersion
9696
implementation "com.facebook.react:react-native:+"
97-
implementation 'com.github.functionland:fula-build-aar:v1.35.0' // From jitpack.io
97+
implementation 'com.github.functionland:fula-build-aar:v1.36.0' // From jitpack.io
9898
implementation 'com.github.functionland:wnfs-android:v1.8.1' // From jitpack.io
9999
implementation 'commons-io:commons-io:20030203.000550'
100100
implementation 'commons-codec:commons-codec:1.15'

android/src/main/java/land/fx/fula/FulaModule.java

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -509,32 +509,68 @@ private byte[] createPeerIdentity(byte[] identity) throws GeneralSecurityExcepti
509509

510510
if (encryptedLibp2pId == null || !encryptedLibp2pId.startsWith("FULA_" +
511511
"ENC_V4:")) {
512-
Log.d("ReactNative", "encryptedLibp2pId is not correct. creating new one " + encryptedLibp2pId);
513-
514-
try {
515-
libp2pId = Fulamobile.generateEd25519KeyFromString(toString(identity));
516-
} catch (Exception e) {
517-
Log.d("ReactNative", "Failed to generate libp2pId: " + e.getMessage());
518-
throw new GeneralSecurityException("Failed to generate libp2pId", e);
519-
}
520-
encryptedLibp2pId = "FULA_ENC_V4:" + Cryptography.encryptMsg(StaticHelper.bytesToBase64(libp2pId), encryptionSecretKey, null);
521-
sharedPref.add(PRIVATE_KEY_STORE_PEERID, encryptedLibp2pId);
512+
Log.d("ReactNative", "encryptedLibp2pId is not correct or empty. creating new one " + encryptedLibp2pId);
513+
encryptedLibp2pId = createEncryptedLibp2pId(identity, encryptionSecretKey);
522514
} else {
523515
Log.d("ReactNative", "encryptedLibp2pId is correct. decrypting " + encryptedLibp2pId);
524516
}
525517

526518
try {
527-
String decryptedLibp2pId = Cryptography.decryptMsg(encryptedLibp2pId.replace("FULA_ENC_V4:", ""), encryptionSecretKey);
528-
519+
String decryptedLibp2pId = decryptLibp2pIdentity(encryptedLibp2pId, encryptionSecretKey);
529520
return StaticHelper.base64ToBytes(decryptedLibp2pId);
530521
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException e) {
531522
Log.d("ReactNative", "createPeerIdentity decryptMsg failed with Error: " + e.getMessage());
532-
throw (e);
523+
Log.d("ReactNative", "creating new encrpyted identity");
524+
try {
525+
encryptedLibp2pId = createEncryptedLibp2pId(identity, encryptionSecretKey);
526+
String decryptedLibp2pId = decryptLibp2pIdentity(encryptedLibp2pId, encryptionSecretKey);
527+
return StaticHelper.base64ToBytes(decryptedLibp2pId);
528+
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException e2) {
529+
Log.d("ReactNative", "createPeerIdentity decryptMsg failed with Error: " + e2.getMessage());
530+
Log.d("ReactNative", "creating new encrpyted identity");
531+
throw(e2);
532+
}
533533
}
534534

535535
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException e) {
536536
Log.d("ReactNative", "createPeerIdentity failed with Error: " + e.getMessage());
537537
throw (e);
538+
} catch (Exception e) {
539+
throw new RuntimeException(e);
540+
}
541+
}
542+
543+
private String decryptLibp2pIdentity(String encryptedLibp2pId, SecretKey encryptionSecretKey) throws Exception {
544+
try {
545+
String decryptedLibp2pId = Cryptography.decryptMsg(encryptedLibp2pId.replace("FULA_ENC_V4:", ""), encryptionSecretKey);
546+
547+
return decryptedLibp2pId;
548+
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException e) {
549+
Log.d("ReactNative", "createPeerIdentity decryptMsg failed with Error: " + e.getMessage());
550+
Log.d("ReactNative", "creating new encrpyted identity");
551+
throw new GeneralSecurityException("decryptLibp2pIdentity Failed to decrypt libp2pId", e);
552+
}
553+
}
554+
555+
private String createEncryptedLibp2pId(byte[] identity, SecretKey encryptionSecretKey) throws Exception {
556+
byte[] libp2pId;
557+
String encryptedLibp2pId;
558+
try {
559+
Log.d("ReactNative", "createEncryptedLibp2pId started");
560+
561+
try {
562+
libp2pId = Fulamobile.generateEd25519KeyFromString(toString(identity));
563+
} catch (Exception e) {
564+
Log.d("ReactNative", " createEncryptedLibp2pId Failed to generate libp2pId: " + e.getMessage());
565+
throw new GeneralSecurityException("createEncryptedLibp2pId Failed to generate libp2pId", e);
566+
}
567+
encryptedLibp2pId = "FULA_ENC_V4:" + Cryptography.encryptMsg(StaticHelper.bytesToBase64(libp2pId), encryptionSecretKey, null);
568+
sharedPref.add(PRIVATE_KEY_STORE_PEERID, encryptedLibp2pId);
569+
return encryptedLibp2pId;
570+
}
571+
catch (Exception e) {
572+
Log.d("ReactNative", "createEncryptedLibp2pId failed with Error: " + e.getMessage());
573+
throw new GeneralSecurityException("createEncryptedLibp2pId Failed to generate libp2pId at hte first level", e);
538574
}
539575
}
540576

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@functionland/react-native-fula",
3-
"version": "1.35.0",
3+
"version": "1.36.0",
44
"description": "This package is a bridge to use the Fula libp2p protocols in the react-native which is using wnfs",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

src/protocols/chain-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export const listPools = async (
172172
let formattedPoolInfo: BType.Pool = JSON.parse(
173173
JSON.stringify(poolInfo.toHuman())
174174
);
175+
formattedPoolInfo.poolID = i;
175176
pools.pools.push(formattedPoolInfo);
176177
}
177178
}

src/types/blockchain.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ export interface PoolUsers {
7878

7979
export interface Pool {
8080
poolID: number;
81-
owner: string;
81+
creator: string;
8282
poolName: string;
8383
parent: string;
8484
participants: string[];
85+
region: string;
8586
}
8687

8788
export interface ManifestMetadata {

0 commit comments

Comments
 (0)